91 Computer Science
91 Computer Science
COMPUTER SCIENCE
General Instructions :
(i) SECTION A refers to programming language C++.
(ii) SECTION B refers to programming language Python.
(iii) SECTION C is compulsory for all.
(iv) Answer either SECTION A or SECTION B.
(v) It is compulsory to mention on the page 1 in the answer-book whether you
are attempting SECTION A or SECTION B.
(vi) All questions are compulsory within each section.
(vii) Questions 2(b), 2(d), 3 and 4 have internal choices.
91 1 P.T.O.
SECTION A
[Only for candidates, who opted for C++]
1. (a) Which of the following are valid operators in C++ :
(i) +=
(ii) not
(iii) = /
(iv) &&
(v)
(vi) = =
(vii) ++
(viii) and 2
(b) Write the names of the correct header files, which must be included
to compile the code successfully : 1
void main()
{
char S1[20]="CS", S2[20]="2018";
strcat(S1,S2);
cout<< S1;
}
(c) Rewrite the following C++ program after removing any/all
syntactical error(s). Underline each correction done in the code : 2
Note : Assume all required header files are already included in the
program.
#define Volume(L,B,H) = L*B*H
structure Cube
{
int Length,Breadth,Height;
};
void main()
{
Cube C = [10,15,20];
cout<<Volume(Length,Breadth,Height);
}
(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.
void Convert(char *P1, char *P2)
{
char *Q;
Q=P2;
P2=P1;
P1=Q;
cout<<P1<<"*"<<P2<<endl;
}
void main()
{
char S1[]="One", S2[]="Two";
Convert(S1,S2);
cout<<S1<<"&"<<S2<<endl;
}
91 2
(e) Find and write the output of the following C++ program code : 3
Note : Assume all required header files are already included in the
program.
void Alter(float &I, int J=2)
{
I=I+J;
J=I/J;
cout<<I<<"#"<<J<<endl;
}
void main()
{
float P=25, Q=15;
Alter(P,Q);
Alter(P);
Alter(Q);
}
(f) Observe the following C++ code and find the possible output(s) from
the options (i) to (iv) following it. Also, write the minimum and
maximum values that can possibly be assigned to the variable End. 2
Note :
Assume all the required header files are already being included in
the code.
The function random(N) generates any possible integer between
0 and N-1 (both values included).
void main()
{
randomize();
int A[]={5,10,15,20,25,30,35,40};
int Start = random(2) + 1;
int End = Start + random(4);
for(int I=Start; I<=End, I++)
cout<<A[I]<<"*";
}
91 3 P.T.O.
2. (a) Given the following class Exam and assuming all necessary header
file(s) included, answer the questions that follow the code :
class Exam
{
int Marks; char EName[20];
public:
Exam (int M) //Function 1
{
Marks = M;
}
Exam (char S[]) //Function 2
{
strcpy(EName,S);
}
Exam (char S[], int M) //Function 3
{
Marks = M;
strcpy(EName,S);
}
Exam (Exam &E) //Function 4
{
Marks = E.Marks + 10;
strcpy(EName,E.EName);
}
};
void main()
{
Exam E1(10); //Statement I
Exam E2(70); //Statement II
Exam E4("THEORY",70); //Statement III
_______________; //Statement IV
}
(i) Which of the statement(s) out of (I), (II), (III), (IV) is/are
incorrect for object(s) of the class Exam ? 1
91 4
(b) Observe the following C++ code and answer the questions (i) and (ii).
Note : Assume all necessary files are included.
class Coordinate
{
int X,Y;
public:
Coordinate(int I=20, int J=10) //Function 1
{
X = J; Y = I;
}
void Show() //Function 2
{
cout<< " Coordinates are " << X << " & " << Y <<endl;
}
~Coordinate() //Function 3
{
cout<<"Erased "<<endl;
}
};
void main()
{
Coordinate C(15);
C.Show();
}
OR
91 5 P.T.O.
(c) Write the definition of a class STATS in C++ with following
description : 4
Private Members
Code // integer
Avg // integer
array Tests */
Public Members
91 6
(d) Answer the questions (i) to (iv) based on the following : 4
class GFloor
{
int GRooms;
protected:
void Give();
public:
void Take();
};
void main()
{
SFloor S;
}
(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 members, which are directly
accessible by the member function Get() of class FFloor.
(iii) Write the names of all the members, which are directly
accessible by the member function Input() of class SFloor.
(iv) Write the names of all the members, which are directly
accessible by the object S of class SFloor declared in the
main() function.
OR
91 7 P.T.O.
(d) Consider the following class Institution 4
class Institution
{
int Code;
char Course[20];
protected :
float Fee;
public:
void Reg(){cin>>Code;gets(Course);cin>>Fee;}
void Show(){cout<<Code<<Course<<Fee<<endl;}
};
Write a code in C++ to publicly derive another class Student from
the base class Institution with following members.
Data Members
Rno of type long
Name of type character of size 10
Member Functions
A constructor function to assign Rno as 100
Admit() to allow user to enter Rno and Name
Display() to display Rno and Name
0 1 2 3 4
25 8 15 49 9
0 1 2 3 4 5
7 5 12 10 8 23
NOTE :
DO NOT DISPLAY the Changed Array contents.
Do not use any other array to transfer the contents of array Arr.
1 1 0 1 0 0 1 0
0 1 0 0 1 0 1 1
0 0 1 1 1 1 0 0
1 1 0 0 0 0 1 1
NOTE :
DO NOT DISPLAY the Changed Array contents.
Do not use any other array to transfer the contents of array M.
OR
91 9 P.T.O.
(b) Write a user-defined function RowSwap(int A [4] [4]) in C++,
which swaps the contents of the first row with the contents of the
third row. 2
For example :
10 15 20 25 50 55 60 65
30 35 40 45 30 35 40 45
50 55 60 65 10 15 20 25
70 75 80 85 70 75 80 85
NOTE :
OR
91 10
(d) For the following structure of Items in C++
struct Item
{
char Name[20];
float Price;
Item *Link;
};
Given that the following declaration of class ItemStack in C++
represents a dynamic stack of Items :
class ItemStack
{
Item *Top; //Pointer with address of Topmost Item
of Stack
public:
ItemStack()
{
Top = NULL;
}
void Push(); //Function to push an Item into the
dynamic stack
void Pop(); //Function to pop an Item from the
dynamic stack
~ItemStack();
};
Write the definition for the member function void ItemStack::Pop(),
that pops the details of an Item from the dynamic stack of
ItemStack. 4
OR
(d) Write a user-defined function Push(Item S[], int &T), which
pushes the details of an Item, into the static stack of Items S, at the
location T (representing the Top end of the stack), where every Item
to be pushed into the stack is represented by the following structure : 4
struct Item
{
char Name[20];
float Price;
};
91 11 P.T.O.
(e) Convert the following Infix expression to its equivalent Postfix
expression, showing the stack contents for each step of conversion : 2
P – Q / R ^ S + T
OR
(e) Evaluate the following Postfix expression, showing the stack
contents : 2
150,25,5,/,45,+,2,*,-
4. (a) A text file named IONS.TXT contains some text. Write a
user-defined function ShowP() in C++ which displays all
such words of the file which start with alphabet 'P'. 3
For example : If the file IONS.TXT contains :
"Whether an atom will form a cation or an anion is
based on its position in the periodic table"
Then the function ShowP() should display the output as
position, periodic
OR
(a) A text file named BIG.TXT contains some text. Another text file
named SMALL.TXT needs to be created such that it would store
only the first 50 characters from the file BIG.TXT.
Write a user-defined function BigToSmall() in C++ that would
perform the above task of creating SMALL.TXT from the already
existing file BIG.TXT. 3
91 12
(b) Write a user-defined function TotalCost() in C++ to read each object
of a binary file ITEMS.DAT, and display the Name from all such
records, whose Cost is above 150. Assume that the file ITEMS.DAT is
created with the help of objects of class Item, which is defined
below : 2
class Item
{
char Name[20]; float Cost;
public:
char* RName() { return Name; }
float RCost() { return Cost; }
};
(c) Find the output of the following C++ code considering that the
binary file ITEMS.DAT exists on the hard disk with the following
5 records for the class Item containing Name and Cost. 1
Name Cost
Rice 110
Wheat 60
Cheese 200
Pulses 170
Sauce 150
void main()
{
fstream File;
File.open("ITEMS.DAT",ios::binary|ios::in);
Item T;
for (int I=1; I<=2; I++)
{
File.seekg((2*I-1)*sizeof(T));
File.read((char*)&T, sizeof(T));
cout<<"Read :"<<File.tellg()/sizeof(T)<<endl;
}
File.close();
}
OR
91 13 P.T.O.
SECTION B
[Only for candidates, who opted for Python]
1. (a) Which of the following are valid operators in Python ? 2
(i) +=
(ii) ^
(iii) in
(iv) &&
(v) between
(vi) */
(vii) is
(viii) like
(d) Find and write the output of the following Python code : 2
Str1="EXAM2018"
Str2=""
I=0
while I<len(Str1):
if Str1[I]>="A" and Str1[I]<="M":
Str2=Str2+Str1[I+1]
elif Str1[I]>="0" and Str1[I]<="9":
Str2=Str2+ (Str1[I-1])
else:
Str2=Str2+"*"
I=I+1
print Str2
91 14
(e) Find and write the output of the following Python code : 3
def Alter(P=15,Q=10):
P=P*Q
Q=P/Q
print P,"#",Q
return Q
A=100
B=200
A=Alter(A,B)
print A,"$",B
B=Alter(B)
print A,"$",B
A=Alter(A)
print A,"$",B
import random
VAL=[80,70,60,50,40,30,20,10]
Start=random.randint(1,3)
End=random.randint(Start,4)
for I in range(Start,End+1):
print VAL[I],"*",
(i) 40 * 30 * 20 * 10 * (ii) 70 * 60 * 50 * 40 * 30 *
(iii) 50 * 40 * 30 * (iv) 60 * 50 * 40 * 30 *
91 15 P.T.O.
2. (a) What is an Abstract Method in a class of Python ? Write a code in
Python to illustrate use of an Abstract Method in Python. 2
(b) class Matter:
Vol = 10
Type="SOLID"
def __init__(self,T,V=30):
self.Type = T
self.Vol = V
def Disp(self):
print self.Type,Matter.Type
print self.Vol,Matter.Vol
M1=Matter("GAS",20)
M1.Disp()
Matter.Type="LIQUID"
M2=Matter("SOLID")
M2.Disp()
OR
(ii) Mention the line number of the statement, which will call
and execute the method/function shown in Line 2. 2
Instance Attributes
- Vno # Vehicle Number
- Vehicle # Vehicle Name
- Type # Type of the Vehicle
Methods/Functions
- FindType() # To assign Type of Vehicle
# based on Name of the Vehicle as shown
# below :
Vehicle Type
MotorCycle MCYCL
Car MTV
Truck HTV
Bus HTV
91 17 P.T.O.
(d) Answer the questions (i) to (iii) based on the following :
class Super(object): #Line 1
def __init__(self,n): #Line 2
self.N = n
def Set(self,n): #Line 3
self.n =self.N+n
def SPShow(self): #Line 4
print self.N
OR
OR
91 19 P.T.O.
(b) Write definition of a method/function FindOut(Names, HisName)
to search for HisName string from a list Names, and display the
position of its presence. 3
For example :
If the Names contain ["Arun","Raj","Tarun","Kanika"]
and HisName contains "Tarun"
OR
Note : Assuming that the list has even number of values in it.
For example :
If the list Numbers contain
[25,17,19,13,12,15]
After swapping the list content should be displayed as
[17,25,13,19,15,12]
OR
91 20
(d) Write a Python method/function Count(Start,End,Step) to display
natural numbers from Start. 2
End in equal intervals of Step
For example :
If the values of Start as 14, End as 35 and Step as 6
The method should be displayed as
14
20
26
32
OR
OR
91 21 P.T.O.
(b) Write a method/function BIGWORDS() in Python to read contents
from a text file CODE.TXT, to count and display the occurrence of
those words, which are having 5 or more alphabets. 2
For example :
If the content of the file is
ME AND MY FRIENDS
ENSURE SAFETY AND SECURITY OF EVERYONE
OR
For example :
If the content of the file is
91 22
(c) Considering the following definition of class ITEMS, write a
method/function LowStock() in Python to search and display
Iname and Qty from a pickled file STOCK.DAT, for the items, whose
Qty is less than 10. 3
class ITEMS :
def __init__(self,I,Q):
self.Iname=N
self.Qty=Q
def IDisp(self):
print self.Iname,"@",self.Qty
OR
def __init__(self,N,T):
self.Name=N
self.Type=T
def Disp(self):
print self.Name,"$",self.Type
91 23 P.T.O.
SECTION C
[For all candidates]
5. (a) Observe the following table STOCK carefully and answer the
questions that follow : 2
Table : STOCK
SNO NAME PRICE
101 PEN 50
102 PENCIL 5
103 PENCIL 10
104 NOTEBOOK 50
105 ERASER 5
Which attribute out of SNO, NAME and PRICE is the ideal one for
being considered as the Primary Key and why ?
(b) Write SQL queries for (i) to (iv) and write outputs for SQL queries
(v) to (viii), which are based on the tables given below : 6
Table : TRAINS
TNO TNAME START END
11096 Ahimsa Express Pune Junction Ahmedabad Junction
12015 Ajmer Shatabdi New Delhi Ajmer Junction
1651 Pune Hbj Special Pune Junction Habibganj
13005 Amritsar Mail Howrah Junction Amritsar Junction
12002 Bhopal Shatabdi New Delhi Habibganj
12417 Prayag Raj Express Allahabad Junction New Delhi
14673 Shaheed Express Jaynagar Amritsar Junction
12314 Sealdah Rajdhani New Delhi Sealdah
12498 Shan-e-Punjab Amritsar Junction New Delhi
12451 Shram Shakti Express Kanpur Central New Delhi
12030 Swarna Shatabdi Amritsar Junction New Delhi
91 24
Table : PASSENGERS
PNR TNO PNAME GENDER AGE TRAVELDATE
P001 13005 R N AGRAWAL MALE 45 2018-12-25
P002 12015 P TIWARY MALE 28 2018-11-10
P003 12015 S TIWARY FEMALE 22 2018-11-10
P004 12030 S K SAXENA MALE 42 2018-10-12
P005 12030 S SAXENA FEMALE 35 2018-10-12
P006 12030 P SAXENA FEMALE 12 2018-10-12
P007 13005 N S SINGH MALE 52 2018-05-09
P008 12030 J K SHARMA MALE 65 2018-05-09
P009 12030 R SHARMA FEMALE 58 2018-05-09
6. (a) State any one Absorption Law of Boolean Algebra and verify it using
truth table. 2
(d) Reduce the following Boolean Expression to its simplest form using
K-Map : 3
F(P,Q,R,S) = (2,6,7,8,9,10,11,13,14,15)
7. (a) William Jones has got a file that is replicating itself in order to
spread to other computers using computer network on its own,
relying on security failures on the target computer to access it. It is
consuming a lot of network bandwidth also. Which of the following
type category of infection will it be considered ? Also, mention, what
should he do to prevent this infection ? 2
(i) Virus
(ii) Worm
(iii) Trojan Horse
(d) Write the expanded names for the following abbreviated terms used
in Networking and Communications : 2
(i) HTML
(ii) PAN
(iii) TCP
(iv) GBPS
91 27 P.T.O.
Number of computers installed at various locations are as follows :
Design Unit 40
Media Unit 50
HR Unit 110
Training Unit 40
(i) Suggest the most suitable location to install the main server
of this institution to get efficient connectivity. 1
91 28