CS (Old)
CS (Old)
491/C
Candidates must write the Code on the
Roll No.
title page of the answer-book.
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 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.
.491/D 1 P.T.O.
SECTION A
[Only for candidates, who opted for C++]
1. (a) Identify the valid keywords in C++ from the following : 2
(i) If
(ii) for
(iii) case
(iv) Object
(v) struct
(vi) sub
(vii) float
(viii) My_class
(b) Write the names of the correct header files, which must be included
in the following C++ code to compile the code successfully : 1
void main()
{
int X = random(10);
int Y = random(20);
cout<<"sum of "<<X<<" and "<<Y<<" = "<<X+Y<<endl;
}
(c) Rewrite the following C++ program after removing any/all
syntactical errors with each correction underlined : 2
Note : Assume all required header files are already included in the
program.
void main()
{
cout<<"Enter two integers";
cin>>A>>B;
if A <= B
A += B;
B –= 5;
else
{
B = B + A;
A – 5 = A;
}
cout<<A<<" : "<< B << Endl;
}
.491/D 2
(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 ChangeVal(int *M, int N)
{
for(int i=0;i<N ; i++)
{
if (*M%5 == 0)
*M /= 5;
if (*M%3 == 0)
*M /= 3;
M++;
}
}
void main()
{
int Val[]={25,8,75,12};
ChangeVal(Val,4);
for(int i=0;i<4; i++)
cout<<Val[i]<<"*";
cout<<endl;
}
(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.
struct Product
{
int X, Y;
};
void Change(Product &P)
{
P.X += 5; P.Y –= 5;
}
void Multiply(int P1, int P2)
{
cout<<"First = "<<P1<<" & Second = "<<P2<<endl;
cout<<"Product = "<<P1*P2<<endl;
}
void main()
{
Product P[] = {{7,10},{10,7},{7,7}};
for(int i=0; i<3; i++)
{
Change(P[i]);
Multiply(P[i].X, P[i].Y);
}
}
.491/D 3 P.T.O.
(f) Look at 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.
void main()
randomize();
cout<<Colours[i]<<"&";
.491/D 4
(b) Observe the following C++ code and answer the questions (i), (ii),
(iii) and (iv) : 2
Note : Assume all necessary files are included.
class Triangle
{
int S1,S2,S3;
public:
Triangle(int X=0, int Y=0, int Z=0) //Function 1
{
S1=X; S2=Y; S3=Z;
}
Triangle(Triangle &T) //Function 2
{
T.S1 += 15;
S1 = T.S1;
S2 = T.S2;
T.S2 += 20;
S3 = T.S3;
}
void Show() //Function 3
{
cout<<S1<<"#"<<S2<<"#"<<S3<<endl;
}
};
void main()
{
___________ //Statement 1
___________ //Statement 2
___________ //Statement 3
}
(c) Write the definition of a class CARGO in C++ with the following
description : 4
Private Members
Distance // integer
Weight // integer
Charge // float
GetCharge()
Member function to assign value of Charge based
upon Distance and Weight as follows :
Public Members
Enter()
.491/D 6
(d) Answer the questions (i) to (iv) based on the following : 4
class Book
{
char Bno[20];
protected:
float Price;
public:
void GetB();
void ShowB();
};
class Member
{
char Mno[20];
protected:
char Name[20];
public:
void GetM();
void ShowM();
};
void main()
{
Library L;
}
(iv) Write the names of all the members, which are directly
accessible by the object L of class Library declared in the
main() function.
OR
Consider the following class College, assuming all required header
files being included :
class College
{
char Cname[20];
protected :
float Fees;
public:
void ShowCollege();
};
.491/D 8
3. (a) Write the definition of a function Mean(int A[], int N) in C++,
which should display the Mean (Average) of all the N number
of integers in the array A. 2
Example : If the array A contains following 5 elements (i.e. for N=5)
0 1 2 3 4
25 5 15 10 25
OR
.491/D 9 P.T.O.
Write the definition for a function RevAlternate(char S[][20], int N)
in C++, which reverses the contents of the strings at every odd index of
the array of strings S. 3
For example : For an array S containing 6 strings (for N=6) as follows:
ORIGINAL ARRAY S CHANGED ARRAY S
First First
Second dnoceS
Third Third
Fourth htruoF
Fifth Fifth
Sixth htxiS
Note :
• DO NOT DISPLAY the Changed Array contents.
• Do not use any other array to transfer the contents of the array S.
OR
Let us assume N[30][25] is a two-dimensional array, which is stored
in the memory along the column and each of its elements occupies
4 bytes. Find the address of the element N[5][10], if the base address
of the array is 20000. 3
(d) Write the definition of a function Push(int P[], int &T), which
pushes an integer and Pop(int P[], int &T) which pops an
integer from the static stack of integers P, where the top of the stack
is represented by index T. The stack should be able to store a
maximum of 10 integers. The functions must also check for stack
overflow and stack underflow errors. 4
OR
.491/D 10
For the following structure of Book in C++
struct Book
{
int Bno;
Book *Link;
};
Given that the following declaration of class BookStack in C++
represents a dynamic stack of Buses :
class BookStack
{
Book *Top; //Pointer T to store address of the
//topmost Node of type Book
public:
BookStack()
{
Top = NULL;
}
void Push(); //Function to push a Book Node into the
//dynamic stack
void Pop(); //Function to pop a Book Node from the
//dynamic stack
~BookStack();
};
Write the definition for the member function
void BookStack::Pop(), that pops a Book Node from the
dynamic stack of BookStack. The function must also check for an
underflow error. 4
(e) Evaluate the following Postfix expression, showing the stack contents : 2
180,15,6,*,30,+,60,-,/
OR
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
.491/D 11 P.T.O.
4. (a) A text file named SOLUTION.TXT contains some English sentences.
Another text file named TEST.TXT needs to be created such that it
replaces every occurrence of 3 consecutive letters ‘h’, ‘i’ and ‘s’
(irrespective of their cases) from each word of the file
SOLUTION.TXT, with 3 underscores (‘__’).
For example : If the file SOLUTION.TXT contains the following content :
"This is his history book."
Then TEST.TXT should contain the following :
"T____ is ____ ____tory book."
Write the definition for function CreateTest() in C++ that would
perform the above task of creating TEST.TXT from the already
existing file SOLUTION.TXT. 3
OR
A text file named AGENCIES.TXT contains some text. Write the
definition for a function Showsites() in C++ which displays all
such words of the file which have more than 9 characters and start
with "www.". For example : if the file AGENCIES.TXT contains : 3
"Name: TechnoCraft, Website: www.technocraft.com,
Name: DataTech, Website: www.datatech.com"
Then the function Showsites() should display the output as :
www.technocraft.com
www.datatech.com
class Stock
{
char Name[20]; float Price;
public:
float RPrice() { return Price; }
};
OR
.491/D 12
A binary file ELECTION.DAT contains records stored as objects of the
following class :
class ELECTION
{
char Name[20]; int Count;
public:
int GetCount() { return Count; }
Char *RName() { return Name; }
};
(c) Considering that binary file TRAINS.DAT contains 100 records of the
following class Train, find the output of the following C++ code : 1
class Train
{
int Tno; char FROM[20], To[20];
public:
void Get(); void Show();
};
void main()
{ fstream File;
File.open("TRAINS.DAT", ios::binary|ios::in);
Train T;
File.read((char*)&T,sizeof(T));
File.seekg(25*sizeof(T));
cout<<"Presently at "<< File.tellg()/sizeof(T)<< endl;
File.read((char*)&T,sizeof(T));
cout<<"Now at "<< File.tellg()/sizeof(T)<< endl;
File.close();
}
OR
Differentiate between seekg() and tellg(). 1
.491/D 13 P.T.O.
SECTION B
[Only for candidates, who opted for Python]
1. (a) Identify the valid keywords in Python from the following : 2
(i) Queue
(ii) False
(iii) in
(iv) Number
(v) global
(vi) method
(vii) import
(viii) List
(b) Name the Python Library modules which need to be imported to
invoke the following functions : 1
(i) floor()
(ii) random()
(c) Rewrite the following code in Python after removing all syntax
error(s). Underline each correction done in the code. 2
W = raw_input('Enter a word')
If W <> 'HELLO':
print W + 2
else
print W * 2
(d) Find and write the output of the following Python code : 2
def ChangeVal(M,N):
for i in range(N):
if M[i]%5 == 0:
M[i] //= 5
if M[i]%3 == 0:
M[i] //= 3
Val=[25,8,75,12]
ChangeVal(Val,4)
for N in Val:
print N,'#',
.491/D 14
(e) Find and write the output of the following Python code : 3
def Assign(P=30,Q=40):
P=P+Q
Q=P–Q
print P,'@',Q
return P
A=100
B=150
A=Assign(A,B)
print A,'@',B
B=Assign(B)
print A,'@',B
import random
Rainbow = ["VIOLET","INDIGO","BLUE","GREEN",
"YELLOW","ORANGE","RED"]
End = randrange(2)+3
Begin = randrange(End)+1
for i in range (Begin,End):
print Rainbow[i],"&",
(i) INDIGO & BLUE & GREEN & (ii) VIOLET & INDIGO & BLUE &
(iii) BLUE & GREEN & YELLOW & (iv) GREEN & YELLOW & ORANGE &
.491/D 15 P.T.O.
(b) Write the output of the given Python code : 2
class Volume(object):
Length=10
Breadth=20
Height=5
def __init__(self,X=20, Y=30, Z=10):
self.Length = X
self.Breadth = Y
self.Height = Z
def ShowVol(self):
print self.Length*self.Breadth*self.Height
print Volume.Length*Volume.Breadth*Volume.Height
V1=Volume(15,30,10)
V1.ShowVol()
Volume.Height = 20
V2=Volume(30,40)
V2.ShowVol()
OR
class Triangle(object):
def __init__(self,N1=3, N2=4, N3=5): # Function 1
self.Side1 = N1
self.Side2 = N2
self.Side3 = N3
def ShowSides(self): # Function 2
print self.Side1, self.Side2, self.Side3
def __del__(self): # Function 3
print "Nothing to show"
def Workit(): # Function 4
___________ # Statement 1
___________ # Statement 2
Workit()
(i) Write the missing Statement 1 which will invoke the Function
1 for an object T of the class Triangle with values for Side1 as
10, Side2 as 15 and Side3 as 20, and the missing Statement 2
which will invoke the Function 2 for the object T.
(ii) Write the output for the above Python code after the missing
Statement 1 and Statement 2 are correctly written. 2
.491/D 16
(c) Write the definition of a class CARGO in Python with following
description : 4
Instance Attributes
Distance
Weight
Charge
Methods/Functions
GetCharge()
# to assign value of Charge based upon Distance and
# Weight as follows :
# and Charge
.491/D 17 P.T.O.
(d) Answer the questions (i) to (iii) based on the following :
class Book(object):
def __init__(self,B_No,B_Price):
self.Bno = B_No
self.Price = B_Price
def GetB(self,B_No,B_Price):
self.Bno = B_No
self.Price = B_Price
def ShowB(self):
print self.Bno, self.Price,
class Member(object):
def __init__(self,M_Num,M_Name):
self.Mno=M_Num
self.Mname=M_Name
def GetM(self,M_Num,M_Name):
self.Mno=M_Num
self.Mname=M_Name
def ShowM(self):
print self.Mno, self.MName
class Library(Book,Member):
def __init__(self,L_Name,B,P,M,N): #Function 1
self.Lname=L_Name
Book.__init__(self,B,P)
Member.__init__(self,M,N)
def GetL(self,L_Name,B,P,M,N): #Function 2
self.Lname=L_Name
Book.GetB(self,B,P)
Member.GetM(self,M,N)
def ShowL(self):
Print self.Lname
Book.ShowB(self)
Member.ShowM(self)
L=Library('First',101,150,901,'Roshni')
L.ShowL()
L.GetL('Second',102,200,902,'Simran')
L.ShowL()
.491/D 18
(i) Write the type of the inheritance illustrated in the above
Python code. 1
Class methods/functions
.491/D 19 P.T.O.
3. (a) Consider the following randomly ordered numbers stored in a list :
325, 215, 74, 465, 520, 132, 97
Show the content of list after the First, Third and Fourth pass of
the Bubble sort method used for arranging in ascending order. 3
Note : Show the status of all the elements after each pass very
clearly encircling the changes.
OR
Consider the following randomly ordered numbers stored in a list :
325, 215, 74, 465, 520, 132, 97
Show the content of the list after the Second, Third and
Fourth pass of the Insertion sort method used for arranging in
descending order. 3
Note : Show the status of all the elements after each pass very
clearly encircling the changes.
(b) Write the definition of a function AddPrev(A, N) in Python, which
should add every previous value of list A to the next value and
assign the sum at the index of the next value. The list A contains N
number of integers. The function should finally display the entire
content of the changed list. 3
Example : If the list A contains the following 10 elements (i.e. for
N=10).
0 1 2 3 4 5 6 7 8 9
9 5 15 10 25 12 5 9 5 12
Then the function should display the output as follows :
9 # 14 # 29 # 39 # 64 # 76 # 81 # 90 # 95 # 107 #
OR
Write the definition of a function ChangeEvenOdd(Num, N) in
Python, which should add 1 to every even number and subtract 1
from every odd number. The function should finally display the
changed content of the list Num. 3
Example : If the list Num contains the following 10 elements
(i.e. for N=10)
0 1 2 3 4 5 6 7 8 9
25 12 5 10 9 5 15 9 5 12
(b) Write SQL queries for (i) to (iv) and write outputs for SQL queries
for (v) to (viii), which are based on the following two tables,
CUSTOMERS and PURCHASES : 6
Table : CUSTOMERS Table : PURCHASES
CNO CNAME CITIES SNO QTY PUR_DATE CNO
C1 SANYAM DELHI S1 15 2018-12-25 C2
C2 SHRUTI DELHI S2 10 2018-11-10 C1
C3 MEHER MUMBAI S3 12 2018-11-10 C4
C4 SAKSHI CHENNAI S4 7 2019-01-12 C7
C5 RITESH INDORE S5 11 2019-02-12 C2
C6 RAHUL DELHI S6 10 2018-10-12 C6
C7 AMEER CHENNAI S7 5 2019-05-09 C8
C8 MINAKSHI BANGALORE S8 20 2019-05-09 C3
C9 ANSHUL MUMBAI S9 8 2018-05-09 C9
S10 15 2018-11-12 C5
S11 6 2018-08-04 C7
.491/D 23 P.T.O.
(i) To display details of all CUSTOMERS whose CITIES are
neither Delhi nor Mumbai.
(ii) To display the CNAME and CITIES of all CUSTOMERS in
ascending order of their CNAME.
(iii) To display the number of CUSTOMERS along with their
respective CITIES in each of the CITIES.
(iv) To display details of all PURCHASES made (PUR_DATE) in
the year 2019.
(v) SELECT COUNT(DISTINCT CITIES) FROM CUSTOMERS;
(vi) SELECT MAX(PUR_DATE) FROM PURCHASES WHERE
QTY <10;
(vii) SELECT CITIES FROM CUSTOMERS
GROUP BY CITIES HAVING COUNT(*) = 2;
(viii) SELECT CNAME, QTY, PUR_DATE FROM CUSTOMERS,
PURCHASES WHERE CUSTOMERS.CNO = PURCHASES.CNO
AND QTY IN (10,20);
6. (a) State any one of the Absorption Laws of Boolean Algebra and verify
it using truth table. 2
.491/D 24
(d) Reduce the following Boolean Expression to its simplest form using
K-Map : 3
F(A,B,C,D) = (5,6,7,10,11,13,14,15)
Technology Feature
IP-based Protocols (LTE)
1G
True Mobile Broadband
Improved Data Services with Multimedia
2G
Mobile Broadband
Basic Voice Services
3G
Analog-based Protocol
Better Voice Services
4G Basic Data Services
First Digital Standards (GSM, CDMA)
(c) Write the names of one client side and one server side scripting
language. 1
.491/D 25 P.T.O.
(d) Write the expanded names for the following abbreviated terms used
in Networking and Communications : 2
(i) PPP
(ii) PAN
(iii) FTP
(iv) WLL
(e) Helping Hands is an NGO with its head office at Mumbai and
branches located at Delhi, Kolkata and Chennai. Their Head Office
located at Delhi needs a communication network to be established
between the head office and all the branch offices. The NGO has
received grant approval from the Central Government for setting up
the network. The physical distances between the branch offices and
the head office and the number of computers to be installed in each
of these branch offices and the head office are given below. As a
network expert you have to suggest the best possible solutions for
the queries as raised by the NGO, as given in (i) to (iv).
.491/D 26
(i) Suggest the drawing the best cable layout for effective
network connectivity of all the Branches and the Head Office
for communicating data. 1
(ii) Suggest the most suitable location to install the main server
of this NGO to communicate data with all the offices. 1
(iii) Write the name of the type of network out of the following,
which will be formed by connecting all the computer systems
across the network : 1
(A) WAN
(B) MAN
(C) LAN
(D) PAN
(iv) Suggest the most suitable medium for connecting the
computers installed across the network out of the following : 1
(A) Optical fibre
(B) Telephone wires
(C) Radio Waves
(D) Ethernet cable
.491/D 27 P.T.O.