CBSE Solved Papers For Class 12 Computer Science (C++) Paper 2


Question 1.
(a) Define Macro with suitable example.
(b) Which C++ header file (s) will be included to run /execute the following C++ code?

void main( )
 int Last =26.5698742658;
 cout< }

(c) Rewrite the following program after removing any syntactical errors. Underline each correction made.

 void main( )
 int A[10];
 A=[3, 2, 5, 4, 7, 9, 10]; int S = 0, p;
 for ( p = 0; p<=6; p++)
 { if(A[p]%2=0)
 int S = S+A[p]; }

(d) Find the output of the following C+ + program:

 void repch(char s[])
 for (int i=0;s [i] !='\0';i++)
 if(((i%2) !=0) &&(s[i]!=s[i+1] ) )
 else if (s [i]==s[i+1])
 void main()
 char str[]="SUCCESS";
 cout<<"Original String"<<str
 cout<<"Changed String"<<str;

(e) Find the output of the following :

 void switchover(int A[ ],int N, int split)
 for(int K = 0; K<N; K++)
 A[K] += K;
 A[K]*= K;
 void display(int A[ ] ,int N)
 for (int K = 0; K<N; K++)
 (K%2== 0) ?cout<<A[K]<<"%" : cout< }
 void main( )
 { int H[ ] = {30, 40, 50, 20, 10, 5};
 switchover(H, 6, 3);
 display(H, 6);

(f) Observe the following C++ code and find out, which out of the given options (i) to (iv) are the expected correct outputAlso assign the maximum and minimum value that can be assigned to the variable ‘Go’.

void main()
 { int X [4] ={100,75,10,125};
 int Go = random(2)+2;
 for (inti = Go; i< 4; i++)
 cout<<X[i ]<<"$$";
 i. 100$$75 ii. 75$$10$$125$$ iii. 75$$10$$ iv.l0$$125$

(a) Macros are preprocessor directive created using # define that serve as symbolic constants. They are created to simplify and reduce the amount of repetitive coding,

For instance,
 ##define max (a, b) (a>b? a: b)

Defines the macro max, taking two arguments a and b. This macro may be called like any function. Therefore, after preprocessing

A = max (x, y) ;
 Becomes A = (x>y?x :y) ;

(b) iostream.h

(c) #include
 void main( )
 { int A[10] = {3, 2, 5, 4, 7, 9, 10};
 int S = 0,p;
 for(p = 0; p<=6; p++)
 { if(A[p]%2==0) (
 S = S+A [p] ; }

(d) Original String SUCCESS
Changed String S@C!ES!

(e) 30%41
52% 60
40% 25

(f) iv is the correct option.
Minimum value of Go = 2
Maximum value of Go = 3

Question 2.
(a) Differentiate between data abstraction and data hiding.
(b) Answer the questions (i) and (ii) after going through the following class :

class Exam
 int Rollno;
 char Cname[25];
 float Marks ;
 public :
 Exam( ) //Function 1
 Rollno = 0 ;
 Exam(int Rno, char candname) //Function 2
 Rollno = Rno ;
 -Exam() //Function 3
 cout << "Result will be intimated shortly" < }
 void() display( ) //Function 4
 cout << "Roll no :"<<Rollno;
 cout<<"Name <<Cname;
 cout <<" Marks:"<<Marks; } } ;

(i) Which OOP concept does Function 1 and Function 2 implement.Explain?
(ii) What is Function 3 called? When will it be invoked?
(c) Define a class Candidate in C++ with the following specification : Private Members: A data members Rno(Registration Number) type long A data member Cname of type string A data members Agg_marks (Aggregate Marks) of type float A data members Grade of type char A member function setGrade () to find the grade as per the aggregate marks obtained by the student. Equivalent aggregate marks range and the respective grade as shown below. Aggregate Marks Grade >=80 A
Less than 80 and > =65 B
Less than 65 and > =50 C
Less than 50 D
Public members:
A constructor to assign default values to data members :
A function Getdata () to allow users to enter values for Rno. Cname, Agg marks and call function
setGrade () to find the grade.
A function dispResult() to allow user to view the content of all the data members.
(d) Give the following class definition answer the question that is follow:

class University
 char name [20];
 protected :
 char vc[20];
 public :
 void estd();
 void inputdata();
 void outputdata() ;
 class College : protected University
 { int regno;
 char principal ()
 public :
 int no_of_students;
 void readdata();
 void dispdata ( );
 } ;
 class Department : public College
 char name[20];
 char HOD[20];
 public :
 void fetchdata(int);
 void displaydata( );

(i) Name the base class and derived class of college.
(ii) Name the data member(s) that can be accessed from function displaydata().
(iii) What type of inheritance is depicted in the above class definition?
(iv) What will be the size of an object (in bytes) of class Department?

(a) Data hiding can be defined as the mechanism of hiding the data of a class from the outside world. This is done to protect the data from any accidental or intentional access.
Implementation-Data hiding is achieved by making the members of the class private.
Data abstraction refers to, providing only essential information to the outside world and hiding their background details.
Implementation-Members defined with a public label are accessible to all parts of the program. The dataabstraction view of a type is defined by its public members.
(b) (i) Constructor Overloading/Polymorphism, as multiple definitions for Constructors are given in the same scope. Functiort 1 is a Default constructor and function 2 is a Parameterized constructor.
(ii) Function 3 is a Destructor which is invoked when the object of class goes out of scope.

(c) class Candidate
 { long Rno;
 char Cname[20];
 float Agg_marks;
 char Grade;
 void setGrade()
 { if (Agg_marks>= 80)
 Grade = 'A';
 else if (Agg_marks>=65)
 Grade = 'B';
 else if (Agg_marks>=50)
 Grade ='C';
 void Getdata ()
 { cout<<"Registration No"; cin>>Rno;
 void dispResult()
 cout<<"Registration No"<<Rno;
 cout< }

(d) (i) Base class: University
Derived class: Department
(ii) name[20], HOD[20], no_of_students.
[Hint: By default access type is private]
(iii) Multilevel Inheritance
[1 mark for the correct answer]
(iv) 62 bytes
[Note: 65 will be also considered correct because of NULL character i.e., ’10’ at last of each array. So ultimately size of array is 21],
85 bytes

Question 3.
(a) An integer array A [40] [30] is stored along the row in the memory. If the element A[20][25] is stored at 50000, find out the location of A[7][10].]
(b) Write the definition of function insert for the linked implemented queue containing passenger in-formation as follows: [4]

struct NODE
 { int Ticketno;
 char PName[20];
 NODE * NEXT; };
 class Queueofbus
 { NODE *Rear, *Front;
 { Rear = NULL;
 Front = NULL; };
 void Insert ();
 void Delete();
 { cout<<"Object destroyed"; }
 } ;

(c) Write a function to sort any array of n elements using insertion sort. Array should be passed as argument to the function.
(d) Write a function NewMAT(int A[][],int r,int c ) in C++, which accepts a 2d array of integer and its size as parameters divide all those array elements by 6 which are in the range 60 to 600(both values inclusive) in the 2d Array .
(e) Evaluate the following postfix expression using stack and show the contents after execution of each Operations:470, 5, 4, ^ , 25, /, 6, *

(a) A[i] [j] = B+W x [No.of columns x(I-Lr) + (J-L,) ]
A [20] [25] = B+ 2x[30x(20-0) + (25-0) ]
50000 = B+2x[30x(20-0)+(25-0)]
B = 48750
A[7] [10] = 48750+ 2x[30x(7-0) + (10-0)]
= 49190

(b) void Queueofbus::Insert()
 { NODE *p = new NODE;
 cout<<"Enter Ticket no" cin>>p->ticketno;
 cout<<"Enter Name"; cin>>p->Pname;
 p->NEXT = NULL;
 if (rear == NULL)
 { Rear = p;
 Front = Rear;
 { Rear -> NEXT = p;
 Rear = Rear -> NEXT;
(c) void insertsort( int a[],int n)
 int p,ptr;
 //Assuming a[0]=int_min i.e. smallest integer
 for (p=1 ,p<=n;p+ + )
 a [ptr+1]=a[ptr]; // Move Element Forward
 ptr- -;
 a[ptr+1]=temp; // Insert Element in Proper Place
(d) void NewMAT(int A[][],int r,int c)
 for (int i = 0;i<r;i++)
 for(j =0;j <c;j ++) if ( (A [i] [ j ] >=60 )&&(A[i] [ j ] <=600) )
 A [i] [j]/=6 ;
 A [i] [j] = A [i] [ j ] / 6 ;


S.No. Symbol Operation  Stack  Result
1 470 push(470) 470
2 5 push(5) 470, 5
3 4 push(4) 470, 5, 4
4 A pop (4) 470, 5
pop(5) 470
push(625) 470, 625
5 25 push(25) 470, 625, 25
6 / pop(25) 470, 625
pop(625) 470
perform(625/25) 470
push(25) 470, 25
7 6 push(6) 470, 25, 6
8 * pop(6) 470, 25
pop(25) 470
perform(25*6) 470

Question 4.
(a) Consider a file F containing objects E of class Emp.
(i) Write statement to position the file pointer to the end of the file
(ii) Write statement to return the number of bytes from the beginning of the file to the current posi¬tion of the file pointer.
(b) Write a function RevText() to read a text file ” Input.txt ” and Print only word starting with T in reverse order.
Example: If value in text file is: INDIA IS MY COUNTRY Output will be: AIDNI SI MY COUNTRY
(c)Write a function in C+ + to search and display details, whose destination is “Chandigarh”from binary file “Flight.Dat”. Assuming the binary file is containing the objects of the following class:

class FLIGHT
 { int Fno; // Flight Number
 char From[20j; // Flight Starting Point
 char To[20j; // Flight Destination
 char * GetFrom (); { return from; }
 char * GetTo(); { return To; }
 void input() { cin> >Fno> >; gets(From); gets(To); }
 void show() { cout< <Fno< < "From:"; puts (From); cout < < "\n To:"; puts (To); }

(a) (i) F.seekg(0,ios::end);
(ii) F.tellg();

(b) void RevText()
 { ifstream in ("Input.txt");
 char word[25];
 { in>>word;
 if (word[0]=='I')
(c) void Dispdetails()
 { ifstream fin ( "Flight. Dat" ) ;
 Flight F;
 while (fin)
 { fin. read( (char*) &F, sizeof (F) )
 if (strcmp(F.GetTo(),"Chandigarh"));


Question 5.
(a) Differentiate between cardinality and degree of a table with the help of an example.
(b) Consider the following tables FACULTY and COURSES. Write SQL commands for the statements (i) to (v) and give outputs for SQL query (vi)

F_ID Fname Lname Hire_date Salary
102 Amit Mishra 12-10-1998 12000
103 Nitin Vyas 24-12-1994 8000
104 Rakshit Soni 18-5-2001 14000
105 Rashmi Malhotra 11-9-2004 11000
106 Sulekha Srivastava 5-6-2006 10000


C_ID F_ID Cname Fees
C21 102 Grid Computing 40000
C22 106 System Design 16000
C23 104 Computer Security 8000
C24 106 Human Biology 15000
C25 102 Computer Network 20000
C26 105 Visual Basic 6000

(i) To display details of those Faculties whose salary is greater than 12000.
(ii) To display the details of courses whose fees is in the range of 15000 to 50000 (both values included).
(iii) To increase the fees of all courses by 500 of “System Design” Course.
(iv) To display details of those courses which are taught by ‘Sulekha’ in descending order of courses.
(vi) Select MIN(Salary) from FACULTY,COURSES where COURSES.F ID = FACULTY.F_ID;

(a) Cardinality is defined as the number of rows in a table. Degree is the number of columns in a table.
Eg:Consider the following tables:
Table : Account

Acno Cname
Ac100 Sheela
Ac101 Darsh
Ac102 Kathy

Cardinality of Account table is : 4
Degree of Account table is :2

(b) (i) Select * from faculty
where salary > 12000
(ii) Select * from Courses
where fees between 15000 and 50000
(iii) Update courses set fees = fees + 500
where Cname = “System Design”
(iv) Select * from faculty fac,courses cour
where fac.f_id = cour.f_id
and fac.fname = ‘Sulekha’
order by cname desc
(v) 4
(vi) 12000

Question 6.
(a) State and Verify Absorption law algebraically.
(b) Draw a logic circuit for the following Boolean expression: A.B+C.D’.
(c) Write the SOP form of a Boolean function F, which is represented in a truth table as follows:

0 0 0 0
0 0 1 1
0 1 0 1
0 1 1 0
1 0 0 1
1 0 1 1
1 1 0 0
1 1 1 0

(d) Obtain a simplified form for a Boolean expression:
F (U, V, W, Z) = 7i (0,1, 3,5,6, 7,15)

(a) Absorption law states that:
A + AB = A and A . (A + B) = A
Algebraic method:
Taking LHS
A + AB = (A.1) + (A.B) by Identity
= A. (1+B) by Distribution
= A.1 by Null Element
= A
(c) ABC’+AB’C+A’BC+A’BC [1 mark for all the terms]
(d) (u+v+w).(u+z’).(v’+w’).(u’+w’+z)

Question 7.
(a) Write any 1 advantage and 1 disadvantage of Bus topology.
(b) SunRise Pvt. Ltd. is setting up the network in the Ahmadabad. There are four departments named as MrktDept, FunDept, LegalDept, SalesDept.
Distance between various buildings is given as follows:

MrktDept to FunDept 80 m
MrktDept to LegalDept 180m
MrktDept to SalesDept 100 m
LegalDept to SalesDept 150 m
LegalDept to FunDept 100 m
FunDept to SalesDept 50 m

Number of Computers in the buildings:

MrktDept 20
LegalDept 10
FunDept 08
SalesDept 42

(i) Suggest a cable layout of connections between the Departments and specify topology.
(ii) Suggest the most suitable building to place the server with a suitable reason.
(iii) Suggest the placement of i) modem ii) Hub /Switch in the network.
(iv) The organization is planning to link its sale counter situated in various part of the same city/which type of network out of LAN, WAN, MAN will be formed? Justify.
(c) Name the protocol
(i) Used to transfer voice using packet switched network.
(i) Used for chatting between 2 groups or between 2 individuals.
(d) What is an IP Address?
(e) What is HTTP?
(f) Explain the importance of Cookies.
(g) How is 4G different from 3G?

(a) Advantage: Since there is a single common data path connecting all the nodes, the bus topology uses a very short cable length which considerably reduces the installation cost.
Disadvantage: Fault detection and isolation is difficult. This is because control of the network is not centralized in any particular node. If a node is faulty on the bus, detection of fault may have to be performed at many points on the network. The faulty node has then to be rectified at that connection point.
(b) (i)
Star Topology should be used.
(ii)As per 80 – 20 rule, Mrkt Dept beacause it has maximium no. of computers.
(iii) Each building should have hub/switch and Modem in case Internet connection is required.
(iv) MAN (Metropolitan Area Network). Because it is suitable to correct across a city.
(c) (i) VOIP (Voice Over Internet Protocol)
(ii) IRC(Internet Relay Chat)
(d) An IP address is a unique identifier for a node or host connection on an IP network. An IP address
is a 32 bit binary number usually represented as 4 decimal values, each representing 8 bits, in the range 0 to 255 (known as octets) separated by decimal points. This is known as “dotted decimal” notation. ’
(e) HTTP is a protocol that is used for transferring hypertext(i.e. text,graphic,image,sound,video,etc,) between 2 computers and is particularly used on the World Wide Web (WWW). It is acronym for Hyper Text Transfer Protocol.
(f) When the user browses a website, the web server sends a text file to the web browser. This small text file is a cookie. They are usually used to track the pages that we visit so that information can be customised for us for that visit.
(g) 3G technology adds multimedia facilities such as video,audio and graphics applications whereas 4G will provide better than TV quality images and video-links. Transfer rate of 4G is very high as compared to 3G.