MS_Computer_Sscience_283_old
MS_Computer_Sscience_283_old
Specific Instructions:
● All programming questions have to be answered with respect to C++ Language / Python only
● In C++ / Python, ignore case sensitivity for identifiers (Variable / Functions / Structures / Class
Names)
● In Python indentation is mandatory, however, the number of spaces used for indenting may vary
● In SQL related questions – both ways of text/character entries should be acceptable for Example:
“AMAR” and ‘amar’ both are acceptable.
● In SQL related questions – all date entries should be acceptable for Example: ‘YYYY-MM-DD’,
‘YY-MM-DD’, ‘DD-Mon-YY’, “DD/MM/YY”, ‘DD/MM/YY’, “MM/DD/YY”, ‘MM/DD/YY’ and {MM/DD/YY}
are correct.
● In SQL related questions – semicolon should be ignored for terminating the SQL statements
● In SQL related questions, ignore case sensitivity.
1 (a) Write the type of C++ Operators (Arithmetic, Relational or Logical Operators) 2
from the following :
(i) ||
(ii) <=
(iii) %
(iv) *
Ans (i) || - Logical
(ii) <= - Relational
(iii) % - Arithmetic
(iv) * - Arithmetic
(½ mark for each correct answer)
(b) Write the names of the correct header files, which must be included in the 1
following C++ code to compile the code successfully :
void main()
{
char STR[]="india2020";
STR[0]=toupper(STR[0]);
puts(STR);
}
Ans stdio.h
ctype.h
(c) Rewrite the following C++ program after removing any/all syntactical errors 2
with each correction underlined :
Note : Assume all required header files are already included in the program.
(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.
Ans cb#*#H#*
(e) Find and write the output of the following C++ program code : 3
Sub Code: 283 Series:3HKP35/C Paper Code: SET: 4 [Page #3/43]
Note : Assume all required header files are already included in the program.
Ans 104@200
304@400
308@608
(f) Look at the following C++ code and find which output(s) from the options (i) to 2
(iv) is/are not possible. Also, write the minimum and maximum values that can
possibly be assigned to the variable Val.
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[4],Val;
for(int I=3; I>=0; I--)
{
Val = random(2+I) + 11;
A[I]=Val;
}
for (I=0;I<4;I++)
cout<<A[I]<<"@";
}
2. (a) Given the following class Packer and assuming all necessary header file(s)
included, answer the questions that follow the code:
class Packer
{
int PID; float WT;
public:
Packer(int ID) //Function 1
{
PID = ID;
}
Packer() //Function 2
{
PID = 1001;
WT = 100;
}
Packer(Packer &P) //Function 3
{
PID = P.PID + 1;
WT = P.WT + 10;
}
Packer(float W) //Function 4
{
WT = W;
}
Packer(int ID, float W) //Function 5
{
PID = ID;
WT = W;
}
};
void main()
{
Packer P1; //Statement I
Packer P2(70); //Statement II
__________; //Statement III
}
(i) Which function out of 1, 2, 3, 4 and 5 is a Copy Constructor and which one is a 1
default constructor in the definition of class Packer ?
(ii) Write the Statement III, to declare an object P3 of class Packer with two 1
parameters 75 and 32.5.
(b) Observe the following C++ code and answer the questions (i) and (ii).
Ans Store25Opened
Store 25 is Active
Store Closed
(ii) For the class Store, what is Function 2 known as ? When does this function get 1
executed ?
Ans Destructor
Function 2 gets executed when the object goes out off scope.
(½ mark for correctly writing Destructor)
(½ mark for writing the correct answer of the second part)
class Point
{ int x;
public:
point() {x=0;}
point(Point &P) // Copy Constructor
{ x=P.x;}
.
.
.
};
( 1 mark for correctly defining copy constructor)
( 1 mark for example of copy constructor)
OR
( 2 mark for correct explanation using an example of copy constructor)
(c) Write the definition of a class ACCESSORY in C++ with the following description: 4
Private Members
● ANO // integer
● TYPE // char array of size 20
● SECTION // char
● SECASSIGN() /* Member function to assign value of
SECTION based upon TYPE as follows : */
TYPE SECTION
MOBILE A
COMPUTER B
CAMERA C
FASHION D
Public Members
GetOne() /* Function to allow user to enter values of ANO
and TYPE then invoke SECASSIGN() to assign SECTION */
void main()
{
STORE ST;
______________; //Statement
}
(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 data members, which are directly accessible by the
member function Display() of class STORE.
(iii) Write the names of all the member functions, which are directly accessible by
the object ST of class STORE in main().
(iv) Write the statement to call and execute Display() function of class GM by the
object ST declared in the main() function.
Ans ST.GM::Display()
OR
Write a code in C++ to privately derive another class TRADER from the base
class COMPANY with the following members.
18 13 12 17 16 21 14 15
70 30 20 10 60 50 5 7
Then the function should display
100
30
110
12
OR
void FourQtr(int A[], int N)
{
int Q1=0,Q2=0,Q3=0,Q4=0;
int U1=N/4,U2=N/2,U3=3*N/4;
for(i=0;i<U1;i++)
Q1+=A[i];
for(i=U1;i<U2;i++)
Q2+=A[i];
for(i=U2;i<U3;i++)
Q3+=A[i];
for(i=U3;i<N;i++)
Q4+=A[i];
cout<<Q1<<endl<<Q2<<endl<<Q3<<endl<<Q4<<endl;
}
OR
Any valid code which serves the purpose
(1 mark for initialising four quarter correctly)
(1 mark for calculating four quarter correctly)
(1 mark for displaying four quarter correctly)
(b) Write the definition for a function TOPDIAG(int T[4][4]) in C++, which displays 2
the portion content of the 2D array as displayed in the example below. For
example :
12 14 16 18 12 14 16 18
10 11 13 15 10 11 13
22 24 26 28 22 24
20 21 23 25 20
OR
Any valid code which serves the purpose
(1 mark for uses of the correct loops)
(½ mark for identifying the correct elements)
OR
(b) Write the definition for a function DiagSum(int P[4][4]) in C++, which finds and 2
displays the sum of values on both the diagonal elements separately.
For example :
ARRAY P OUTPUT
55 50 60 45
70 75 85 80
OR
Any valid code which serves the purpose
(1 mark for uses of the correct loops)
(½ mark for identifying the correct elements)
OR
Write the definition for the member function void ITEMQUEUE::QINSERT(), that
will insert an item into the dynamic queue of ITEMQUEUE (take necessary input
from user).
Ans void ITEMQUEUE::QINSERT()
{
ITEM *Temp = new ITEM;
cout<<"Enter ID : ";
cin>>Temp->ID;
cout<<"Enter Qty: ";
cin>>Temp->Qty;
Temp->Next=NULL;
if (F==NULL)
F=R=Temp;
else
{
R->Next=Temp;
R=Temp;
}
}
350,5,/,19,2,*,20,-,-
(e) Convert the following Infix expression to its equivalent Postfix expression, 2
showing the stack contents for each step of conversion :
U - V / W * R + T
Ans
Scanned Stack Postfix
Element
( (
U ( U
- (- U
V (- UV
/ (-/ UV
W ( - / UVW
* ( - * UVW /
R ( - * UVW / R
+ ( + UVW / R * -
T ( + UVW / R * - T
) Empty UVW / R * - T +
4. (a) A text file named PRAYER.TXT contains some text. Write a function definition 3
GODLINES() in C++ that would read each line of PRAYER.TXT and display those
lines, which are starting with GOD.
Ans void GODLINES()
{
ifstream F("PRAYER.TXT");
char Line[80];
while (F.getline(Line,80))
if (Line[0]=='G' && Line[1]=='O' && Line[2]=='D')
cout<<Line<<endl;
F.close();
}
(1 Mark for opening PRAYER.TXT correctly)
(1 Mark for reading each Line (using any method) from the file)
(½ Mark for checking the Line starting with GOD)
(½ Mark for displaying the Line)
OR
(a) A text file named NOTES.TXT contains some text. Write the function definition 3
DISPLAY2() in C++ which displays first 2 letters of each word of the text file.
Assume that the file TRADER.DAT is created with the help of objects of class
Trader, which is defined below :
class Trader
{
int Code;char Region[20]; float Amount;
public:
void RegTrader();
void ShowTrader();
float GetAmount() { return Amount; }
char* GetRegion() { return Region; }
};
OR
Write definition for function ShowHigh() in C++, which displays the details of
those sweets from the file SWEETS.DAT, whose Qty is more than 1000.
void main()
{
fstream F;
F.open("CHANNEL.DAT",ios::binary|ios::in);
CHANNEL C;
F.seekg(3*sizeof(C));
F.read((char*)&C, sizeof(C));
F.read((char*)&C, sizeof(C));
C.ShowC();
F.close();
}
Ans GAMEZ:50
OR
(c) Differentiate between seekp() and tellp(). Give a suitable example to illustrate 1
the difference.
Ans tellp(): This function returns the position of the current
put pointer in terms of bytes in a file.
int n = f.tellp();
seekp(): This function takes the file put pointer to the
specified byte in a file.
SECTION B
[Only for candidates, who opted for Python]
1 (a) What is the difference between logical error and run-time error ? Give a 2
suitable example of each.
Ans Logical error: :Logical error occurs when there is a fault in the logic of Program
Logical errors are difficult to trace and can cause a program to produce
unexpected results.
Example
A=10
B=20
C=A*B
print C
Multiplying two numbers instead of adding them together may also produce
unwanted results.
Example
A=10
B=int(raw_input("Value:"))
print A/B
# If B entered by user is 0, it will be run-time error
( ½ mark each for defining Logical error and run-time error )
( ½ mark for each correct example)
OR
( Full 2 Marks for illustrating both through examples)
(b) Name the Python Library modules which need to be imported to invoke the 1
following functions :
(i) factorial()
(ii) group()
Ans (i) math
(ii) grp
(c) Rewrite the following code in Python after removing all syntax error(s). 2
Underline each correction done in the code.
Val = 32
for K in range(20:32):
Sub Code: 283 Series:3HKP35/C Paper Code: SET: 4 [Page #21/43]
if K>25
print K*Val
Else:
PRINT K+ValNumber
Ans Val = 32
for K in range(20,32): # Error 1
if K>25 : # Error 2
print K*Val
else: # Error 3
print K+Val # Error 4 and Error 5
(½ Mark for each correction, not exceeding 2 Marks)
OR
(1 mark for identifying the errors, without suggesting corrections)
(d) Find and write the output of the following Python code : 2
Txt="Some2Thing"
STxt=""
Fold=0
for C in range(0,len(Txt)):
if Txt[C]>="0" and Txt[C]<="9":
Fold=1
STxt = STxt + "#"
elif Fold==0 and Txt[C]>="A" and Txt[C]<="S":
STxt = STxt + "@"
elif Fold==1 and Txt[C]>="T" and Txt[C]<="Z":
STxt = STxt + "*"
else:
STxt = STxt + Txt[C]
print STxt
Ans @ome#*hing
( ½ Mark for mentioning @om)
( ½ Mark for e# correctly)
( ½ Mark for *hi)
( ½ Mark for ng)
(e) Find and write the output of the following Python code : 3
def Compute(A,B,C="*"):
for I in range(A,B+1):
if I%2==0:
print I,C,
else:
print I,"@",
print " "
Compute(10,14)
Compute(25,29,"#")
Compute(5,10)
Ans Indentation Error
OR
10 *
Sub Code: 283 Series:3HKP35/C Paper Code: SET: 4 [Page #22/43]
11 @
12 *
13 @
14 *
25 @
26 #
27 @
28 #
29 @
5 @
6 *
7 @
8 *
9 @
10 *
OR
10 *
12 *
14 *
14 @
26 #
28 #
29 @
6 *
8 *
10 *
10 @
(3 Marks for mentioning Indentation Error in question)
OR
(Full 3 mark for writing six correct values out of the above outputs)
(f) Out of the (i) to (iv) options, which is/are not possible outputs(s) of the 2
following program code ? Also specify the maximum value that can be assigned
to the variable R.
import random
(i) F : B : F : (ii) C : G : F :
(iii) A : G : F : (iv) G : B : G :
Ans 25 TOYS
GEN.STORE 100
105 FURNITURE
GAMES 100
( ½ Mark for each correct line of output)
OR
(b) class Flat: #Line 1
def __init__(self): #Line 2
self.No = 100 #Line 3
self.Floor = 2 #Line 4
def __del__(self): #Line 5
print "Sold Out" #Line 6
def VIEW(self): #Line 7
print self.No,self.Floor #Line 8
def Buy(): #Line 9
F=Flat() #Line 10
F.VIEW() #Line 11
Buy() #Line 12
(i) Which statement (Line number) out of Line 1 to Line 8 will be called and get
executed first, when statement at Line 10 gets executed ? Justify your answer.
Ans Lines 2,3, 4 will get executed
The given statement in Line 10 creates an Object of the Class Flat, which will
invoke the constructor defined in lines 2,3,4
(½ Mark for writing the statements that will get executed)
(½ Mark for writing the justification)
(ii) What will be the output of the above code ?
Ans 100 2
Sold Out
( ½ Mark for each correct line of output)
(c) Define a class CLUB in Python with following specifications : 4
Instance Attributes
- ID # Member Number
- Mname # Member Name
- Activity # Activity
- Fee # Membership Fee
Methods/function
Show the content of list after the First, Second and Third pass of the bubble sort
method used for arranging in descending order ?
Note : Show the status of all the elements after each pass very clearly encircling
the changes.
Ans
PASS 0 1 2 3 4 5
16 14 18 12 15 11
First 14 16 12 15 11 18
Second 14 12 15 11 16 18
Third 12 14 11 15 16 18
12 11 14 15 16 18
11 12 14 15 16 18
( 1 Mark for correctly showing status of the content after each pass upto
Third Pass)
OR
Consider the following randomly ordered numbers stored in a list : 3
16, 14, 16, 12, 15, 17
Show the content of the list after the First, Second and Third pass of the
selection sort method used for arranging in ascending order.
Note : Show the status of all the elements after each pass very clearly
encircling the changes.
Ans
PASS 0 1 2 3 4 5
16 14 16 12 15 17
First 11 16 12 15 14 18
Second 11 12 16 15 14 18
Third 11 12 14 15 16 18
11 12 14 15 16 18
( 1 Mark for correctly showing status of the content after each pass upto
Third Pass)
(b) Write definition of a method/function TenSum(SCORES) to find and display sum 3
of those scores which are less than 500 and ending with 0.
For example,
If the SCORES contain [150,206,370,110,920,530,501,120]
Note : Assuming that the list has even number of values in it. For Example :
(a) Write a statement in Python to open a text file NOTICES.TXT so that new 1
contents can be written in it.
Ans F=open("NOTICES.TXT","w")
OR
F=open("NOTICES.TXT","a")
OR
with open("NOTICES.TXT","w") as F:
OR
with open("NOTICES.TXT","a") as F:
( ½ Mark for using open function)
( ½ Mark for correctly specifying file mode)
(b) Write a method/function FIRSTTWO() in Python to read contents from a text 2
For example :
If the content of the file is
MIZORAM IS IN THE NORTH EAST OF INDIA
PUNJAB IS PROSPEROUS LAND
KERALA IS MOST LITERATE STATE
MUMBAI IS FILM CITY
MANIPUR IS FAMOUS FOR LOKTAK LAKE
class TRADING:
def __init__(self,R,A):
self.Region=R
self.Amount=A
def Display(self):
print self.Region,"#", self.Amount
class GAMER:
def __init__(self,I,T):
self.ID=I
self.TYPE=T # PC,CONSOLE, MOBILE, INTERNET
def Show(self):
print self.ID,"#", self.TYPE
5 (a) Observe the following table FOOD carefully and answer the questions that 2
follow :
TABLE: FOOD
AVGPRICE FNAME FNO ORIGIN
75 DOSA F01 SOUTH INDIA
100 BURGER F03 AMERICAN
45 VADA PAV F04 MAHARASHTRA
70 CHOW MEIN F09 CHINA
70 CHOLE BHATURE F15 PUNJAB
80 SARSON KA SAAG F12 RAJASTHAN
25 MAKKI KI ROTI F11 RAJASTHAN
Ans Degree: 4
Cardinality: 7
(½ Mark for writing correct Degree)
(½ Mark for writing correct Cardinality)
(ii) Which attribute out of AVGPRICE, FNAME, FNO and ORIGIN of table FOOD is
the ideal one for being considered as the Primary Key and why ?
Ans Primary Key: FNO OR FNAME (any one)
Reason: Unique values for identification of each tuple/record
(½ Mark for writing correct Primary key)
(½ Mark for writing correct Reason)
(b) Write SQL queries for (i) to (iv) and write outputs for SQL queries (v) to (viii), 6
which are based on the following tables :
TABLE: FURNITURE
FNO FNAME MATERIAL QTY SUPID
F01 CLASSIC BED WOOD 12 S01
F02 SOFT SOFA LEATHER 50 S05
F03 SHAHI BED METAL 5 S06
TABLE: SUPPLIER
SUPID SNAME TURNOVER CONTACT
S01 WOOD FINISHERS 5600000 P K MANTRA
S02 SHINE N CUT 12000000 F SAHOO
S04 PLASTINA TECH 32000000 T CHANDRA
S05 SOFTELIA 56000000 S JOHN
S06 SOLID METALS 45000000 P C KATKAR
(i) To display details of all the furniture from table FURNITURE, which are either
GLASS or LEATHER material.
Ans SELECT * FROM FURNITURE
WHERE MATERIAL = 'GLASS' OR MATERIAL = ‘LEATHER’;
Or
SELECT * FROM FURNITURE
WHERE MATERIAL IN ('GLASS', 'LEATHER');
(ii) To display the FNO, FNAME, QTY of those furnitures from table FURNITURE,
whose QTY is more than 100.
Ans SELECT FNO, FNAME, QTY FROM FURNITURE WHERE QTY>100;
Ans DISTINCT(MATERIAL)
WOOD
LEATHER
METAL
PLASTIC
GLASS
(½ Mark for writing correct output, ignore the output heading)
6 (a) State any one De Morgan’s Law of Boollean Algebra and verify it using truth 2
table.
Ans (X+Y)’=X’.Y’
Verification:
X Y X+Y (X+Y)’ X’ Y’ X’.Y’
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
OR
(X.Y)’=X’+Y’
Verification:
X Y X.Y (X.Y)’ X’ Y’ X’+Y’
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
Sub Code: 283 Series:3HKP35/C Paper Code: SET: 4 [Page #38/43]
(2 Mark for correctly verifying the (X+Y)’ =X’.Y’ using Truth Table)
OR
(2 Mark for correctly verifying the (X.Y)’ =X’+Y’ using Truth Table)
(b) Draw the Logic Circuit of the following Boolean Expression : 2
A’.(B’ + C) + D’
Ans
P Q R F (P,Q,R)
0 0 0 1
0 0 1 1
0 1 0 0
0 1 1 1
1 0 0 0
1 0 1 0
1 1 0 1
1 1 1 0
F(U,V,W,Z) = ∑(0,2,4,5,8,10,11,13,14,15)
F(U,V,W,Z)=UW+V’Z’+U’VW’+VW’Z
F(U,V,W,Z)=UW+V’Z’+U’W’Z’+VW’Z
F(U,V,W,Z)=UW+V’Z’+U’VW’+UVZ
( ½ Mark for correctly representing K-Maps for the given expression)
( ½ Mark for each grouping)
Use an antivirus application to prompt her about threats and to disinfect the
affected Laptop files and Operating System.
(1 Mark for writing any correct answer Virus OR Trojan Horse)
(1 Mark for writing any correct measure to remove the infection from her
Laptop)
(b) Mr. Priyaver Desai was travelling from Mumbai to Delhi for his vacation along 1
with his brand new Laptop (with no data and software installed in it) and one
brand new portable hard drive. These items, he had bought for gifting to his
nephew in Delhi. While travelling in the train, a co-traveller ran away with both
these items. Do you think Mr. Desai should report this as a Cyber Crime or any
other crime ? Write the reason for your answer.
Ans Mr. Desai should report to local police as regular theft.
Reason: Stealing of gadgets without any digital content is not considered a case
of Cyber crime.
(½ Mark for writing correct answer)
(½ Mark for writing correct reason)
(c) Give two differences between Video Conferencing and Text Chat service. 1
Ans
Video Conferencing Text Chat service
Video conferencing services allow real Text chat services allow you to receive
time communication between two or and reply to text messages.
more people.
SIP ( Session Initiation Protocol) is IRC (Internet Relay Protocol) is
required for Video Conferencing. required for Text chat services.
(i) Suggest the most suitable location to install the main server of Global 1
Knowledge Share Institute to get efficient connectivity with all the blocks.
Also, mention which Topology of network, will be formed by connecting all the
computer systems within each centre :
● Bus Topology or Star Topology
Ans Optical Fiber
Star Topology
(½ Mark for writing the correct network cable)
(½ Mark for writing the correct Topology)