Professional Documents
Culture Documents
Computer Science (2016-17) Set MS
Computer Science (2016-17) Set MS
Computer Science (2016-17) Set MS
MM: 70
Instructions:
i.
All Questions are Compulsory.
ii.
Programming Language : Section A : C++
iii. Programming Language : Section B : Python
iv. Answer either Section A or B and Section C is compulsory.
Section A
1
(a)
Ans
Syntax:
Conditional expression? Expression 1 : Expression 2;
Explanation:
If the conditional expression is true then expression 1 executes
otherwise expression 2 executes.
Example:
int y=10,x;
x=y>10?1:0;
cout<<x;
Output: 0
(1 Mark for correct explanation)
(1 Mark for correct example)
(b)
char *word1="Hello",*word2="Friends";
strcat(word1,word2);
cout<<word1;
}
Ans
iostream.h
string.h
( Mark each for writing correct header file)
(c)
Ans
#include<conio.h>
#include<iostream.h>
#include<string.h>
#include<stdio.h>
class product
{
int product_code,qty,price;
char name[20];
public:
product(){
product_code=0;qty=0;price=0;
strcpy(name,NULL);
}
void entry()
{
cout<<"\n Enter code,qty,price";
cin>>product_code>>qty>>price;
gets(name);
}
int tot_price() {return qty*price;}
};
void main()
{
product p;
p.entry();
cout<<p.tot_price();
}
( Mark for each correction upto a maximum of four corrections)
OR
(1 Mark for only identifying any 4 errors without suggesting
corrections)
(d)
{
if(*s%2==0)
*s=*s+10;
else
*s=*s+11;
}
else
{
if(*s%2==0)
*s=*s-10;
else
*s=*s-11;
}
cout<<*s<<" ";
s++;
}
}
void main()
{
int score[]={25,60,35,53};
change(score);
}
Ans
(e)
36 50 46 42
( Mark for each correct value of output)
Write the output of the following C++ program code:
Note: Assume all required header files are already being included in
the program.
class seminar
{
char topic[30];
int charges;
public:
seminar()
{
strcpy(topic,"Registration");
charges=5000;
}
seminar(char t[])
{
strcpy(topic,t);
charges=5000;
}
seminar(int c)
{
strcpy(topic,"Registration with Discount");
charges=5000-c;
}
void regis(char t[],int c)
{
strcpy(topic,t);
charges=charges+c;
}
void regis(int c=2000)
{
charges=charges+c;
}
void subject(char t[],int c)
{
strcpy(topic,t);
charges=charges+c;
}
void show()
{
cout<<topic<<"@"<<charges<<endl;
}
};
void main()
{
seminar s1,s2(1000),s3("Genetic Mutation"),s4;
s1.show();
s2.show();
s1.subject("ICT",2000);
s1.show();
s2.regis("Cyber Crime",2500);
s2.show();
s3.regis();
s3.show();
s4=s2;
s4.show();
getch();
}
Ans
Registration@5000
Registration with Discount@4000
ICT@7000
Cyber Crime@6500
Genetic Mutation@7000
Cyber Crime@6500
( Mark for each correct line of output)
Note:
Deduct Mark for not considering any @ symbol.
(f)
Ans
(a)
Ans
void show()
{
cout<<\n Hello World!;
}
void show(char na[])
{
cout<<\n Hello World! Its <<na;
}
(1 Mark for correct explanation of Function overloading)
(1 Mark for suitable example of Function overloading)
(b)
Answer the questions(i) and (ii) after going through the following
class:
class planet
{
char name[20];char distance[20];
public:
planet()
//Function 1
{
strcpy(name, "Venus");
strcpy(distance,"38 million km");
}
void display(char na[],char d[])
//Function 2
{
cout<<na<<"has "<<d<<" distance from Earth"<<endl;
}
planet(char na[], char d[])
//Function 3
{
strcpy(name,na);
strcpy(distance,d);
}
~planet()
//Function 4
{
cout<<"Planetarium time over!!!"<<endl;
}
};
I. What is Function 1 referred as? When will it be executed?
II. Write suitable C++ statement to invoke Function 2.
Ans
I. Constructor
It will be executed at the time of object creation.
( Mark for each correct answer)
II. planet p;
p.display(Pluto,7.5 Billion Km);
( Mark for each correct answer)
(c)
Fee
Classical
10000
Western
8000
Freestyle
11000
Public Members
class DanceAcademy
{
int Enrollno;
char Name[20];
char Style[20];
float Fee;
void chkfee()
{
if(strcmpi(Style, "Classical")==0)
Fee=10000;
else if(strcmpi(Style, "Western")==0)
Fee=8000;
else if(strcmpi(Style, "Freestyle")==0)
Fee=11000;
}
public:
void enrollment()
{
cout<<"Please enter Enrollno,Name,Style";
cin>>Enrollno;
gets(Name);
gets(Style);
chkfee();
}
void display()
{
cout<<"\n Entered Enrollno, Name, Style and Fee is:
"<<Enrollno<<"\t"<<Name<<"\t"<<Style<<"\t"<<Fee;
}
};
( Mark for correct syntax of class header)
( Mark for correct declarations of data members)
void registration();
void showdata();
};
(i) Name the type of inheritance illustrated in the above C++ code.
Ans
Multiple Inheritance
(1 Mark for correct answer)
(ii) Write the names of all the members, which are accessible from
the objects belonging to class outdoor_sports.
Ans
Ans
Ans
46 Bytes
(1 Mark for correct answer)
(a)
Write the definition of a function grace_score (int score [], int size)
in C++, which should check all the elements of the array and give an
increase of 5 to those scores which are less than 40.
Example: if an array of seven integers is as follows:
45, 35, 85, 80, 33, 27, 90
After executing the function, the array content should be changed as
follows:
45, 40, 85, 80, 38, 32, 90
Ans
(b)
(c)
void Library::push()
{
book *nptr;
nptr=new book;
cout<<"Enter values for bookid and bookname";
cin>>nptr->bookid;
gets(nptr->bookname);
nptr->next=NULL;
if(top==NULL)
top=nptr;
else
{
nptr->next=top;
top=nptr;
}
}
(1 Mark for creating new node)
20
30
40
50
60
70
80
90
Then after function call, the content of the array should be:
Ans
70
80
90
40
50
60
10
20
30
(e)
Ans
Element Scanned
45
45
+
32
20
10
/
*
Stack Status
45
45, 45
90
90, 32
90,32,20
90,32,20,10
90,32,2
90,30
2700
(a)
Find the output of the following C++ code considering that the
binary file sp.dat already exists on the hard disk with 2 records in it.
class sports
{
int id;
char sname[20];
char coach[20];
public:
void entry();
void show();
void writing();
void reading();
}s;
void sports::reading()
{
ifstream i;
i.open("sp.dat");
while(1)
{
i.read((char*)&s,sizeof(s));
if(i.eof())
break;
else
cout<<"\n"<<i.tellg();
}
i.close();
}
void main()
{
s.reading();
}
Ans
42
84
( Mark for each correct answer)
(b)
Ans
void word_count()
{
ifstream i;char ch[20];int c=0;
i.open("opinion.txt ");
while(!i.eof())
{
i>>ch;
c=c+1;
}
cout<<" Total number of words present in the text file are: <<c;
}
( Mark for opening opinion.txt correctly)
( Mark for fetching each word from the file correctly)
( Mark for counting each word)
( Mark for correct display)
(c)
Write a function display () in C++ to display all the students who have
got a distinction(scored percentage more than or equal to 75) from a
binary file stud.dat, assuming the binary file is containing the
objects of the following class:
class student
{
int rno;
char sname [20];
int percent;
public:
int retpercent()
{
return percent;
}
void getdetails()
{
cin>>rno;
gets(sname);
cin>>percent;
}
void showdetails()
{
cout<<rno;
puts(sname);
cout<<percent;
}
};
Ans
void display()
{
student s;
ifstream i(stud.dat);
while(i.read((char*)&s,sizeof(s)))
{
if(s.retpercent()>=75)
s.showdetails();
}
i.close();
}
( Mark for opening stud.dat correctly)
(1 Mark for reading all records from the file)
(1 Mark for comparing desired value with obtained data)
( Mark for calling showdetails() function)
Section - B (Python)
(a)
When x is reassigned with the value 3 the local x hides the global x
and hence 3 is printed.
(2 marks for explaining the output)
(Only 1 mark for explaining global and local namespace.)
(b)
Ans:
(c)
Ans:
(d)
a. random()
b. math()
( mark each for the correct modules)
Rewrite the following code after removing the syntactical errors (if
any). Underline each correction.
def chksum():
x= input("Enter a number")
if (x%2 == 0):
for i in range(2*x):
print i
else:
print "#"
( mark for each correction)
(1 mark to be given if only the errors are identified)
Observe the following Python code carefully and obtain the output,
which will appear on the screen after execution of it.
Ans:
(e)
Ans:
EA3n
( mark for each correct character of the output)
What output will be generated when the following Python code is
executed?
[11, 10, 9, 8, 7, 4]
( mark for each correct value)
(Deduct mark if output not displayed as a list i.e. missing [])
(f)
Observe the following program and answer the questions that follow:
b. Find out, which line of output(s) out of (i) to (iv) will not be
expected from the program?
I. 0#1
ii. 1#2
iii. 2#3
iv. 3#4
Ans:
a. Minimum Number = 1
Maximum Number = 3
b. Line iv is not expected to be a part of the output.
( 1 mark for correct Minimum and Maximum value)
( 1 mark for identifying iv as the answer)
Explain the two strategies employed by Python for memory
allocation.
Ans:
Garbage
Collection:
Python
schedules
garbage
collection based upon a threshold of object allocations and object deallocations. When the number of allocations minus the number of
deallocations are greater than the threshold number, the garbage
collector is run and the unused block of memory is reclaimed.
(1 mark for writing the names of both the strategies)
(1 mark for explaining any one strategy)
(2 mark for explaining both the strategies)
Observe the following class definition and answer the questions that
follow:
i. print I
ii. The statement 2 is giving an error because __Systemdate is a
private variable and hence cannot be printed outside the class.
(1 mark for correct answer of i.)
( mark for identifying __Systemdate as private variable and
mark for correct explanation)
Pname
Member Functions:
method
SetRemarks()
that
assigns
Margin
as
Margin
Remarks
Profit
method
Getdetails()
to
accept
values
for
i.
i. Multiple Inheritance
(1 mark for the correct answer)
ii. Statement 1 and 2 invoke the getSdata() function of class Shop and
getData() function of class Brand respectively.
(1 mark for the correct answer)
iii. getdata() method of class Brand is overridden.When object of class
Mall is created,
M = Mall()
M.getdata()
getdata() method of class Mall is invoked and not of class Brand is
called.
(1 mark for the correct answer)
iv. print Brand().category
(1 mark for the correct answer)
95 79 19 43 52 3
Write the passes of bubble sort for sorting the list in ascending order
till the 3rd iteration.
Ans:
Kritika was asked to accept a list of even numbers but she did not put
the relevant condition while accepting the list of numbers. You are
required to write a user defined function oddtoeven(L) that accepts the
List L as an argument and convert all the odd numbers into even by
multiplying them by 2 .
Ans:
Aastha wants to create a program that accepts a string and display the
characters in the reverse order in the same line using a Stack. She
has created the following code , help her by completing the
definitions on the basis of requirements given below :
class mystack:
def __init__(self):
self.mystr= ________________ # Accept a string
self.mylist =________________ # Convert mystr to a list
# Write code to display while removing element from the stack.
def display(self):
:
:
Ans:
20,10,-,15,3,/,+,5,*
Symbol
Operation
Stack
20
Push
20
10
Push
20,10
Pop(10)
Pop(20)
Push(20-10)
=10
10
15
Push
10,15
Push
10,15,3
Pop(3)
Pop(15)
Push(15/3)=5
10,5
Pop(5)
Pop(10)
Push(10+5)=15
15
Resul
t
Push
15,5
Pop(5)
Pop(15)
Push(15*5)=5
75
75
Observe the following code and answer the questions that follow:
File = open("Mydata","a")
_____________________ #Blank1
File.close()
i. What type (Text/Binary) of file is Mydata?
ii. Fill the Blank 1 with statement to write ABC in the file Mydata
Ans:
i. Text File
( mark for the correct answer)
ii. File.write("ABC")
( mark for the correct statement)
Ans:
Consider the following class declaration and answer the question that
follows:
A
nuj has been asked to display all the students who have scored less than
40 for Remedial Classes.
Write a user defined function to display all those students who have
scored less than 40 from the binary file Student.dat assuming it
stores all the object of the class Student mentioned above.
Ans:
(a)
Club
Member_id
Member_Name Address
Age Fee
M001
Sumit
New Delhi
20
2000
M002
Nisha
Gurgaon
19
3500
M003
Niharika
New Delhi
21
2100
M004
Sachin
Faridabad
18
3500
i.
What is the cardinality and degree of the above given table?
ii. If a new column contact_no has been added and three more
members have joined the club then how these changes will affect the
degree and cardinality of the above given table.
Ans
i. Cadinality: 4
Degree: 5
( Mark for each correct answer)
ii. Cardinality: 7
Degree: 6
( Mark for each correct answer)
(b)
Write SQL commands for the queries (i) to (iv) and output for (v) to
(viii) based on the tables Watches and Sale given below.
Watches
Watchid
Watch_Name
Price
Type
Qty_Store
W001
HighTime
10000
Unisex
100
W002
LifeTime
15000
Ladies
150
W003
Wave
20000
Gents
200
W004
HighFashion
7000
Unisex
250
W005
GoldenTime
25000
Gents
100
Sale
Watchid
W001
W003
W002
W003
W001
W002
W005
W003
Qty_Sold
10
5
20
10
15
20
10
15
Quarter
1
1
2
2
3
3
3
4
i. To display all the details of those watches whose name ends with
Time
ii. To display watchs name and price of those watches which have price
range in between 5000-15000.
vi.
sum(qty_sold)
15
30
45
15
price
7000
type
Unisex
watch_name
HighTime
LifeTime
Wave
GoldenTime
qty_store
100
150
200
100
qty_sold
25
40
30
10
Stock
75
110
170
90
(a)
Ans:
1.
2.
3.
4.
X+1 =1 or X+0=X
((A)) = A
A + A= 1 or A . A=0
(A+B) = A . B
Ans:
Ans:
(P+Q+R).(P+Q+R).(P+Q+R)
( mark each for correct maxterms)
( mark for the correct representation as POS)
(d)
F(A,B,C,D)=
Ans:
A'B'C' + D + BC
( mark for correct K MAP format)
( mark for putting 1 at the right place)
( mark for each correct groups)
( mark for the correct answer)
7
(a)
Ans:
a. Star Topology
b. Bus Topology
(1 mark for each correct answer)
(b)
Ans:
(c)
Ans:
(d)
Ans:
Ans
Daniel has to share the data among various computers of his two
offices branches situated in the same city. Name the network (out of
LAN, WAN, PAN and MAN) which is being formed in this process.
MAN
(1 mark for correct answer)
(f)
Rehaana Medicos Center has set up its new center in Dubai. It has
four buildings as shown in the diagram given below:
55 m
Accounts to Store
150 m
160 m
60 m
125 m
180 m
Number of Computers
Accounts
25
Research Lab
100
Store
15
Packaging Unit
60
1
1
1
i) Suggest a cable layout of connections between the buildings.
ii) Suggest the most suitable place (i.e. buildings) to house the server of this
organization.
1
(i) Layout 1
Layout 2
(iii)
a) For layout1, since the cabling distance between Accounts to Store is
quite large, so a repeater would ideally be needed along their path to
avoid loss of signals during the course of data flow in this route. For
layout2, since the cabling distance between Store to Recresearch Lab
is quite large, so a repeater would ideally be placed.
b) In both the layouts, a Hub/Switch each would be needed in all the
buildings to interconnect the group of cables from the different
computers in each building.
( mark for each correct answer)
(iv) Firewall
(1 mark for correct answer)