Computer Science Class 12 Cbse Previous Year Question Paper 2017
Computer Science Class 12 Cbse Previous Year Question Paper 2017
General Instructions :
SECTION A
[Only for candidates, who opted for C++]
1. (a) Write the type of C++ tokens (keywords and user defined identifiers) from the
following: (2)
(i) new (ii) While (iii) case (iv) Num_2
Ans. (i) new - Keyword (ii) While - User defined Identifier
(iii) case - Keyword (iv) Num_2 - User defined Identifier
(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: (1)
void main( )
{
char Txt [ ] = "Welcome";
for (int C= 0; C<strlen(Txt); C++)
Txt[C] = Txt[C]+1;
1 / 31
For more such free study materials, visit www.mathongo.com
MathonGo CBSE Class 12 Previous Year Papers
cout<<Txt<<endl;
}
Ans. string.h
iostream.h OR fstream.h OR iomanip.h
(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;
}
Ans. 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) Find and write the output of the following C++ program code: 2
Note: Assume all required header files are already included in the program.
#define Diff(N1,N2) ((N1>N2)?N1-N2:N2-N1)
void main ( )
{
2 / 31
For more such free study materials, visit www.mathongo.com
MathonGo CBSE Class 12 Previous Year Papers
3 / 31
For more such free study materials, visit www.mathongo.com
MathonGo CBSE Class 12 Previous Year Papers
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<<DOCK[R][C]<<" ";
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
4 / 31
For more such free study materials, visit www.mathongo.com
MathonGo CBSE Class 12 Previous Year Papers
Private Protected
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) 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;
5 / 31
For more such free study materials, visit www.mathongo.com
MathonGo CBSE Class 12 Previous Year Papers
}
};
void main ( )
{
_______ //Statement 1
_______ //Statement 2
}
(i) Which Object Oriented Programming feature is illustrated by the Member Function
1 and the Member Function 2 together in the class TEST? (1)
Ans. Polymorphism OR Constructor overloading OR Function Overloading
(ii) Write Statement 1 and Statement 2 to execute Member Function 1 and Member
Function 2 respectively. (1)
Ans. TEST T1;
TEST T2(T1); //Statement 2
OR
TEST T2=T1; //Statement 2
(c) Write the definition of a class BOX in C++ with the following description: (4)
Private Members
- Box Number // data member of integer type
- Side // data member of float type
- Area // data member of float type
- Exec Area ( ) // 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 Exec Area ( ) to calculate
// Area
- ShowBox ( ) // A function to display Box Number, Side
// and Area
Ans. class BOX
{
int BoxN mber ;
6 / 31
For more such free study materials, visit www.mathongo.com
MathonGo CBSE Class 12 Previous Year Papers
float Side ;
float Area ;
void Exec Area ( ){ Area=Side*Side;}
public:
void GetBox ( );
void ShowBox ( );
};
void BOX::Get Box ()
{
cin>>BoxNumber>>Side;
Exec Area ( );
}
void BOX::ShowBox ( )
{
cout<<BoxNumber<<” ”<<Side<<” ”<<Area<<endl;
(d) Answer the questions (i) to (iv) based on the following: (4)
class First
{
int X1;
protected:
float X2;
public:
First ( );
void Enter1 ( ); void Display1( );
};
class Second: private First
{
int Y1;
protected:
float Y2;
public:
Second ( );
void Enter2 ( );
7 / 31
For more such free study materials, visit www.mathongo.com
MathonGo CBSE Class 12 Previous Year Papers
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
Ans. Multilevel 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.
Ans. Enter2( ), Display( ) of class Second
Enter3( ), Display( ) of class Third
OR
Enter2( )
Second::Display( )
Enter3( )
Display( ) OR Third::Display( )
(iii) Write Statement 2 to call function Display ( ) of class Second from the object T of
class Third.
Ans. T.Second: :Display ( );
(iv) What will be the order of execution of the constructors, when the object T of class
Third is declared inside main ( )?
Ans. First, Second, Third
8 / 31
For more such free study materials, visit www.mathongo.com
MathonGo CBSE Class 12 Previous Year Papers
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.
(3)
Example: if the array Arr contains
23 30 45 10 15 25
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.
9 / 31
For more such free study materials, visit www.mathongo.com
MathonGo CBSE Class 12 Previous Year Papers
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
Ans. void SUMMIDCOL(int MATRIX[][10],int N,int M)
{
int mid=M/2;
int sum=0;
for(int i=0; i<N; i++)
{
sum=sum+MATRIX[i][mid];
} c
out<<” Sum of Middle Column”<<sum;
} O
R
Any other correct C++ code for the required function definition
(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. (3)
Ans. 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)
10 / 31
For more such free study materials, visit www.mathongo.com
MathonGo CBSE Class 12 Previous Year Papers
11 / 31
For more such free study materials, visit www.mathongo.com
MathonGo CBSE Class 12 Previous Year Papers
Gift *TOP;
public:
STACK(){TOP=NULL;}
void PUSHGIFT ( );
void POPGIFT ( );
~STACK ( );
};
Ans. void STACK::PUSHGIFT ( )
{
GIFT *T = new GIFT;
cin>>T->GCODE;
gets(T->GDESC);
T->Link = TOP;
TOP = T;
}
(e) Convert the following Infix expression to its equivalent Postfix expression, showing
the stack contents for each step of conversion: (2)
X – (Y + Z) / U * V
Ans.
X X
- - X
( -( X
Y -( XY
+ -(+ XY
Z -(+ XYZ
) - XYZ+
/ -/ XYZ+
U -/ XYZ+U
12 / 31
For more such free study materials, visit www.mathongo.com
MathonGo CBSE Class 12 Previous Year Papers
* -* XYZ+U/
V -* XYZ+U/V
XYZ+U/V*-
OR
X-(Y+A)/U*V = (X-(((Y+Z)/U) *V))
X X
- -
Y XY
+ -+
Z XYZ
) - XYZ+
/ -/
U XYZ+U
) - XYZ+U/
* -*
V XYZ+U/V
) XYZ+U/V*
) XYZ+U/V*-
Postfix= XYZ+U/V*-
OR Any other method for converting the given infix expression to its equivalent postfix
13 / 31
For more such free study materials, visit www.mathongo.com
MathonGo CBSE Class 12 Previous Year Papers
14 / 31
For more such free study materials, visit www.mathongo.com
MathonGo CBSE Class 12 Previous Year Papers
F.close ( ); //IGNORE
}
OR
Any other correct function definition
(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: (2)
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;}
};
Ans. void COUNTPICS()
{
ifstream F;
F.open ("PHOTOS.DAT",
ios::binary);
int count=0;
PHOTOS obj;
while(F.read((char*)&obj,
sizeof(obj)))
{
15 / 31
For more such free study materials, visit www.mathongo.com
MathonGo CBSE Class 12 Previous Year Papers
if(strcmp(obj. GETPTYPE(),“PORTRAIT”)==0)
count++;
} c
out<<”Number of PORTRAIT photos :”<<count;
F.close ( ); //IGNORE
}
OR Any other correct function definition
(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 : (1)
class CLIENTS
{
int CCode; char CName[20];
public:
void REGISTER ( ); void DISPLAY();
};
void main ( )
{
fstream 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.tellg()/sizeof(C)<<endl;
File.close();
}
Ans. Client Number 8 of 200
SECTION B
[Only for candidates, who opted for Python]
1. (a) Which of the following can be used as valid variable identifier(s) in Python? (2)
(i) 4thSum (ii) Total (iii) Number# (iv) _Data
16 / 31
For more such free study materials, visit www.mathongo.com
MathonGo CBSE Class 12 Previous Year Papers
17 / 31
For more such free study materials, visit www.mathongo.com
MathonGo CBSE Class 12 Previous Year Papers
class INVENTORY:
def __init__(self,C=101,N="Pad",Q=100): #constructor
self.Code=C
self.IName=N
self.Qty=int(Q);
def Procure(self,Q):
self.Qty = self.Qty + Q
def Issue(self,Q):
self.Qty -= Q
def Status(self):
print self.Code,":",self.IName,"#",self.Qty
I1=INVENTORY ( )
I2=INVENTORY(105,"Thumb Pin",50)
I3=INVENTORY(102,"U Clip")
I1.Procure(25)
I2.Issue(15)
I3.Procure(50)
I1.Status ( )
I3.Status ( )
I2.Status ( )
Ans. Output
101 : Pad # 125
102 : U Clip # 150
105 : Thumb Pin # 35
(f) What are the possible outcome(s) executed from the following code? Also specify the
maximum and minimum values that can be assigned to the variable N. (2)
import random
NAV = ["LEFT","FRONT","RIGHT","BACK"];
NUM = random.randint(1,3)
NAVG = ""
for C in range (NUM,1,-1):
NAVG = NAVG+NAV[I]
print NAVG
18 / 31
For more such free study materials, visit www.mathongo.com
MathonGo CBSE Class 12 Previous Year Papers
19 / 31
For more such free study materials, visit www.mathongo.com
MathonGo CBSE Class 12 Previous Year Papers
Def_init_(self, B, S, A):
#Any variable instead of B, S, A, may be used
Self.Box=B
Self.Side=S
Self.Side=A
def __init__(self):
self.BoxID=101
self.Side=10
self.Area=0
def ExecArea(self):
self.Area=self.Side*self.Side
def NewBox(self):
self.BoxID=input("Enter BoxID")
self.Side=input("Enter side")
self.ExecArea ( ) # OR ExecArea(self)
def viewBox (self):
20 / 31
For more such free study materials, visit www.mathongo.com
MathonGo CBSE Class 12 Previous Year Papers
print self.BoxID
print self.Side
print self.Area
(d) Differentiate between static and dynamic binding in Python ? Give suitable
examples of each. (2)
Ans. Static Binding: It allows linking of function call to the function definition during
compilation of the program.
Dynamic Binding: It allows linking of a function during run time. That means the code of the
function that is to be linked with function call is unknown until it is executed. Dynamic
binding of functions makes the programs more flexible.
(e) Write two methods in Python using the concept of Function Overloading
(Polymorphism) to perform the following operations: (2)
(i) A function having one argument as Radius, to calculate Area of Circle as
3.14*Radius*Radius.
(ii) A function having two arguments as Base and Height, to calculate Area of right-angled
triangle as 0.5*Base* Height.
Ans. def Area(R):
print 3.14*R*R
def Area(B,H):
print 0.5*B*H
Note: Python does not support function overloading “ as illustrated in
the example shown above ”. If you run the code, the second Area(B,H)
definition will overide the first one.
3. (a) What will be the status of the following list after the First, Second and Third pass
of the bubble sort method used for arranging the following elements in ascending order
? (3)
Note : Show the status of all the elements after each pass very clearly underlining the
changes.
52, 42, –10, 60, 90, 20
Ans. I Pass
52 42 -10 60 90 20
42 52 -10 60 90 20
21 / 31
For more such free study materials, visit www.mathongo.com
MathonGo CBSE Class 12 Previous Year Papers
42 -10 52 60 90 20
42 -10 52 60 90 20
42 -10 52 60 90 20
42 -10 52 60 20 90
II Pass
42 -10 52 60 20 90
-10 42 52 60 20 90
-10 42 52 60 20 90
-10 42 52 60 20 90
-10 42 52 20 60 90
III Pass
-10 42 52 20 60 90
-10 42 52 20 60 90
-10 42 52 20 60 90
-10 42 20 52 60 90
(b) Write definition of a method EvenSum(NUMBERS) to add those values in the list of
NUMBERS, which are odd. (3)
Ans. def EvenSum(NUMBERS):
n=len(NUMBERS)
s=0
for i in range(n):
if (i%2!=0):
s=s+NUMBERS[i]
p
(c) Write Addnew(Member) and Remove(Member) methods in Python to Add a new
Member and Remove a Member from a list of Members, considering them to act as
22 / 31
For more such free study materials, visit www.mathongo.com
MathonGo CBSE Class 12 Previous Year Papers
4 4
2 4, 2
23 / 31
For more such free study materials, visit www.mathongo.com
MathonGo CBSE Class 12 Previous Year Papers
* 8
22 8, 22
5 8, 22, 5, 6
6 8, 22, 5, 6
+ 8, 22, 11
/ 8, 2
- 6
Answer: 6
4. (a) Differentiate between file modes r+ and rb+ with respect to Python. (1)
Ans. r+ Opens a file for both reading and writing. The file pointer placed at the beginning of
the file.
rb+ Opens a file for both reading and writing in binary format. The file pointer placed at the
beginning of the file.
(b) Write a method in Python to read lines from a text file MYNOTES.TXT, and display
those lines, which are starting with the alphabet ―K‖. (2)
Ans. def display ( ):
file=open('MYNOTES.TXT','r')
line=file.readline ( )
while line:
if line[0]=='K' :
print line
line=file.readline ( )
file.close ( ) #IGNORE
(c) Considering the following definition of class FACTORY, write a method in Python to
search and display the content in a pickled file FACTORY.DAT, where FCTID is matching
with the value ―’105’. (3)
class Factory:
def __in it__(self, FID, FNAM):
self. FCTID = FID # FCTID Factory ID
self. FCTNM = FNAM # FCTNM Factory Name
24 / 31
For more such free study materials, visit www.mathongo.com
MathonGo CBSE Class 12 Previous Year Papers
SECTION C
[For all the candidates]
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: (2)
MEMBER
NO MNAME STREAM
RESULT
25 / 31
For more such free study materials, visit www.mathongo.com
MathonGo CBSE Class 12 Previous Year Papers
NO MNAME STREAM
DVD
MEMBER
(i) To display all details from the table MEMBER in descending order of ISSUEDATE.
Ans. SELECT * FROM MEMBER ORDER BY ISSUEDATE DESC;
(ii) To display the DCODE and DTITLE of all Folk Type DVDs from the table DVD.
Ans. SELECT DCODE,DTITLE FROM DVD WHERE DTYPE=’Folk’;
(iii) To display the DTYPE and number of DVDs in each DTYPE from the table DVD.
Ans. SELECT COUNT(*),DTYPE FROM DVD GROUP BY DTYPE;
(iv) To display all NAME and ISSUEDATE of those members from the table MEMBER
26 / 31
For more such free study materials, visit www.mathongo.com
MathonGo CBSE Class 12 Previous Year Papers
27 / 31
For more such free study materials, visit www.mathongo.com
MathonGo CBSE Class 12 Previous Year Papers
(ii)
(b) Draw the Logic Circuit of following Boolean Expression using only NOR Gates: (2)
(A+B).(C+D)
Ans.
(c) Derive a Canonical POS expression for a Boolean function G, represented by the
following truth table: (1)
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
28 / 31
For more such free study materials, visit www.mathongo.com
MathonGo CBSE Class 12 Previous Year Papers
1 1 0 0
1 1 1 1
OR
E(U,V,Z,W)=UZ’+V’Z+U’ZW’
7. (a) Differentiate between communication using Optical Fiber and Ethernet Cable in
context of wired medium of communication technologies. (2)
Ans. - 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) 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
29 / 31
For more such free study materials, visit www.mathongo.com
MathonGo CBSE Class 12 Previous Year Papers
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: (2)
(i) Computer Virus (ii) Spam Mail (iii) Computer Bacteria (iv) Trojan Horse
Ans. (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) 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
Ans. (i) Hacker - A Hacker is a person who breaks into the network of an
organization without any malicious intent.
(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.
30 / 31
For more such free study materials, visit www.mathongo.com
MathonGo CBSE Class 12 Previous Year Papers
(i) Suggest the most appropriate block/location to house the SERVER in the CHENNAI
office (out of the 3 blocks) to get the best and effective connectivity. Justify your
answer. (1)
Ans. Training Block - Because it has maximum number of computers.
(ii) Suggest the best wired medium and draw the cable layout (Block to Block) to
efficiently connect various blocks within the CHENNAI office compound. (1)
Ans. Best wired medium: Optical Fibre OR CAT5 OR CAT6 OR CAT7 OR CAT8 OR Ethernet
Cable
(iii) Suggest a device/software and its placement that would provide data security for
the entire network of the CHENNAI office. (1)
Ans. Firewall - Placed with the server at the Training Block OR Any other valid device/
software name
(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. (1)
Ans. Device Name: WiFi Router OR WiMax OR RF Router OR Wireless Modem OR RF
Transmitter
31 / 31
For more such free study materials, visit www.mathongo.com