CBSE Solved Papers For Class 12 Computer Science (C++) Paper 4
SECTION ‘A’
Question 1:
(a) Find the correct identifiers out of the following, which can be used for naming variable, constants or functions in a C + + program :
While, FLOAT, Switch, – 123, + Two, Add5, typedef, First_Name
(b) Read the following code and answer the questions (i) and (ii).
void main ()
{
char name [20];
int Roll no =20;
gets (name);
puts (name);
cout«Roll no;
}
What are the header files to be included?
(c) Rewrite the following program after removing the syntactical error(s) if any Underline each correction.
#include<iostream.h>
const int Dividor 5;
void main ()
{
Number =15;
for (int count =1 count =<5; count++, Number -=3)
if (Number %Dividor==0)
cout «nuraber/Dividor «endl;
else
cout« Number+Dividor « endl;
}
(d) Find the output of the following C+ + program: [2]
#include<iostream.h>
void repch(char s [] )
{
for(int i=0;s [i] ! =’\0′;i++)
{
A( ( (i%2) !=0) &&(s [i] !=s [i + 1]))
{
S [ i ] = ‘ @’ ;
cout << “Hello”;
}
else if (s [i]==s [i + 1])
{
S [i + 1]=’ ! ‘ ;
i++;
}
}
}
void main ();
{
char str[]=”SUCCESS”;
cout<<“Original String”<<str<<endl; repch(str);
cout<<“Changed String”<<str;
}
(e) Find and write the output of the following C++ program code : [2]
Note :
Assume all required header files are already included in the program.
typedef char STRING[80]; .
STRING MIXITNOW(STRINGS)
{
int SIZE=strlen (S);
for(int I=0;I<size-1;I+=2)
{
char WS=S [I];
S[I]=S[I+1];
S[I+1]=WS;
}
for (I=1; I<size; I+=2)
if(S[I]>=’M’&& S[I]<=’U’)
S[I]=’@’;
}
void main()
{
STRING Word = “CRACKAJACK”;
STRING Str;
Str = MIXITNOW(Word);
cout<<Str<<endl;
}
(f) In the following program, find the correct possible output(s) from the options: [2]
#include<stdlib.h>
#include<iostream.h>
void main ()
{
randomize ();
char City [ ] [10]={“DEL”, “CHN”, “KOL”, “BOM”, “BNG”};
int Fly;
for (int I=0; I<3; I+ +)
{
Fly=random(2) + I;
cout«City [Fly]«”:”;
}
}
Outputs:
- DEL:CHN:KOL:
- CHN:KOL:CHN:
- KOL:BOM:BNG:
- KOL:CHN:KOL:
Solution:
(a) Adds, First_Name
(b) #include<iostream.h>
#include<stdio.h>
(c) #include<iostream.h>
const int Dividor=5;
void main ()
{
int Number = 15;
for (int count=l;
count<=5; count ++) Number-=3;
if (Number % Dividor= = 0)
{
cout«number/Dividor«endl;
}
else
cout<<Number+Dividor <<endl;
(d) Original String SUCCESS <- Hellos@C!ES!
(e) RCCAAKAJCK
(f) The possible out puts of the above program are :
CHN : KOL : CHN :
KOL : CHN : KOL :
Question 2:
(a) What is Encapsulation? Explain it with an example?
(b) Answer the questions
(i) and (ii) after going through the following class:
class Student {
int class;
char subject [20];
public:
Student () //Function 1
{ class=12;
strcpy (subject, “C++”);
Student (char sub [J]) //Function 2
{
class=12;
strcpy (subject, Sub);
}
Student (int C) //Function 3
classic;
strcpy (subject, “C++”);
Student (char sub [ ], int c) //Function 4
{
class=c;
strcpy (subject, Sub);
};
- Write statements in C++ that would execute Function 3 and Function 4 of class Student. [1]
- Which feature of Object Oriented Programming is demonstrated using Function 1, Function 2, Function 3 and Function 4 in the above Class Student? [1]
(c) Define a Class Student with the following specifications:
roll-No. | integer |
name | 20 characters |
class | 8 characters |
marks [5] | integer |
percentage | float |
Calculate () a function that calculates overall percentage of marks and returns the percentage of marks. [Assume total marks as 500 i.e., max. marks per subject is 100].
Public Members:
Readmarks () a function that read marks and invokes the calculate function, displaymarks () a function that prints the marks.
(d) Answer the questions (i) to (iv) based on the following code: class Trainer
{
char TNo [5], TName [20], Specialization [10];
int Days;
protected:
float Renumeration;
void AssignRem (float) ;
public:
Trainer ();
void TEntry ();
void TDisplay ();
}
class Learner
{
char Regno [10], LName [20], Program [10]; protected:
int Attendence, grade;
public:
Learner ();
void LEntry ();
void LDisplay ();
};
class Institute : public Learner, public Trainer
{
char ICode [10], IName [20];
public:
Institute ();
void TEntry ();
void TDisplay ();
} ;
- Which type of Inheritance is depicted by the above example? [1]
- Identify the member function(s) that cannot be called directly from the object of class Institute from the following: [1]
TEntry ()
LDisplay () - What will be the size of object of class Institute ? [1]
- If class Institute was derived privately from class Learner and privately from class Trainer, then name the member function(s) that could be accessed through, object of class Institute.
Solution:
(a) Data Encapsulation: Wrapping up of data and functions together in a single unit is known as Data Encapsulation.
Example:
class Item /* Class wraps Data & Functions together in a single unit. */.
{
int Ino: char Desc [20] ;
public: void Purchase ();
void Sale ();
};
(b)
- For function 3 : student S(10);
For function 4 : Student C(“cluestech”, 100); - Function overloading or constructor overloading or polymorphism.
(c) class Student {
private: int roll_no;
char name [20];
char clhss [8];
int Marks [5];
float percentage;
float Calculate ()
{
int sum=0;
for (int i=0; i<5; i++)
sum=sum+marks [i];
return (sum/5);
}
public:
void Readmarks ()
{
cout<<“Enter the student’s name”;
gets(name);
cout<<“\n Enter the roll no”;
cin>>roll_no;
cout«”\n Enter the student’s class”;
cin»class;
cout«”\n Enter 5 marks”;
for (int i=0; i<5; i++)
cin>>marks [i];
percentage=calculate();
}
void displaymarks ()
{
cout«”\n Name entered is”; puts (name) ;
cout«”\n Class of the student is”<<class;
cout«”\n Roll number of the student is” <<roll_no;
cout«”\n Marks entered are”;
for (int i=0; i<5; i++)
cout<<marks [i ] «” “;
cout«”\n percentage of the student is”«percentage;
}
};
(d)
- Multiple Inheritance is depicted by the given example.
- Both the given member functions can be called directly from the objects of the class Institute.
- 37 bytes.
- The member functions are:
Institute()
TEntry()
TDisplay()
SECTION ‘B’
Question 3:
(a) An array A[10] [20] is stored in the memory along the row, with each of the element occupying 2 bytes, find out the memory location for element A[2] [5], if an element A[5] [10] is stored at the memory location 3020. [3]
(b) Write definition for a function SHOWMID (int P[][5], int R, int C) in C++ to display the elements of middle row and middle column from a two dimensional array P having R number of rows and C number of columns.
For example, If the content of array is as follows:
115 | 112 | 116 | 101 | 125 |
103 | 101 | 121 | 102 | 101 |
185 | 109 | 109 | 160 | 172 |
The function should display the following as output:
103 101 121 102 101 116 121 109
(c) Top is a pointer variable pointing to the top element of a Stack, with each node having the following structure declaration:
struct Stack {int Data; Stack*Next;| considering the above explanation, what does the following code do?
int count=0, Sum=0;
Stack*Temp = Top;
while (Temp —» Next!= NULL)
{ count++;
Sum+=Temp -+Data;
Temp=Temp —>Next;
}
count«Sum/count ;
Also find output if stack contains data as 10, 20, 9, 10.
(d) Given a class declaration as below to implement a Queue using a circular array. Complete the class definition with all member functions. [4]
class Queue
{
int F,R;
int Element [100];
Queue (); //To initialize F and R
void Addition (); //this function should check over flow Condition before adding elements
void Deletion () ; //this function should check empty Queue condition before deleting elements
(e) Convert the expression (x*3+y*3+z*3) / (x + y + z) into postfix expression. Show the content of the stack during the conversion.
Solution:
(a) Array is of A [10] [20].
Total rows, m = 10.
Total columns, n = 20 Width of elements, W = 2 bytes.
If it is stored along row
Formula : Address of A [I] [J] = B + W ((I-Ir)n + (J-Jc)) row = 0 & Jc = Lowest number & column = 0 Position of A [5] [10] = 3020 Therefore, 3020 = B + 2 (5 x 20 + 10)
3020 = B + 2 (110)
3020 = B + 220
B = 2800. [IV*]
Now, position of A [2] [5]
2810 + 2 (2 x 20 + 50)
2810 + 2 (45)
2810 + 90
2900.
(b) void SHOWMID (int P[][5],int R,int C)
{
If (R%2 ! =0);
int X = R + 1;
else
X = R;
If (C%2!=0)
int Y = C+1;
else
Y = R;
forCintJ=Q;J<C;J++)
cout«P[X/2] [J]«””;
cout«endl;
for(intl=0;I<R;I++)
cout«P[I] [Y/2]«””;
(c) It will calculate the average of stack values. Output will be 9.
(d) class Queue {
int F,R;
int Element [100];
Queue ()
{
R=Null;
F=Null;
}
void Addition ();
void Deletion ();
} ;
void Queue :: Addition ()
{
int val;
if ((R+l) % 100 = =F)
cout «”Queue is full”;
else
{
R=(R+l)%Element;
Element [R] =Val;
}
}
void Queue :: Deletion ()
{
int val;
if (F!=R)
{
F=(F+1)%100;
val=Element [F];
cout<< “Removed value =” <<val;
}
else
{
cout<< “Queue is empty”;}
}
}
(e) (x*3 + y*3 + z*3)/ (x+y+z)
Symbol Scanned | Stack | Expression |
( | ( | |
( | (( | |
x | (( | x |
* | ((* | x |
3 | ((* | x3 |
+ | ((+ | x3 * |
y | ((+ | x3 * y |
* | ((+* | x3 * y |
3 | ((+* | x3 * y3 |
+ | ((+ | x3 * y3 *+ |
z | ((+ | x3 * y3 *+z |
* | ((+* | x3 * y3 *+z |
3 | ((+* | x3 * y3 * + z3 |
) | ( | x3 * y3 * z3 *+ |
/ | (/ | x3 * y3 * z3 *+ |
Symbol Scanned | Stack | Expression |
( | (/( | x3 * y3 * z3 *+ |
x | (/( | x3 * y3 * z3 *+x |
+ | (/(+ | x3 * y3 * z3 *+x |
y | (/(+ | x3 * y3 * z3 *+xy |
+ | (/(+ | x3 * y3 * z3 *+xy+ |
z | (/(+ | x3 * y3 * z3 *+xy+z |
) | (/ | x3 * y3 * z3 *+xy+z+/ |
) | x3 * y3 * z3 *+xy+z+/ |
Question 4:
(a) Observe the program segment carefully and answer the question that follows :
class Labrecord
{
int. Expno;
char Experiment[20];
char Checked;
int Marks;
pubilc:
void Enter_Exp();
void Show_Exp();
char RChecked()
{
return Checked;
}
void AssignMark(int M)
{
Marks = M;
}
};
void Modify Marks()
{
fstream File;
File.open(“Marks.Dat”,ios::binary:ios::in|ios::out);
Labrecord L;
int Rec=0;
while(File.read((char*)&L, sizeof(L)))
{
if(L.Rchecked()==’N’)
L.Assignmark(0);
else
L.AssignMark(10);
——————–//Statement 1
——————–//Statement 2
Rec ++;
}
File.Close ();
If the function ModifyMarks() is supposed to modify marks for the records in the file MARKS.DAT based on their status of the member checked (containing value either ‘Y or ‘N’). Write C++ statements for the statement 1 and statement 2 where statement 1 is required to position the file write pointer to an appropriate place in the file and statement 2 is to perform the write operation with the modified record.
(b) Write a function in C++ to count the number of uppercase alphabets present in a text file [2] “Article.TXT”
(c) Given a binary file DATABASE.DAT, containing records of the following structure type : [3]
struct product
{
int prod_id;
char grade;
float price;
};
Write a function in C++ that would read contents from the file ‘DATABASE.DAT and creates a file named ‘IMPORTED.DAT’ copying only those records from DATABASE.DAT whose price ranges from 2000 to 5000.
Solution:
(a) Statement 1: File Seekp (size of (L));
Statement 2: File write ((clear*)&L, size of (L));
(b) void Countupper()
{ int count=0; char c’h;
infstream fin (“Article . txt”) ;
while (Ifin.eof () )
{
fin»ch;
if(isupper(ch))
count ++;
}
cout «”No of uppercase characters = “«count;
fin. close () ;
}
(c) void create filed
{
ifstream fin;
ofstream fout;
fin.open (“DATABASE.DAT”, ios : :binary) ;
fout.open(“IMPORTED.DAT”, ios::binary);
product p;
while (fin.read(( char*)&p, sizeof (p) )
{
if(p.price>=2000&& p.price<=5000)
fout.write ((char*) & p, size of (p));
}
fin. close () ;
fout. close ();
}
SECTION ‘C’
Question 5:
(a) What do you understand by primary key and candidate key? [2]
(b) Consider the following tables Item and Customer. Write SQL commands for the statement (i) to (iv) and give outputs for SQL queries (v) to (viii).
Table: Item
I_Id | Manufacturer | Price | Item Name |
PC01 | ABC | 35000 | Personal Computer |
LC05 | ABC | 55000 | Laptop |
PC03 | XYZ | 32000 | Personal Computer |
PC06 | COMP | 37000 | Personal Computer |
LC03 | PQR | 27000 | Laptop |
Table: Customer
C_ID | City | IJD | Customer Name |
01 | Delhi | LC03 | N Roy |
06 | Mumbai | PC03 | H Singh |
12 | Delhi | PC06 | R Pandey |
15 | Delhi | LC03 | C Sharma |
16 | Banglore | PC01 | K Agarwal |
- To display the details of those customers whose city is Delhi. [1]
- To display the details of Items whose price is in the range of 35000 to 55000 (Both values included) [1]
- To display the customer Name, City from table customer and Item Name and Price from table Item, with their corresponding matching I_Id. [1]
- To increase the price of all Items by 1000 in the table Item. [1]
- SELECT DISTINCT City FROM CUSTOMER; [1/2]
- SELECT Item Name, MAX (Price)
FROM ITEMGROUP BY Item Name; - SELECT Customer Name, Manufacturer [1/2]
FROM ITEM, CUSTOMER WHERE ITEM.IJd = CUSTOMER.I_Id; - SELECT Item Name, Price *100 VM
FROM ITEM WHERE Manufacturer = ‘ABC’
Solution:
(a) Primary key: Primary key is the key that uniquely identifies a particular record in a file. i.e. in a table.
Candidate key:
- If a relation scheme has more than one primary key, each is called a candidate key.
- One of the candidate keys is arbitrarily designated to be the primary key and the others are called secondary keys.
(b)
- SELECT * FROM Customer WHERE City = ‘Delhi’; [1]
- SELECT * FROM Item WHERE Price > = 35000 and Price < = 55000;
- SELECT Customer Name, City FROM Customer, Item WHERE Customer.I_Id=Item. I_Id;
- Update Table Item Set Price=Price+1000;
City |
Delhi Mumbai Banglore |
6.
Item: Name | Price |
Personal Computer Laptop | 37.000
57.000 |
7.
Customer Name | Manufacturer |
K Agarwal H Singh R Pandey C Sharma N. Roy |
ABC XYZ COMP PQR PQR |
8.
Item Name | Price |
Personal computer Laptop | 35.0. 00 55.0. 00 |
Question 6:
(a) State and define principle of duality. Why is it so important in Boolean Algebra ?
(b) Write the equivalent Boolean Expression for the following Logic Circuit: [2]
(c) Derive a Canonical SOP expression for a Boolean function F, represented by the following truth table:
p | Q | R | P(P,Q,R) |
0 | 0 | 0 | 1 |
0 | 0 | 1 | 0 |
0 | 1 | 0 | 1 |
0 | 1 | 1 | 0 |
1 | 0 | 0 | 0 |
1 | 0 | 1 | 0 |
1 | 1 | 0 | 1 |
1 | 1 | 1 | 1 |
(d) Reduce the following Boolean expression using K-map: F(a,b,c,d) = Σ(0,2,3,8,10,11).
Solution:
(a) Principal of duality : Daulity principle states that from every boolean relation another boolean . relation can be derived by :
- Changing each or sign (+) to an AND sign (-).
- Changing each AND sign (-) to an or sign (+) ex. Daul of A + A’B = A.(A’+B)
Importance in Boolean Algebra : The principle of daulity is an important concept in boolean algebra to prove various theorems.
(b) (A+B). (A+B’)
(c) F (P, Q, R) = (P+Q+R).(P+Q’+R’).(P’+Q+R).(P’+Q+R’) OR
F(P,Q,R) = π(0,3,4,S)
Note:
Deduct ½ mark if wrong variable names are used.
(d) F (a,b,c,d) = Σ(0,2,3,8,10,11)
The K-map is:
Hence F(a,b,c,d)= b’c+b’d’ + b’c = b’c + b’d’.
Question 7:
(a) Out of the following which is the fastest
- wired and
- wireless medium of communication.
Infrared, Coaxial cable, Ethernet cable, Microwave, Optical fiber. [2]
(b) Expand the following terminologies: [1]
- SMS
- VOIP.
(c) What is MODEM? [1]
(d) Describe the following in brief: [2]
- MOSAIC
- Usenet
(e) ABC SWITCH GEARS LTD in Srinagar is setting up the network between its different departments located in different wings. There are 4 wings named as Manufacturing (M). Research (R), Administration (A) and Personnel (P).
Distance between various wings are :
Wing A to wing M | 100 m |
Wing A to wing R | 200 m |
Wing A to wing P | 400 m |
Wing M to wing R | 300 m |
Wing M to wing P | 100 m |
Wing R to wing P | 450 m |
Number of Computers:
Wing M | 15 m |
Wing R | 100 m |
Wing A | 50 m |
Wing P | 150 m |
- Suggest a suitable Topology for networking the computers of all wings.
- Name the wing where the server is to be installed. Justify your answer.
- Suggest the placement of Hub/Switch in the network.
- Mention an economic technology to provide Internet Accessibility to all the wings.
Solution:
(a)
- Wired : Optical Fiber
- Wireless : Infrared (or Microwave)
(b)
- SMS : stands for Short Message Service.
- VOIP : Voice-Over-Internet-Protocol.
(c) Modem : (Modulator Demodulator)
- It is a device which converts analog signal to digital signals & vice versa.
- It is a device used to connect and communicate with other computers.
(d)
- MOSAIC: It is an easy method to navigate through internet. It was developed by Mark Anderson in 1993, at NCSA (National Center of Super-Computing Applications) at University of Illinois.
- Usenet: It is a group of individuals sharing a particular interest to discuss the views regarding their interest i.e newsgroups.
(e)
- Suitable network topology for all wings is BUS Topology.
- Wing P should be used to install server as it has maximum number of computers.
- The Hub /Switch should be installed in all the four wings.
- The economic technology to provide Internet Accessibility to all wings is co-axial.
Cable Network or Broadband Network.