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

Question 1:
(a) Write the type of C + + tokens (keywords and user defined identifiers) from the following :
(i) For
(ii) delete
(iii) default
(iv) Value
(b) Anil typed the following C + + code and during compilation he found four errors as follows :
(i) Function strlen should have a prototype
(ii) Undefined symbol cout
(iii) Undefined symbol endl
(iv) Function getchar should have a prototype
On asking his teacher told him to include necessary header files in the code. Write the names of the header files, which Anil needs to include, for successful compilation and execution of the following code :

void main ()
 char S [ ] = “Hello”,
 for (int i = 0; i < strlen (s); i++)
 S[i] = S[i] + 1,
 cout« B«endl;
 getchar 0;
 }

(c) Rewrite the following C+ + code after removing any/all syntactical errors with each correction underlined.
Note :
Assume all required header files are already being included in the program.

void main ()
 cout<<“Enter an integer”; cin>>N;
 switch (N%2)
 case 0 cout«“Even”; Break;
case 1 cout<<“Odd”; Break;
 }

(d) Find and write the output of the following C+ + program code :
Note : Assume all required header files are already included in the program.

#define Big (A, B) (A > B) ? A + 1: B + 2
 void main ()
 {
 char w [ ] = “Exam”;
 int L = strlen (w);
 for (int i = 0, i < L - 1, i ++)
 w [i] = Big (w[i], w [i + 1]);
 cout < < w < < endl;
 }

(e) Find and write the output of the following C++ program code :
Note : Assume all required header files are already being included in the program.

void main ()
 {
 int A [ ] = (10,12,15,17,20,30},
 for (int i = 0, i < 6, i+ +)
 {
 if (A [i] % 2 = = 0)
 A [i] / = 2;
 else if (A [i] % 3 = = 0)
 A [i] / = 3;
 if (A [i] % 5 = = 0)
 A [i] / = 5;
 }
 for (i = 0; i < 6; i ++)
 cout<<A [i]<<“#”,
 }

(f) Look at the following C+ + code and find the possible output(s) from the options (i) to (iv) following it. Also, write the maximum values that can be assigned to each of the variables R and C.
Note:
• Assume all the required header files are already being included in the code.
• The function random (n) generates an integer between 0 and n -1.

 void main ()
 {
 randomize ();
 int R = random (3), C = random (4);
 int MAT [3] [3] = {{ 10, 20, 30}, {20, 30, 40}, {30, 40, 50}},
 for (int I = 0,1 < R, I + +)
 for (int J = 0; J < C; J ++)
 {
 cout < < MAT [I] [J] <<" ";
cout<< endl;
 }
 }
(i) (ii)
10         20        30

20         30        40

30         40        50

10       20        30

20       30        40

(iii) (iv)
10       20

20       30

10       20

20       30

30       40

Solution:
(a) (i) For – user defined identifier
(ii) delete – keyword
(iii) default – keyword
(iv) Value – user defined identifier
(b) iostream.h or iomanip.h or fstream.h
string.h
stdio.h
NOTE: Ignore additional header file(s)

(c) void mainO :
 {
 int N:
 cout«"Enter an integer";
 cin»N; switch(N%2);
 case 0:
 cout«’'Even“; break;
 case 1:
 cout«"Odd”; break:
 }

(d) zyom
(e) 1#6#1#17#2#3#
(f) (ii) and (iii)
Max Value of R:2
Max Value of C:3

Question 2:
(a) Differentiate between private and public members of a class in context of Object Oriented Programming. Also give a suitable example illustrating accessibility/non-accessibility of each using a class and an object in C++.
(b) Observe the following C+ + code and answer the questions (i) and (ii).
Note :
Assume all necessary files are included.

class EXAM
 {
 long code; char EName [20]; float Marks; public :
 EXAM 0 //Member Function 1
 {
 code = 100, strcpy (EName, “Noname”);
 Marks = 0;
 }
 EXAM (EXAM &E) //Member Function 2
 {
 code = E.code + 1;
 strcpy (EName, E.EName);
 Marks = E. Marks;
 };
 void main ()
 ------------------ //Statement 1
 ------------------ //Statement 2
 }

(i) Which Object Oriented Programming feature is illustrated by the Member Function 1 and Member Function 2 together in the class EXAM ?
(ii) Write Statement 1 and Statement 2 to execute Member Function 1 and Member Function 2 respectively.
(c) Write the definition of a class RING in C + + with following description :
– Private Members
– RingNumber  // data member of integer type
– Radius  // data member of float type
– Area  // data member of float type
– CalcArea ()  // Member function to calculate and assign
// Area as 3.14 ‘Radius* Radius
Public Members
– GetArea () //A function to allow user to enter values of
// RingNumber and Radius. Also, this // function should call CalcArea () to calculate // Area .
– Show Area () //A function to display RingNumber, Radius
// and Area
(d) Answer the questions (i) to (iv) based on the following :

class One
 {
 int A1,
 protected : float A2;
 public : One ();
 void Get1 ();
 void showl ();
 };
 class Two : private One
 {
 int B1; protected : float B2;
 public : Two (), void Get2 ();
 void Show ();
 };
 Class Three : public Two
 {
 int C1;
 public : Three ();
 void Get 3 ();
 void Show ();
 };
 void main ()
 {
 Three T; //Statement 1
 ------------- // Statement 2
 }

(i) Which type of inheritance out of the following is illustrated in the above example?
Single Level Inheritance, Multilevel Inheritance, Multiple Inheritance.
(ii) Write the names of all the member functions, which are directly accessible by the object T of class Three as declared in main () function.
(iii) Write Statement 2 to call function Show () of class Two from the object T of class Three.
(iv) What will be the order of execution of the constructors, when the object T of class Three is declared inside main () ?
Solution:
(a)

Private Public
Implicit Visibility Mode
Not accessible by the objects of class
Explicit Visibility Mode Accessible by the objects of class

Example:

class A
 {
 intx; //private Member
 public: void In0; //public member
 };
 Or
 Any other correct example demonstrating difference between private and public members of a class

(b) (i) Polymorphism OR Constructor overloading OR Function Overloading
(ii) EXAM El; //Statement 1
EXAM’E2(El); //Statement 2
OR
EXAM E2=E1; //Statement 2

(c) class RING
 int RingNumber; float Radius ; float Area;
 void CalcArea()
 {
 Area=3.14*Radius*Radius;
 }
 public:
 void GetArea();
 void ShowAreaO;
 };
 void RING: :GetArea()
 {
 cin»RingNumber»Radius;
 CalcAreaO;
 }
 void RING::ShowAreaO
 {
 cout<<RingNumber«” ”<<Radius<<” ”<<Area«endl;
 }

(d) (i) Multilevel Inheritance.
(ii) Get3(),ShowO of class Three
Get2(),Show() of class Two
OR
Get3(),Show() OR Three: :Show()
Get2(),Two::Show()
NOTE:
• Marks not to be awarded for partially correct answer
• Ignore the mention of Constructors
(iii) T TWo::Show()
(iv) One,Two, Three
NOTE:
• No Marks to be awarded for any other combination/order.
• Names of the constructor/class without parenthesis is acceptable

Question 3:
(a) Write the definition of a function Reverse (int Arr [ ], int N) in C + + , which should reverse the entire content of the array Arr having N elements, without using any other array.
Example : if the array Arr contains

13 10 15 20 5

Then the array should become

5 20 15 10 13

Note:
• The function should only rearrange the content of the array.
• The function should n,ot copy the reversed content in another array.
• The function should not display the content of the array.
(b) Write definition for a function ADDMIDROW (int MAT[ ] [10], int R, int C) in C++, which finds sum of the middle row elements of the matrix MAT (Assuming C represents number of Columns and R represents . number of rows, which is an odd integer).
For example, if the content of array MAT having R as 3 and C as 5 is as follows :

1 2 3 4 5
2 1 3 4 5
3 4 1 2 5

The function should calculate the sum and display the following :
Sum of Middle Row : 15
(c) T[25][30] is a two dimensional array, which is stored in the memory along the row with each of its element
occupying 2 bytes, find the address of the element T[10] [15], if the elements T[5] [10] is stored at the memory location 25000.
(d) Write the definition of a member function ADDMEM () for a class QUEUE in C ++, to add a MEMBER in a dynamically allocated Queue of Members considering the following code is already written as a part of the program.

 struct Member
 {
 int MNO;
 char MNAME (20);
 Member ‘Next;
 Class QUEUE
 Member “Rear, “Front; public :
 QUEUE () {Rear = NULL, Front = NULL}
 void ADDMEM ();
 void REMOVEMEM ();
 ~ QUEUE ();}

(e) Convert the following Infix expression to its equivalent Postfix expression, showing the stack contents for each step of conversion.
P + (Q-R)*S/T

Solution:

(a) void Reverse(int Arr[],int N)
 {
 for (int I=0;I<N/2;I++)
 {
 int T=Arr[I];
 Arr[I]=Arr[N-I-l];
 Arr[N-I-l]=T;
 }
 }

OR
Any other correct alternative code in C + +

(b) void ADDMIDROW(int MAT[][10],int R,int C)
 {
 int MIDR=0; for (int J=0;J<C;J++)
 MIDR+=MAT[R/2][J];
 cout<<”Sum of Middle Row:”<<MIDR<<endl;
 }

OR
Any other correct alternative code in C+ +
(c) LOC(T[I][J]) = Base(T)+W*(NC*I+J)
LOC(T[5][10]) = Base(T)+2*(30*5+10).
25000= Base(T)+2*(30*5+10)
Base(T) = 25000 – 2*(160) ;
Base(T) = 25000- 320 = 24680
LOC(T[10][15])= 24680 + 2*(30*10+15)
= 24680 + 2*(315)
= 24680 + 630
= 25310
Or
LOC(T(10][15]) = LOC(T[5][10]) + 2(30*(10-5) + (15-10))
= 25000 + 2(150 + 5)
= 25000 + 2(155)
= 25000 + 310
= 25310

(d) void QUEUE: :ADDMEM0
 {
 Member *T;
 T=new Member; cin»T->MNO; gets(T->MNAME); T->Next=NULL; if (Rear==NULL)
 {
 Rear=T;Front=T;
 }
 else
 {
 Rear->Next=T;
 Rear=T;
}
}

OR
Any other equivalent code in C + +
(e) (P+ (((Q-R) *S) / T))

INFIX STACK POSTFIX
P P
+ + P
Q PQ
+ – PQ
R + – PQR
) + PQR-
* +* PQR-
S +* PQR-S
) + PQR – S*
/ +/ PQR – S*
T +/ PQR – S*T
) + PQR – S*T/
) PQR – S*T/+

OR

INFIX STACK POSTFIX
( (
P ( P
+ (+ P
( (+( P
Q (+( PQ
(+(- PQ
R (+(- PQR
) (+ PQR-
* (+* PQR-
S (+* PQR-S
/ (+/ PQR-S*
T C+/ PQR – S*T
) PQR -S*T/+

Question 4:
(a) Aditi has used a text editing software to type some text. After saving the article as WORDS.TXT, she realised that she has wrongly typed alphabet J in place of alphabet I everywhere in the article. [3]
Write a function definition for JTOI () in C++ that would display the corrected version of entire content of the file WORDS.TXT with all the alphabets “J” to be displayed as an alphabet “I” on screen.
Note : Assuming that WORD.TXT does not contain any J alphabet otherwise.
Example:
If Aditi has stored the following content in the file WORDS.TXT :
WELL, THJS JS A WORD BY JTSELF. YOU COULD STRETCH THIS TO BE A SENTENCE
The function JTOI () should display the following content:
WELL, THIS IS A WORD BY ITSELF. YOU COULD STRETCH THIS TO BE A SENTENCE
(b) Write a definition for function COUNTDEPT () in C++ to read each object of a binary file TEACHERS.DAT,
find and display the total number of teachers in the department MATHS. Assume that the file TEACHERS. DAT is created with the help of objects of class TEACHERS, which is defined below :

 class TEACHERS
 {
 intTID;
 char DEPT [20];
 public : void GET ()
 {
 cin » TID, gets, (DEPT);
 }
 void SHOW ()
 {
 cout« TID « "i" «DEPT«endl;
 }
 char *RDEPT () {return DEPT;}
 };

(c) Find the output of the following C+ + code considering that the binary file BOOK.DAT exists on the hard disk with a data of 200 books.

class BOOK
 {
 int BID;
 char BName [20];
 public : void Enter ();
 void Display ();
 };
 void main ()
 fstream InFile;
 InFile.open ("BOOK.DAT", ios :: binary | ios :: in);
 BOOK B;
 InFile.seekg (5* sizeof (B));
 InFile, read ((char *) &B, sizeof (B));
 cout« "Book Number «InFile.tellg () / size of (B) + 1;
 InFile.seekg (0, ios : : end);
 cout « "of’ « InFile.tellg () / size of (B) « endl;
 InFile.close ();
}

Solution:

 (a) void JTOI().
 {
 char ch;
 ifstream FfWORDS.TXT" );
 while(F.get(ch))
 {
 if(ch==’J’) ch=I;
 cout<<ch;
 }
 F.close(); //IGNORE
 }

OR
Any other correct function definition

(b) void COUNTDEPT()
 {
 ifstream F;
 F.open("TEACHERS,DAT", ios::binary);
 int count=0;
 Teachers obj; while(F.read((char*) &obj, sizeof(obj)))
 {
 if(strcmp(obj.RDEPTO/'MATHS”)==0)
 count++;
 }
 cout«”Number of MATHS teachers :”«count«endl;
 F.close(); //IGNORE

OR
Any other correct function definition
(c) Book Number: 7 of 200

SECTION – C

Question 5:
(a) Observe the following table CANDIDATE carefully and write the name of the RDBMS operation out of
(i) SELECTION (ii) PROJECTION (iii) UNION (iv) CARTESIAN PRODUCT, which has been used to produce the output as shown in RESULT. Also, find the Degree and Cardinality of the RESULT.
TABLE: CANDIDATE

NO NAME STREAM
C1 AJAY LAW
C2 ADITI MEDICAL
C3 ROHAN EDUCATION
C4 RISHAV ENGINEERING

RESULT

NO NAME
C3 ROHAN

(b) Write SQL queries for (i) to (iv) and find outputs for SQL queries (v) to (viii), which are based on the tables :
TABLE: BOOK

Code BNAME TYPE
F101 The Priest Fiction
L102 German easy Literature
C101 Tarzan in the lost world Comic
F102 Untold story Fiction
C102 War heroes Comic

TABLE: MEMBER

MNO MNAME CODE ISSUEDATE
M101 RaghavSinha L102 2016-10-13
M103 Sarthakjohn F102 2017-02-23
M102 Anisha Khan C101 2016-06-12

(i) To display all details from table MEMBER in descending order of ISSUEDATE.
(ii) To display the BNO and BNAME of all Fiction Type books from the table BOOK.
(iii) To display the TYPE and number of books in each TYPE from the table BOOK.
(iv) To display all MNAME and ISSUEDATE of those members from table MEMBER who have books issued {i.e„ ISSUEDATE) in the year 2017.
(v) SELECT MAX (ISSUEDATE) FROM MEMBER;
(vi) SELECT DISTINCT TYPE FROM BOOK;
(vii) SELECT A.CODE, BNAME, MNO, MNAME
FROM BOOK A, MEMBER B WHERE A.CODE=B.CODE;
(viii) SELECT BNAME FROM BOOK
WHERE TYPE NOT IN (“FICTION”, “COMIC”);

Solution:
(a) (i) SELECTION and (ii) PROJECTION
OR
(i) SELECTION
OR
(ii) PROJECTION DEGREE = 2
CARDINALITY = 1
(b) (i) SELECT * FROM MEMBER ORDER BY ISSUEDATE DESC;
(ii) SELECT Code,BNAME FROM BOOK WHERE TYPE=’Fiction’;
OR
SELECT BNO.BNAME FROM BOOK WHERE TYPE=’Fiction’;
NOTE:
Full 1 Mark for mentioning BNO does not exist in table BOOK
(iii) SELECT COUNT(*),TYPE FROM BOOK GROUP BY TYPE;
(iv) SELECT MNAME, ISSUEDATE FROM MEMBER WHERE ISSUEDATE>=’2017-01-0T AND ISSUEDATE<=’2017-12-31’;
OR
SELECT MNAME, ISSUEDATE FROM MEMBER WHERE ISSUEDATE BETWEEN ‘2017-01-01′ AND ‘2017-12-31’;
OR
SELECT MNAME,’ISSUEDATE FROM MEMBER WHERE ISSUEDATE LIKE ‘2017%’;
(v) MAX (ISSUEDATE)
2017-02-23
(vi) DISTINCT TYPE
Fiction
Literature
Comic
NOTE: Values may be written in any order
(vii) Mark for correct output

CODE BNAME MNO MNAME
L102 The priest M101 RAGHAVSINHA
F102 Untold story M103

SARTHAKJOHN

C101 Tarzan in the lost world M102

ANISHAKHAN

(viii) BNAME
German Easy
OR
BNAME
The priest
German easy
Tarzan in the lost world
Untold Story
War heroes

Question 6:
(a) State Distributive Laws of Boolean Algebra and verify them using truth table.
Draw the Logic Circuit of the following Boolean Expression using only NAND Gates :
X .Y+Y . Z
(c) Derive a Canonical SOP expression for a Boolean function F, represented by the following truth table

U V W F (U,V,W)
0 0 0 1
0 0 1 0
0 1 0 1
0 1 1 1
1 0 0 0
1 0 1 0
1 1 0 1
1 1 1 0

(d) Reduce the following Boolean Expression to its simplest form using K-Map :
F (X, Y, Z, W) = ∑(0,1, 2, 3, 4, 5,10, 11,14)

Solution:
(a) (i) X. (Y+Z)= X.Y + X.Z
(ii) X + YZ= (X + Y). (X+Z)
Truth Table Verification:
(i)
X Y z Y + Z X. (Y+Z) X.Y X.Z X.Y + X.Z

X Y z Y + Z X. (Y+Z) X.Y X.Z X.Y + X.Z
0 0 0 0 0 0 0 0
0 0 1 1 0 0 0 0
0 1 0 1 0 0 0 0
0 1 1 1 0 0 0 0
1 0 0 0 0 0 0 0
1 0 1 1 1 0 1 1
1 1 0 1 1 1 0 1
1 1 1 1 1 1 1 1

(ii)
X Y.Z + Y.Z X+Y.Z (X.Y) (X+Z) (X+Y).(X+Z)

X Y z Y.Z X+Y.Z (X.Y) (X+Z) (X+Y).(X+Z)
0 0 0 0 0 0 0 0
0 0 1 0 0 0 1 0
0 1 0 0 0 1 0 0
0 1 1 1 1 1 1 1
1 0 0 0 1 1 1 1
1 0 1 0 1 1 1 1
1 1 0 0 1 1 1 1
1 1 1 1 1 1 1 1

(b)
cbse-solved-papers-for-class-12-computer-science-c-paper-6-2
(c) F(U,V,W)= U’V’W’ + U’VW’ + U’VW + UVW*
OR
F(U,V,W)=∑(0, 2, 3, 60
(d)
cbse-solved-papers-for-class-12-computer-science-c-paper-6-3
F(X,Y,Z)= X’Z’+Y’Z+XZW’

Question 7:
(a) Differentiate between Radio Link and Microwave in context of wireless communication technologies.
(b) Amit used a pen drive to copy files from his friend’s laptop to his office computer. Soon his office computer
started abnormal functioning. Sometimes it would restart by itself and sometimes it would stop functioning totally. Which of the following options out of (i) to (iv), would have caused the malfunctioning of the computer ? Justify the reason for your chosen option : 2
(i) Computer Worm
(ii) Computer Virus
(iii) Computer Bacteria
(iv) Trojan Horse
(c) Jai is an IT expert and a freelancer. He recently used his skills to access the Administrator password for the
network server of Megatech Corpn Ltd. and provided confidential data of the organization to its Director, informing him about the vulnerability of their network security. Out of the following options (i) to (iv), which one most appropriately defines Jai. 2
Justify the reason for your chosen option :
(i) Hacker
(ii) Cracker
(iii) Operator
(iv) Network Admin
(d) Hi Speed Technologies Ltd. is a Delhi based organization which is expanding its office setup to Chandigarh. At Chandigarh office campus, they are planning to have 3 different blocks for HR, Accounts and Logistics related work. Each block has number of computers, which are required to be connected in a network for communication, data and resource sharing.
As a network consultant, you have to suggest the best network related solutions for them for issues/problems raised in (i) to (iv), keeping in mind the distances between various blocks / locations and other given parameters.
cbse-solved-papers-for-class-12-computer-science-c-paper-6-1
Shortest distances between various blocks/locations;

HR Block to Accounts Block 400 metres
Accounts Block to Logistics Block 200 metres
Logistics Block to HR Block 150 metres
DELHI Head Office to CHANDIGARH Office 270 km

Number of Computers installed at various blocks are as follows :

HR Block 70
Accounts Block 50
Logistics Block 40

(i) Suggest the most appropriate block/location to house the SERVER in the CHANDIGARH Office (out of the 3 Blocks) to get the best and effective connectivity. Justify your answer.
(ii) Suggest the best wired medium and draw the cable layout (Block to Block) to efficiently connect various Blocks within the CHANDIGARH office compound.
(iii) Suggest a device / software and its placement that would provide data security for the entire network of
CHANDIGARH Office.
(iv) Which of the following kind of network, would it be?
(a) PAN (b) WAN
(c) MAN (d) LAN

Solution:
(a) Radio Link: Data is transmitted outward from the antenna through free space in all directions. It is a Slow means of communication;
Microwave: Data is transmitted based on line of sight principle, faster than radio communication.
(b) (ii) Computer Virus
OR
(iv) Trojan Horse
• Pen drive containing Computer Virus / Trajan Horse was used before the abnormal functioning started, which might have corrupted the system files.
• Computer Virus/Trojan Horse affects the system files and start abnormal functioning in the computer (1 Mark for writing any of the options (ii) OR (iv))
(1 Mark for writing any one correct justification) [CBSE Marking Scheme 2017]
(c) (i) Hacker
A Hacker is a person who breaks into the network of an organization without any malicious intent.
(d) (i) HR Block – Because it has maximum number of computers.
(ii) Best wired medium: Optical Fibre OR CAT5 OR CAT6 OR CAT7 OR CAT8 OR Ethernet Cable
cbse-solved-papers-for-class-12-computer-science-c-paper-6-4
(iii) Firewall – Placed with the server at the HR Block
OR
Any other valid device/software name
(iv) (b) WAN and (d) LAN
OR
(b) WAN
OR
(d) LAN