Xii Cs Solved Sample Pap3er

Download as pdf or txt
Download as pdf or txt
You are on page 1of 14

CBSE Class 12th Computer Science

General Instructions :
1. Programming language Python.
2. All questions are compulsory within each section.

SECTION A
1. (a) Which of the following can be used as valid variable identifier(s) in Python? (2)
(i) 6pri (ii) sum (iii) num# (iv) _goa
Ans. The valid variable identifiers are:
ii) sum iv) _goa
(b) Name the Python Library modules which need to be imported to invoke the
following functions: (1)
(i) sqrt ( ) (ii) randint ( )
Ans. sqrt:math randint:random
(c) Rewrite the following code in Python after removing all syntax error(s). Underline
each correction done in the code. (2)
STRING=""WELCOME
NOTE=""
for S in range[0,8]:
print STRING(S)
print S+STRING
Ans. STRING= "WELCOME"
NOTE=""
for S in range (0,8) :
print STRING [S]
print S.STRING
Also range(0,8) will give a runtime error as the index is out of range. It should be range(0,7)
(d) Find and write the output of the following Python code: (2)
Lst1 = ["20","50","30","40"]
CNT = 3
Sum = 0
for I in [7,5,4,6]:
T = Lst1[CNT]
Sum = float (T) + I
print Sum
CNT-=1
Ans. 47.0
35.0
54.0
26.0
(e) Find and write the output of the following Python code: (3)
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) Given the following code, which is repeated four times. What could be the possible
set of outputs out of the given four sets. (2)
import random
print(15+random.random()*5)
(i) 17.dddd, 19.dddd, 20.dddd, 15.dddd
(ii) 15.dddd, 17.dddd, 19.dddd, 18.dddd
(iii) 14.dddd, 16.dddd, 18.dddd, 20.dddd
(iv) 15.dddd, 15.dddd, 15.dddd, 15.dddd
Ans. Option (ii) and (iv) are correct outputs
 random generates number N between range 0,0<=N<=1.0
 when it is multiplied with 5, the range becomes 0.0 to 5
 when 15 added to it, the range becomes 15 to 20
 so only option (ii) & (iv) fulfill the condition of range between 15 to 20
Max value 3 and minimum value 1 for variable NUM

2. (a) What are base case and recursive case? What is their role in recursive program?
(2) (2)

Ans. - In a recursive solution, the base case are predetermined solutions for the simplest version
of the problem: if the given problem is the base case, no further computation is necessary for the
result.

The recursive case is the one that calls the function again with a new set of values. The recursive
step is a set of rules that eventually reduces all versions of the problem to one of the base case
when applied repeatedly.

(b) class Exam: (2)


Regno=1
Marks=75
def init (self, r, m): #function 1
self. Regno=r
self. Marks=m91 14
def Assign (self, r, m): #function 2
Regno = r
Marks = m
def Check(self): #function 3
print self. Regno, self. Marks
print Regno, Marks
(i) In the above class definition, both the functions — function 1 as well as function 2
have similar definition. How are they different in execution ?
(ii) Write statements to execute function 1 and function 2.
Ans. (i) Function 1 is the constructor which gets executed automatically as soon as the object
of the class is created. Function 2 is a member function which has to be called to assign the
values to Regno and Marks.

(ii) Function 1 E1=Exam(1,95) # Any values in the parameter


Function 2 E1.Assign(1,95) # Any values in the parameter
(c) Define a class Cartoon in Python with the following specifications: (4)
Instance Attributes
- CartoonID # Numeric value with a default value 101
- Side # Numeric value with a default value 10
- Area # Numeric value with a default value 0
Methods :
- TotalArea ( ) # Method to calculate Area as # Side * Side
- Enter ( ) # Method to allow user to enter values of # CartoonID and Side. It should also
# Call TotalArea Method
- View ( ) # Method to display all the Attributes

Ans. class Cartoon: # can also be given as class Cartoon ( ):

Def_init_(self, B, S, A):
#Any variable instead of B, S, A, may be used
Self.Cartoon=B
Self.Side=S
Self.Side=A

def init (self):


self.CartoonID=101
self.Side=10
self.Area=0
def TotalArea(self):
self.Area=self.Side*self.Side
def Enter(self):
self.CartoonID=input("Enter CartoonID")
self.Side=input("Enter side")
self.TotalArea ( )
def View (self):

print
self.CartoonID
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
3. (a) What will be the status of the following list after the First, Second and Third
pass of the insertion 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.
16, 19, 11, 15, 10
Ans. I Pass

16 19 11 15 10

16 19 11 15 10

No Swapping
II Pass

16 19 11 15 10

16 19 11 15 10

11 16 19 15 10

III Pass

11 16 19 15 10

11 16 19 15 10
11 15 16 19 10

(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]
print s
(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

INSERT and DELETE operations of the data structure Queue. (4)

Ans. class queue:


Member= [ ]
def Addnew(self):
a=input("enter member name: ")
queue.Member.append(a)
def Remove(self):
if (queue.Member== [ ]):
print "Queue empty"
else:
print "deleted element is: ",queue.Member[0]
del queue.Member[0] # queue.Member.delete ( )
(d) Write definition of a method MSEARCH(STATES) to display all the state names from
a list of STATES, which are starting with alphabet M. (2)
For example :
If the list STATES contains
["MP","UP","WB","TN","MH","MZ","DL","BH","RJ","HR"]
The following should get displayed :
MP
MH
MZ
Ans. def MSEARCH(STATES):
for i in STATES:
if i[0]=='M':
print i
(e) Evaluate the following Postfix notation of expression: (2)
4, 2, *, 22, 5, 6,+,/,-
Ans.

ELEMENT Stack Contests

4 4

2 4, 2

* 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
self. PROD = 1000 # PROD Production
def Display(self):
print self. FCTID,":" self. FCTNM,":", self. PROD
Ans. import pickle
def ques4c ( ):
f=Factory ( )
file=open('FACTORY.DAT','rb')
try:
while True:
f=pickle.load(file)
if f.FCTID==105:
f.Display()
except EOF Error:
pass
file.close ( ) #IGNORE

SECTION B
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

M001 JAYA SCIENCE

M002 ADITYA HUMANITIES

M003 HANSRAJ SCIENCE


M004 SHIVAK COMMERCE

RESULT
NO MNAME STREAM

M002 ADITYA HUMANITIES

Ans. (i) SELECTION


Degree=3
Cardinality=1
(b) Write SQL queries for (i) to (iv) and find outputs for SQL queries (v) to (viii), which
are based on the tables. (6)
DVD

DVD

DCODE DTITLE DTYPE

F101 Henry Martin Folk

C102 Dhrupad Classical

C101 The Planets Classical

F102 Universal Soldier Folk

R102 A day in life Rock

MEMBER

MID NAME DCODE ISSUEDATE

101 AGAM SINGH R102 2017-11-30

103 ARTH JOSEPH F102 2016-12-13

102 NISHA HANS C101 2017-07-24

(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
who have DVDs issued (i.e., ISSUEDATE) in the year 2017.
Ans. SELECT NAME, ISSUEDATE FROM MEMBER WHERE
ISSUEDATE>=’2017-01-01’ AND ISSUEDATE<=’2017-12-31’;
OR SELECT NAME, ISSUEDATE FROM MEMBER WHERE ISSUEDATE
BETWEEN ‘2017-01-01’ AND ‘2017-12-31’;
OR SELECT NAME, ISSUEDATE FROM MEMBER WHERE ISSUEDATE LIKE
‘2017%’;
(v) SELECT MIN(ISSUEDATE) FROM MEMBER;
Ans. MIN(ISSUEDATE)
2016-12-13
(vi) SELECT DISTINCT DTYPE FROM DVD;
Ans. DISTINCT DTYPE
Folk
Classical
Rock
(vii) SELECT D.DCODE, NAME, DTITLE
FROM DVD D, MEMBER M WHERE D.DCODE=M.DCODE;
Ans.

DCODE NAME DTITLE


R102 AGAM SINGH A Day in Life
R102 ARTH JOSEPH Universal Soldier
C101 NISHA HANS The Planets

(viii) SELECT DTITLE FROM DVD


WHERE DTYPE NOT IN ("Folk", "Classical");
Ans. DTITle
A day in life
6. (a) State DeMorgan‖s Laws of Boolean Algebra and verify them using truth table. (2)
Ans. (i) (A.B)'=A'+B' (ii) (A+B)'=A'.B'
Truth Table Verification:
(i)
(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

1 1 0 0

1 1 1 1
Ans. G(X,Y,Z)= (X+Y+Z).( X+Y+Z’).( X+Y’+Z’).(X’+Y’+Z)
OR G(X,Y,Z)= ∏ (0,1,3,6)
(d) Reduce the following Boolean Expression to its simplest form using K-Map: (3)
E (U , V , Z , W ) = (2 , 3 , 6 , 8 , 9 , 10 , 11 , 12 , 13 )
Ans.

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

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.

Shortest distances between various blocks/locations:


Admin Block to Accounts Block 300 Metres

Accounts Block to Training Block 150 Metres

Admin Block to Training Block 200 Metres

MUMBAI Head Office to CHENNAI Office 1300 Km

(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

You might also like