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

SECTION A

Question 1.
(a) Write the type of C + + tokens (keywords and user defined identifiers) from the following :
(i) new
(ii) While
(iii) case
(iv) Num_2
(b) Anil typed the following C+ + code and during compilation he found three errors as follows :
(i) Function strlen should have prototype
(ii) Undefined symbol cout
(iii) Undefined symbol endl
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 Txt [ ] = “Welcome”;
 for (int C = 0; C Txt [C] = Txt [C]+l;
 cout<<Txt<<endl;
 }

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

void main ()
 {
 cout < < "Enter an Alphabet: "; cin>>CH;
 switch(CH)
 case ‘A cout < <"Ant"; Break;
 case 'B' cout < <"Bear" ; 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 Diff (N1, N2) ((N1>N2) ?N1 – N2 : N2 – N1)

 void main ()
 {
 int A, B, NUM [ ] = (10, 23,14, 54, 32};
 for (int CNT = 4 ; CNT > 0 ; CNT - -)
 {
 A=NUM[CNT] ;
 B=NUM[CNT-1] ;
 cout< }
 }

(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 *Point, Score [ ]={100, 95, 150, 75, 65, 120};
 Point = Score;
 for (int L = 0; L<6; L++) 
{ if ((*Point)%10==0) *Point /= 2; 
else 
*Point- = 2; 
if ((*Point)%5==0) *Point /= 5; Point++ ; } 
for (int L =5; L> = 0; L- -)
 cout<<Score[L]<<"*";
 }

(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 N and M.
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 N=random(3), M=random (4);
 int DOCK [3] [3] = {{1, 2, 3}, (2, 3, 4}, (3, 4, 5}};
 for (int R=0; R<N; R++)
 {
 for (int C=0; C<M; C++)
 cout< cout<<endl;
 }
 }
 (i) (ii)
1 2 3 1 2 3
2 3 4 2 3 4
3 4 5
(iii) (iv)
1 2 1 2
2 3 2 3
3 4

Answer:
(a) (i) new – Keyword
(ii) While – User defined Identifier
(iii) case – Keyword
(iv) Num_2 – User defined Identifier
(b) string.h
iostream.h OR fstream.h OR iomanip.h

(c) void main()
 {
 cout<<"Enter an Alphabet:"; char CH: // Error 1 cin>>CH;
 switch(CH)
 {.............. // Error 2(i)
 case ‘A’_ // Error 3(i)
 cout<<"Ant"; break; //Error 4(i)
 case ‘B’_ // Error 3(ii)
 cout<<"Bear"; break; // Error 4(ii)
 }.............. // Error 2(ii)
 }

(d) 22#40#9#13#
(e) 12*63*73*15*93*10*
(f) Correct Options: (ii) and (iii)
Maximum value of N = 2
Maximum value M=3

Question 2.
(a) Differentiate between protected and private 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 TEST
 {
 long TCode;
 char TTitle [20];
 float Score;
 public:
 TEST () //Member Function 1
 {
 TCode=100;strcpy(TTitle, "FIRST Test") ;Score=0;
 }
 TEST (TEST &T) //Member Function 2
 {
 TCode=E. TCode+1;
 strcpy (TTitle, T . TTitle);
 Score=T . Score;
 }
 };
 void main ()
 {
 ............ //Statement 1
 ............ //Statement 1
 }

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

class First
 {
 int X1;
 protected:
 float X2;
 public :
 First () ;
 void Enter1 (); void Displayl ();
 };
 class Second : private First
 {
 intY1;
 protected:
 float Y2;
 public:
 Second ();
 void Enter 2 ();
 void Display ();
 };
 class Third : public Second
 {
 int Z1;
 public:
 Third ();
 void Enter3 ();
 void Display ();
 };
 void main ()
 {
 Third 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 Third as declared in main() function.
(iii) Write Statement 2 to call function Display () of class Second from the object T of class Third.
(iv) What will be the order of execution of the constructors, when the object T of class Third is declared inside main() ?

Answer:
(a)

Private Protected
Implicit Visibility Mode Not accessible to member functions of derived class Explicit Visibility Mode Accessible to member function of derived class
Example:
 class A
 {
 int X;
 protected: ,
 int Y;
 public:
 void Z();
 };

OR
Any other correct example demonstrating difference between private and protected members of a class
(b) (i) Polymorphism OR Constructor overloading OR Function Overloading.
(ii) TEST T1; //Statement 1
TESTT2(T1); //Statement 2
OR
TEST T2=T1; //Statement 2

(c) class BOX
 {
 int BoxNumber;
 float Side;
 float Area;
 void ExecArea(){ Area=Side*Side;}
 public:
 void GetBox();
 void ShowBox();
 };
 void BOX::GetBox()
 {
 cin>>BoxNumber>>Side;
 ExecArea();
 }
 void BOX::ShowBox()
 { cout<<BoxNumber<<" "<<Side<<" "<<Area<<endl;
 }

(d) (i) Multilevel Inheritance.
(ii) Enter2(), Display() of class Second
Enter3(), Display() of class Third
OR
Enter2()
Second: :Display()
Enter3()
Display()
OR Third::Display()

NOTE:
• Marks not to be awarded for partially correct answer
• Ignore the mention of Constructors
(iii) T.Second::Display();
(iv) First, Second, Third

Question 3.
(a) Write the definition of a function AddUp(int Arr[], int N) in C+ +, in which all even positions (i.e., 0,2,4,…) of the array should be added with the content of the element in the next position and odd positions (i.e., 1,3,5,…) elements should be incremented by 10.
Example : if the array Arr contains

23 30 45 10 15 25

Then The Array should become

53 40 55 20 40 35

Note:
• The function should only alter the content in the same array.
• The function should not copy the altered content in another array.
• The function should not display the altered content of the array.
• Assuming, the Number of elements in the array are Even.
(b) Write a definition for a function SUMMIDCOL(int MATRIX [ ] [10], int N,int M) in C+ +, which finds the sum of the middle column’s elements of the MATRIX (Assuming N represents number of rows and M represents number of columns, which is an odd integer).
Example : If the content of array MATRIX having N as 5 and M as 3 is as follows:

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

The function should calculate the sum and display the following :
Sum of Middle Column : 15
(c) ARR[15][20] is a two-dimensional array, which is stored in the memory along the row with each of its
elements occupying 4 bytes. Find the address of the element ARR[5] [15], if the element ARR[10] [5] is stored at the memory location 35000.
(d) Write the definition of a member function PUSHGIFT ( ) for a class STACK in C++, to add a GIFT in a dynamically allocated stack of GIFTs considering the following code is already written as a part of the
program:

struct GIFT
 {
 int GCODE; //Gift Code
 char GDESC[20] ; //Gift Description
 GIFT ’Link;
 };
 class STACK
 {
 Gift ’TOP;
 public :
 STACK () { TOP=NULL ;}
 void PUSHGIFT () ;
 void POPGIFT () ;
 -STACK () ;
 };

(e) Convert the following Infix expression to its equivalent Postfix expression, showing the stack contents for each step of conversion :
X-(Y + Z)/U*V

Answer:

(a) void AddUp(int Arr[], int N)
 {
 for(int i=0; i<N; i++)
 {
 if(i%2==0) :
 Arr[i]=Arr[i]+Arr[i+l];
 else
 Arr[i]=Arr[i]+10;
 }
 }

OR
Any other correct C++code for the required function definition.

(b) void SUMMIDCOL(int MATRiX[][10],intN, int M)
 int mid-M/2; :
 int sum=0;
 for(int i=0; i<N; i++)
 {
 sum=sum+MATRIX[i][mid];
 cout<<” Sum of Middle Column”<<sum; }

OR Any other correct C++ code for the required function definition.
(c) ROW MAJOR:
Loc(ARR[I][J]) =BaseAddress + W [(I – LBR)*C + J – LBC)]
(where W=size of each element = 4 bytes, R=Number of Rows=15, C=Number of Columns=20) Assuming LBR = LBC =0
LOC(ARR[10][5])
35000 = BaseAddress + W(I*C + J)
35000 = BaseAddress + 4(10*20 + 5)
35000 = BaseAddress + 4(205)
35000 = BaseAddress + 820
BaseAddress = 35000 – 820
= 34180
LOC(ARR[5][15])= BaseAddress + W(PC + J)
= 34180 + 4(5*20 + 15)
= 34180 +4(100 + 15)
= 34180 +4×115
= 34180 + 460
= 34640
OR
Loc(ARR[I][J]) = Ref. Address + W ((I- LR)*C + (J – LC))
(where W=size of each element = 4 bytes, R=Number of Rows =15, C=Number of Columns=20 Reference Address= Address of given cell ARR[10][5]=35000
LR = Row value of given cell = 10
LC = Column value of given cell = 5)
LOC(ARR[5)(15]) = LOC(ARR[10][5]) + 4((5-10)*20 + (15-5))
LOC(ARR[5](15])=35000 + 4(-100 + 10) ;
= 35000 + 4[-90]
= 35000-360
= 34640

(d) void STACK::PUSHGIFT()
 { GIFT *T = new GIFT;
 cin>>T->GCODE;
 gets(T->GDESC);
 T->Link = TOP; .
 TOP = T;
 }

(e)

ELEMENT Stack POSTFIX
X X
X
( -( X
Y -( XY
+ -(+ XYZ
Z -(+ XYZ
) XYZ+
/ -/ XYZ+
U -/ XYZ+U
* —* XYZ+U/
V —* XYZ+U/V
XYZ+U/V*-

OR
X-(Y+Z)/U*V = (X-(((Y+Z)/U)*V))

ELEMENT Stack POSTFIX
(
X X
(
(
(
Y XY
+  -+
Z XYZ
)  – XYZ+
/  -/
 U XYZ+U

Postfix=XYZ+U/V*
Any other method for converting the given infix expression to its equivalent postfix expression showing stack contents.

Question 4.
(a) Polina Raj has used a text editing software to type some text in an article. After saving the article as MYNOTES. TXT, she realised that she has wrongly typed alphabet K in place of alphabet C everywhere in the article. Write a function definition for PURETEXT() in C + + that would display the corrected version of the entire article of the file MYNOTES. TXT with all the alphabets “K” to be displayed as an alphabet “C” on screen. 3 Note : Assuming that MYNOTES. TXT does not contain any C alphabet otherwise.
Example:
If Polina has stored the following content in the file MYNOTES. TXT :
I OWN A KUTE LITTLE KAR.
I KARE FOR IT AS MY KHILD.
The function PURETEXT () should display the following content
I OWN A CUTE LITTLE CAR.
I CARE FOR IT AS MY CHILD.
(b) Write a definition for function COUNTPICS() in C + + to read each object of a binary file PHOTOS.DAT, find and display the total number of PHOTOS of type PORTRAIT. Assume that the file PHOTOS.DAT is created with the help of objects of class PHOTOS, which is defined below :

class PHOTOS
 {
 int PCODE;
 char PTYPE[20];//Photo Type as "PORTRAIT”,’’NATURE”
 public :
 void ENTER ()
 {
 cin>>PCODE;gets (PTYPE) ;
 }
 void SHOWCASE ()
 {
 cout<<PCODE<<“: “ >>PTYPE<<endl;
 }
 char *GETPTYPE () {return PTYPE;}
 };

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

class CLIENTS
 {
 int CCode;char CName [20];
 public :
 void REGISTER () ; void DISPLAY () ;
 };
 void main ()
 {
 f stream File;
 File, open (“CLIENTS. DAT ”, ios : : binary | ios : : in) ;
 CLIENTS C;
 File . seekg (6*sizeof (C)) ;
 File, read ((char*) &C, sizeof(C));
 cout<<”Client Number: “<<File.tellg() /sizeof(C) + 1;
 File . seekg (0 , ios :: end) ;
 cout<<” of “< File . close () ;
 }

Answer:
cbse-solved-papers-for-class-12-computer-science-c-paper-7-2
cbse-solved-papers-for-class-12-computer-science-c-paper-7-3
(c) Client Number 8 of 200

SECTION C

Question 5.
(a) Observe the following table MEMBER 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 :
MEMBER

NO MNAME STREAM
M001 JAYA SCIENCE
M002 ADITYA HUMANITIES
M003 HANSRAJ SCIENCE
M004 SHIVAK COMMERCE

RESULT

NO MNAME STREAM
M002 ADITYA HUMANITIES

(b) Write SQL queries for (i) to (iv) and find outputs for SQL queries (v) to (viii), which are based on the tables.6
DVD

DCODE DTITLE DTYPE
F101 Henry Martin Folk
C102 Dhrupad Classical
C101 The Planets Classical
F102 Universal Soldier Folk
R102 A day in life Rock

MEMBER

MID NAME DCODE ISSUEDATE
101 AGAM SINGH R102 2017-11-30
103 ARTH JOSEPH F102 2016-12-13
102 NISHAHANS C101 2017-07-24

(i) To display all details from the table MEMBER in descending order of ISSUEDATE.
(ii) To display the DCODE and DTITLE of all Folk Type DVDs from the table DVD.
(iii) To display the DTYPE and number of DVDs in each DTYPE from the table DVD.
(iv) To display all NAME and ISSUEDATE of those members from the table MEMBER who have DVDs issued (i.e., ISSUEDATE) in the year 2017.
(v) SELECT MIN (ISSUEDATE) FROM MEMBER; .
(vi) SELECT DISTINCT DTYPE FROM DVD;
(vii) SELECT D. DCODE, NAME, DTITLE : ,
FROM DVD D, MEMBER M WHERE D.DCODE=M.DCODE;
(viii) SELECT DTITLE FROM DVD
WHERE DTYPE NOT IN (“Folk”, “Classical”);

Answer:
(a) (I) SELECTION DEGREE=3 CARDINALITY=1
(b) (i) SELECT * FROM MEMBER ORDER BY ISSUEDATE DESC;
(ii) SELECT DCODE,DTITLE FROM DVD WHERE DTYPE=’Folk’;
(iii) SELECT COUNT(*),DTYPE FROM DVD GROUP BY DTYPE;
(iv) SELECT NAME, ISSUEDATE FROM MEMBER WHERE
ISSUEDATE>=’2017-01-0T AND ISSUEDATE<=’2017-12-31;
OR
SELECT NAME, ISSUEDATE FROM MEMBER WHERE
ISSUEDATE BETWEEN ‘2017-01-01’ AND ‘2017-12-31’;
OR
SELECT NAME, ISSUEDATE FROM MEMBER WHERE ISSUEDATE LIKE ‘2017%’;
(v) MIN (ISSUEDATE)
2016-12-13
(vi) DISTINCT DTYPE
Folk
Classical
Rock
(vii)
DCODE NAME DTITLE
R102 AGAMSINGM Adayinlife
F102 ARIH JOSEPH Universal soldier
C101 NISHAHANS The planets
(viii) DTITLE
A day in life

Question 6.
(a) State DeMorgan’s Laws of Boolean Algebra and verify them using truth table.
(b) Draw the Logic Circuit of the following Boolean Expression using only NOR Gate :
(A+B) . (C+D)
(c) Derive a Canonical POS expression for a Boolean function G, represented by the following truth table

X Y z G (X, Y, Z)
0 0 0 0
0 0 1 0
0 1 0 1
0 1 1 0
1 0 0 1
1 0 1 1
1 1 0 0
1 1 1 1

(d) Reduce the following Boolean Expression to its simplest form using K-Map :
E (U, V, Z, W) = X (2,3,6,8,9,10,11,12,13)

Answer:
(a) (i) (A.B)’=A>+BI (ii) (A+B)’=A’.B’
Truth Table Verification:
(i)

A B A.B (A.B)’ A’ B’ A’+B’
0 0 0 1 1 1 1
0 1 0 1 1 0 1
1 0 0 1 0 1 1
1 1 1 0 0 0 0

(ii)

A B A+B (A+B)’ A’ B’ A.B’
0 0 0 1 1 1 1
0 1 1 0 1 0 0
1 0 1 0 0 1 0
1 1 1 0 0 0 0

(b)
cbse-solved-papers-for-class-12-computer-science-c-paper-7-4
(c) G(X,Y,Z)= (X+Y+Z).( X+Y+Z’).( X+Y’+Z’).(X’+Y’+Z)
OR
G(X,Y,Z)= TT (0,13,6)
(d)
cbse-solved-papers-for-class-12-computer-science-c-paper-7-5
E(u,yz,w)=uz’+v’z+u’zw’

Question 7.
(a) Differentiate between communication using Optical Fiber and Ethernet Cable in context of wired medium of communication technologies.
(b) Janish Khanna used a pen drive to copy files from his friend’s laptop to his office computer. Soon his
computer started abnormal functioning. Sometimes it would restart by itself and sometimes it would stop different applications running on it. 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 :
(i) Computer Virus
(ii) Spam Mail
(iii) Computer Bacteria
(iv) Trojan Horse
(c) Ms. Raveena Sen is an IT expert and a freelancer. She recently used her skills to access the Admin password for the network server of Super Dooper Technology Ltd. and provided confidential data of the organization to its CEO, informing him about the vulnerability of their network security. Out of the following options (i) to (iv), which one most appropriately defines Ms. Sen? 2
Justify the reason for your chosen option :
(i) Hacker
(ii) Cracker
(iii) Operator
(iv) Network Admin
(d) Hi Standard Tech Training Ltd. is a Mumbai based organization which is expanding its office set-up to Chennai. At Chennai office compound, they are planning to have 3 different blocks for Admin, Training and Accounts related activities. Each block has a 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 by them in (i) to (iv), as per the distances between various blocks/locations and other given parameters.
cbse-solved-papers-for-class-12-computer-science-c-paper-7-1
Shortest distances between various blocks/locations :

Admin Block to Accounts Block 300 Metres
Accounts Block to Training Block 150 Metres
Admin Block to Training Block 200 Metres
MUMBAI Head Office to CHENNAI Office 1300 Km

Number of computers installed at various blocks are as follows :

Training Block 150
AccountsBlock 30
Admin Block 40

(i) Suggest the most appropriate block/location to house the SERVER in the CHENNAI office (out of the 3blocks) 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 CHENNAI office compound.
(iii) Suggest a device/software and its placement that would provide data security for the entire network of the CHENNAI office.
(iv) Suggest a device and the protocol that shall be needed to provide wireless Internet access to all smartphone/laptop users in the CHENNAI office.

Answer:
(a) Optical Fibre:
Very Fast
Expensive
Immune to electromagnetic interference
Ethernet Cable:
Slower as compared to Optical Fiber
Less Expensive as compared to Optical Fiber
prone to electromagnetic interference
(b) (i) Computer Virus
OR
(iv) Trojan Horse
Justification:
Pen drive containing Computer Virus / Trojan 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
(c) (i) Hacker
A Hacker is a person who breaks into the network of an organization without any malicious intent.
(d) (i) Training 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-7-6
(iii) Firewall – Placed with the server at the Training Block
OR
Any other valid device/software name
(iv) Device Name: WiFi Router OR WiMax OR RF Router OR Wireless Modem OR RF Transmitter
Protocol: WAP OR 802.16 OR TCP/IP OR VOIP OR MACP OR 802.11