CBSE Sample Papers for Class 12 Computer Science Set 3 with Solutions

Practicing the CBSE Sample Papers for Class 12 Computer Science Set 3 allows you to get rid of exam fear and be confident to appear for the exam.

CBSE Sample Papers for Class 12 Computer Science Set 3 with Solutions

Section-A

Question 1.
State True or False:
Lists and dictionaries are mutable.
Answer:
True

Question 2.
In complex number a + ib, b represents as:
(a) real part
(b) imaginary part
(c) special part
(d) None of these
Answer:
(b) imaginary part

CBSE Sample Papers for Class 12 Computer Science Set 2 with Solutions

Question 3.
What is the output of the following code?
num = 4 + float (7)/int (2.0)
print (“num=”, num)
(a) num = 7.0
(b) num = 7.5
(c) Error
(d) Num = 10.5
Answer:
(b) num = 7.5

Question 4.
Identify the output of the following Python statement.
[st] = [10,15, 20, 25, 30]
[st]. insert(3,4)
[st] .inset (2,3)
print(Istl[-5])
(a) 2
(b) 3
(c) 4
(d) 20
Answer:
(b) 3

Question 5.
Given: s-‘Olympic@gmail.com”. What will be the output of:
print(s[2: :2])
(a) ‘ypealem’
(b) ‘ypcgalcm’
(c) ‘ypcglcm’
(d) ’pcgalm’
Answer:
(b) ‘ypcgalcm’

Question 6.
Which of the following types of files will need the pickle module for working on it:
(a) Binary files
(b) Text files
(c) Csv files
(d) All of these
Answer:
(a) Binary files

Fill in the blank:

Question 7.
______ command modifies the data of a table.
(a) Update
(b) Change
(c) Alter
(d) Modify
Answer:
(a) Update
Explanation: Update is a DML command that can be used to make changes to the data of the table.

CBSE Sample Papers for Class 12 Computer Science Set 2 with Solutions

Question 8.
Which of the following SQL commands displays the structure of a table?
(a) Alter
(b) Structure
(c) Describe
(d) Show data
Answer:
(c) Describe
Explanation: The describe is a DDL command that shows the entire structure of a table with its fields, their types and constraints.

Question 9.
Observe the following tuples and answer the questions that follow.
t1=(4, 7, 8, 9)
t2=(0, 4, 3)
(i)>>>t=tl+t2
>>>print(t)

(ii)
>>>t=t1*t2( )
>>>print(t)
What will bet the outputs of (i) and (ii)
(a) (i) (4,7,8,9,0,4,3) (ii) Error
(b) (i) (4,7,8,9) (ii) (0,28,24,0)
(c) (i) (4,11,11,12) (ii) Error
(d) None of these
Answer:
(a) (i) (4,7,8,9,0,4,3) (ii) Error

Fill in the blank:

Question 10.
There can be ______ alternate keys in a table
(a) Only 1
(b) 2
(c) 3
(d) Multiple
Answer:
(d) Multiple

Question 11.
Which of the following are proper syntax of read( ) function.
(a) str=<fileobject>.read( )
(b) str=<fileobject>.read(n)
(c) str=read(<fileobject>)
(d) Both (a) and (b)
Answer:
(d) Both (a) and (b)

Fill in the blank:

Question 12.
The Alter table command with ______ clause allows to change the data type of a field in a table.
(a) Modify
(b) Drop
(c) Add
(d) Edit
Answer:
(a) Modify

Fill in the blank:

Question 13.
______ is a protocol used for remote login.
(a) HTTP
(b) PPP
(c) IRCP
(d) Telnet
Answer:
(d) Telnet

Question 14.
The following expression evaluates to : 15//7 + 20**2 + 100**0.5
(a) 400.0
(b) 412.0
(c) 415.0
(d) 412.5
Answer:
(b) 412.0

CBSE Sample Papers for Class 12 Computer Science Set 2 with Solutions

Question 15.
The clause to get the unique values from a field of a table is:
(a) max
(b) unique
(c) distinct
(d) None of these
Answer:
(c) distinct

Question 16.
What is default value of host?
(a) Host
(b) localhost
(c) global host
(d) None of these
Answer:
(b) localhost

Q. 17 and 18 are Assertion and Reasoning based questions. Mark the correct choice as :
(a) Both A and R are true and R is the correct explanation for A
(b) Both A and R are true and R is not the correct explanation of A
(c) A is True but R is False
(d) A is false but R is Ture

Question 17.
Assertion (A): A function with 3 formal parameters must be called with 3 actual parameters.
Reason (R): Since all the formal parameters are used to produce the output from the function , the function expects the same number of parameters from the function call.
Answer:
(a) Both A and R are true and R is the correct explanation for A
Explanation: def sum(a,b,c):
return (a+b+c)
sum(5,10,15)
The sum( ) function requires all the 3 parameters to return the sum.

Question 18.
Assertion (A): The csv files are like text files and are comma separated value files.
Reason (R): The data stored in csv files are separated by comma by default. Although the delimiter can be changed.
Answer:
(a) Both A and R are true and R is the correct explanation for A
Explanation: The csv files are so called as the data stored in them are normally separated by the comma delimiter.

Section-B

Question 19.
Riya was asked to accept a list of even numbers, but she did not put the relevent condition while accepting the list of numbers. She wrote a user defined function oddtoeven (L) that accepts the list L as an argument and converts all the odd numbers into even by multiplying them by 2.
def oddtoeven (L)
for i in range (size(L)):
if (L[i]% 2! = 0)
L [i]= L [i] ** 2
print (L)
There are some errors in the code . Rewrite the correct code:
Answer:
def oddtoeven (L)
for i in range (len(L)):
if (L[i]% 2! =0):
L[i]=L[i]*2
print (L)

Question 20.
How are Email and chat applications different?
OR
How are LAN and MAN different?
Answer:
Email or Electronic mail is a system where the recipient may not be online . The sender writes an email address, subject and the message along with any attachment files and sends. A chat is a kind of application that needs both the users to be online in real time . In chatting both the ends are online in real time. Each writes a message and sends it to other. On the other side the receiver reads the message and accordingly answers.
OR
LAN: Local area network is a kind of network of computers within a local area like a room, campus, building etc. The computers may be connected by wires or wireless mediums. Distance is roughly 500m – lKm.
MAN: Metropolitan area network is a kind of network of computers spread across a city. The range is roughly the diameter of a city – 60Km . CATTV is an example of MAN.

Question 21.
(a) Find outputs of the 2 print statements.
L=[118,16,[20,30,50],120]
Ll=[12,16,17]
L.extend(Ll)
print(L[2][2])
print(L)

(b) t1=(9,6,l,12)
t2=(10,11,12)
print(t1+t2)
print(t1*2)
print(t2-t1)
Answer:
(a) [50]
[118,16, [20, 30,50], 120,12,16,17]
(b) (9,6,1,12,10,11,12)
(9, 6,1,12, 9, 6,1,12)
Error

CBSE Sample Papers for Class 12 Computer Science Set 2 with Solutions

Question 22.
Write a line about the terms Degree and cardinality of a table.
Answer:
Degree: Refers to the number of columns/attributes in a table.
Cardinality: Refers to the number of rows/records in a table.
A table Employee stores records of 10 employees in the following structure:
Eno Ename Dept Salary The degree of the table is : 4.
The cardinality of the table is 1.

Question 23.
(a) Write the full forms of :
(i) URL
(ii) VoIP

(b) Write the use of SMTP.
Answer:
(a) (i) URL: Uniform resource locator
(ii) VoIP: Voice over internet protocol

(b) SMTP: Simple Mail Transfer Protocol is a protocol used for sending and receiving emails.

Question 24.
What will be the output of the following code, when executed :
d={‘Name’:’Ram’,’Subjects’: [‘EngYPhysics’/CS’j/Marks’: [67,78,90]}
print(d[‘Subjects’])
print(d[‘Subjects’][2])
OR
tupnames=(/Tndia”,”Australis”/(//UK”/”NepaT’)/”Bangladesh”)
print(tupnames[5:])
print(tupnames[2][l])
Answer:
[‘Eng’, ‘Physics’, ‘CS’]
‘CS’
OR
( )
‘Nepal’

Question 25.
Differentiate Drop and Delete commands of SQL.
OR
Identify any two DML commands from the following:
ALTER, INSERT, UPDATE, DROP, CREATE
Answer:
Drop: A DDL command is used to remove a table or a database. The DROP command removes the entire table with its structure and records.
Delete : A DML command to delete records of a table.
OR
INSERT, UPDATE
The insert command adds a record to a table.
The update command is used to change record(s) of a table.

Section-C

Question 26.
(a) Consider the tables cars and Supplier given below . What will be the output of the statement given:
Table Student

Sname Class Hid
Raj 12ScA C1
Shekhar 11ComC C2
Ravi 12HumB C2
Jaisnav 12ScB C3

Table: House

Hcode Lname
C1 East
C2 West
C3 South
C4 North

Write the output of the following code:
Select S.Sname, H.Lname from Student S, House H where S.Hid = H.Hcode and SName like “R%”;

(b) Consider the following tables STORE and answer the questions:
Table: Store

Item No. Item Scode Qty Rate LastBuy
2005 Shapener Classic 23 60 8 31-JUN-09
2003 Balls 22 50 25 01-FEB-10
2002 Gel Pen Premium 21 150 12 24-FEB-10
2006 Gel Pen Classic 21 250 20 11-MAR-09
2001 Eraser Small 22 220 6 19-JAN-09
2004 Eraser Big 22 110 8 02-DEC-09
2009 Ball Pen 0.5 21 180 18 03-NOV-09

Write SQL commands for the following statements:
(i) To display details of all the items in the STORE table in ascending order of LastBuy.
(ii) To display Item No. and Item name of those items from STORE table, whose Rate is more than ?15.
(iii) To display the details of those items whose Supplier code (Scode) is 22 or Quantity in Store (Qty) is more than 110 from the table STORE.
(iv) To display minimum rate of items for each Supplier individually as per Scode from the table STORE.
Answer:
(a)

Sname LName
Raj East
Ravi West

(b) (i) SELECT * FROM STORE ORDER BY LastBuy:
(ii) SELECT ItemNo. Item FROM STORE WHERE Rate > 15:
(iii) SELECT * FROM STORE WHERE Scode = 22 OR Qty > 110:
(iv) SELECT MIN (Rate) FROM STORE GROUP BY Scode:

Question 27.
Write a program to accept a filename and a position . Using the inputs, call a function SearchFile(Fname, pos) to read the contents of the file from the position to the end. Now display all those words that start with “U” or “u”.
OR
Write a program to search a Employee record according to Id from the “emp.txt” file. The “emp.txt” file contains Id, Name and Salary fields. Assume that first field of the employee records (between Id and Name) is separated with a comma(,).
Answer:
def SearchFile(Fname, pos):
f=open(Fname,”r”)
f.seek(pos)
data=f.read( )
datawords=data.split(”)
for w in datawords :
if w[o] in “uU” :
print(w)
OR
Answer:
import os,
f1=”emp.txt”
if ox.path.isfile(fl):
fob=open(f1)
eid=int(input(“Enter employee id:”))
flag=false
for emp in fob:
strlen=len(emp)
i=0
strid=” ”
while True:
if(emp[i]=”,”):
break
if(emp[i]>=/0/ and emp[i]<=’9’):
strid=strid+emp[i]
i=i+1
nid=int(strid)
if(eid==nid):
print(”Employee found:”, emp)
flag=True
break fob.close( )
if(flag=False):
print(“Record does not found”)
else:
print(“File does not exist”)

Question 28.
(a) Consider the following tables GARMENT and FABRIC.Write SQL commands for the statements
(i) to (iv).
Table Garment

GCODE DESCRIPTION PRICE FCODE READYDATE
10023 PENCIL SKIRT 1150 F03 19-DEC-08
10001 FORMAL SHIRT 1250 F01 12-JAN-08
10012 INFORMAL SHIRT 1550 F02 06-JUN-08
10024 BABY TOP 750 F03 07-APR-07
10090 TULIP SKIRT 850 F02 31-MAR-07
10019 EVENING GOWN 850 F03 06-JUN-08
10009 INFORMAL PANT 1500 F02 20-OCT-08
10007 FORMAL PANT 1350 F01 09-MAR-08
10020 FROCK 850 F04 09-SEP-07
10089 SLACKS 750 F03 20-OCT-08

Table: Fabric

FCODE TYPE
F04 POLYSTER
F02 COTTON
F03 SILK
F01 TERELENE

(i) To display GCODE and DESCRIPTION of each GARMENT in descending order of GCODE.
(ii) To display the details of all the GARMENT, which have READYDATE in between 08-DEC-07 and 16-JUNE-08 (inclusive of both the dates).
(iii) To display the average PRICE of all the GARMENT, which are made upofFABRICWITH FCODE as F03.
(iv) To display FABRIC wise highest and lowest price of GARMENT from GARMENT table. (Display FCODE of each GARMENT alongwith highest and lowest price.)

(b) Write a command to remove all the records of a table “Shipping”.
Answer:
(a) (i) SELECT GCODE, DESCRIPTION FROM GARMENT ORDER BY GCOD DESC:
(ii) SELECT*FROM GARMENT WHERE READYDATE BETWEEN ’08-DEC-07’AND ’16-JUN-08′:
(iii) SELECT AVE(PRICE) FROM GARMENT WHERE FCODE = ’F03′:
(iv) SELECT FCODE, MAX(PRICE), MIN(PRICE) FROM GARMENT GROUP BY FCODE:

(b) Delete from Shipping;

CBSE Sample Papers for Class 12 Computer Science Set 2 with Solutions

Question 29.
Write a user defined function findname (name) where name is an argument in Python to delete phone number from a dictionary phonebook on the basis of the name, where name is the key.
Answer:
def findname (name):
if phonebook, has_key ( ):
del phonebook [name] else:
print (“Name not found”)
print (“Phonebook Information”)
print (“Name”, \t, “Phone no”)
for i in phonebook. keys ( ):
print (i, \t, phonebook [i])

Question 30.
Julie has created a dictionary containing names and marks as key value pairs of 6 students. Write a program, with separate user defined functions to perform the following operations

  • Push the keys (name of the student) of the dictionary into a stack, where the corresponding value (marks) is greater than 75.
  • Pop and display the content of the stack.

For example: If the sample content of the dictionary is as follows R=(“OM”:76,”JAI”:45, “BOB”:89, “ALI”:65, ”ANU”:90, “TOM”:82)
The output from the program should be TOM ANU BOB OM
OR
Write Push (contents) and Pop (contents) methods in Python to add numbers and remove numbers considering them to act as Push and Pop operations of stack.
Answer:
R=(“OM”:76, “JAI”:45, “BOB”:89, “ALI” : 65,
“ANU”:90, “TOM”:82)
def PUSH(S,N):
S, append (N)
def POP (S):
if S! =[ ]:
return S.pop( )
else:
return None
ST=[ ]
for k inR:
if R[k]>=75:
PUSH (ST, k)
while True:
if ST! = [ ]:
print(POP(ST), end-” “)
else:
break
Answer:
def Push (contents):
if (len(stack)>= limit):
print (“Stack Overflow!”)
else:
stack, append (contents)
print (“Stack after Push”, stack)
def Pop ( ):
if (len (stack) <= 0):
print (“Stack Underflow!”)
return 0
else:
return stack, Pop( )

Section-D

Question 31.
Red Pandas Infosystems has its 4 blocks of buildings . The number of computers and distances between them is given below :
CBSE Sample Papers for Class 12 Computer Science Set 2 Img 1

Building Number of Computers
HR 15
ADMIN 100
SYSTEM 25
PERS 30
HR – Admin 10m
HR- System 50m
HR-Pers 750m
Admin- System 300m
Admin- Pers 20m
System-Pers 250m

Answer following questions with respect to the above:
(a) Suggest a suitable cable layout for the network.
(b) Suggest the best place to house the server of the network.
(c) Which topology should be used to connect computers in each building?
(d) What kind of network will be formed here (LAN/MAN/WAN)?
(e) Write one advantage of the topology suggested by you.
Answer:
(a) The cable layout is given below:
CBSE Sample Papers for Class 12 Computer Science Set 2 Img 2
Since the ADMIN building has the maximum number of computers, connecting to it will ensure best connectivity.
(b) ADMIN building, as it has the maximum number of computers.
(c) Star topology, as it is the topology offering best facilities.
(d) LAN-Local area network.
(e) Fault detection is easy.

CBSE Sample Papers for Class 12 Computer Science Set 2 with Solutions

Question 32.
(a) Find the output of the following Python program:
def makenew (mystr):
newstr -” ”
count = 0
for i in mystr:
if count % 2! = 0:
newstr = newstr + str (count)
else:
if islower (i):
newstr = newstr + upper (i)
else:
newstr = newstr + i
count + = 1
newstr = newstr + mystr [:1]
print (“The new string is : “, newstr)
makenew (“sTUdeNT”)

(b) Consider the table Student whose fields are:

SCODE Name Age Strede Points Grade
101 Amit 16 1 6 NULL
102 Arjun 13 3 4 NULL
103 Zaheer 14 2 1 NULL
104 Gagan 15 5 2 NULL
105 Kumar 13 6 6 NULL

Write the Python code to update grade to A’ for all these students who are getting more than 8 as points.
The table structure is as follows:
Scode: integer
Name: Varchar
Age: integer
Strede: integer
Points: integer
Grade: varchar
Note the following to establish the connection between python and MySQL:
Host: localhost
Username: Admin
Password: Admin@123
The table exists in MySQL database as : Student
Answer:
(a) Output
The new string is : STUDENTS
(b) import mysql.connector as mydb
con = mydb, connect (host = “localhost”
user = “Admin”.
passwd = “Admin@123”
database = “system”
cursor = con.cursor ( )
Sql = “UPDATE Student SET Grade = ‘A’
WHERE Points >’8′
try:
cursor, execute (sql)
con.commit ( )
except:
con.rollback ( )
con.close ( )
OR
(a) Predict the output
str = “Python Program”
def sTringoutput(str)
print(str[3:5]
print(str(-10)
print(str[5:]
print(str[-28])

(b) Consider the table MobileStock with following fields
M_Id, M_Name, M_Qty, M_Supplier
Write the Python code to fetch all records with fields M_Id, M_Name and M_Supplier from database Mobile.
Consider:
host: localhost
UserName: root
Password: system
Database: Mobile
Answer:
(a) ho
‘o’
n Program
IndexError

(b) import mysql, connector as mydb
mycon = mydb. connect (host = ‘localhost”, user = “root”, passwd = “system”, database = “Mobile”)
cursor = mycon.cursor ( )
Sql =”SELECT M_Id, M_Name, M_Supplier From MobileStock”
try:
cursor.execute (sql)
display = cursor.fetchall ( )
for i in display
print (i)
except:
mycon.rollback( )
mycon.close ( )

Question 33.
(a) What is the advantage of using Binary files.
(b) Write a user defined function in Python that displays the number of lines starting with ‘H’ in the file Para.txt.
e.g. If the file content is Hello…. How are you?
Hi…I am fine.
What are you doing now?
Hmm…nothing special.
Then the line count should be 3.
OR
(a) Differentiate between the following:
(i) Filel=open (“employee, txt’, ‘a’)
(ii) Filel=open(’employee. txt’, V)
Answer:
(a) Binary files are faster and easy to process. In contrast to text files where translation of the file contents are required, binary files are stored in binary format and hence no translations are required.
(b) def count( ):
f = open (“Para.txt”, “r”)
lines = 0
l=f.readlines( )
for i in 1:
if i[0] = =’H’:
lines+=1
print(“No. of lines is”, lines)
OR
(a) (i) This statement opens a ’employee.txt’ file for appending only.
(ii) This statement opens a ’employee.txt’ file for reading only.

(b) Write a functioon countEU( ) in Python, which should read each character of a text file. IMP.TXT, should count and display the occurrence of alphabets E and U (including small cases e and u too).
e.g. if the file content is an follows:
Pinaky has gone to his friends’s house.
His friends’s name is Ravya. Her house is 12 km from Pinaky’s house.
The countEU( ) function should display the output as
E : 8
U : 3

(b) def countEU( ):
f=open(“IMP.TXT”)
e=0
u=0
while True:
l=f,readline( )
if not1:
break
for i in 1:
if (i=’E’ or i=’e’):
e=e+1
elif (i=’U” or i=’u”):
u=u+1
pint(“E : “,e)
print(“U:”,u)
f,close( )

Section-E

Question 34.
Consider the following table Student
Table Student

AdmNo Name Name Class Marks
2715 Ram Ram 12 90
2816 Shyam Shyam 11 95
2404 Ajay Ajay 10 92
2917 Tarun Tarun 12 94

(i) Can we make class as the Primary key of the table.
(ii) What is the cardinality of the table.
(iii) Write statements to:
(a) Display the average marks.
(b) Display the different classes.
(iv) Write statements to :
(a) Change the data type of Marks column so that it can take fractional values upto 2 decimals .
(b) Increase width of Name column to Varchar(50).
Answer:
(i) No, as the column carries duplicate values and Primary must be unique.
(ii) 4, Cardinality is the number of rows in a table.

(iii) (a) Select Avg(Marks) from Student;;
(b) Select Distinct Class from Student;

(iv) (a) Alter table Student Modify Marks float(8,2);
(b) Alter table Student Modify Name Varchar(50);

CBSE Sample Papers for Class 12 Computer Science Set 2 with Solutions

Question 35.
The code given below opens a binary file and writes records of customer’s roomid, Name and days of stay . Some of the codes are missing .Write codes to fill up the blanks :
import ………………# Blank1
hotellst=[ ]
cname=” ”
days=0.0
roomid=0
ans=’y’
f=open(“hotel.dat”,” wb”)
print(“Welcome to my Hotel “)
while ans=’y’:
roomid=input(“Enter Roomid:”)
cname=input(“Enter Customer name:”)
days=float(input(“Enter days of stay :”))
hotellst=[…………, ……………, ……….] # Blank2 To create the record to be written …………………..# Blank3 To write the data to the binary file.
ans=input(“Continue(y/n)”)
f.close( )
(i) Write the missing code for Blank 1.
(ii) Write the missing code for Blank2.
(iii) Write the missing code for Blank3.
Answer:
(i) pickle
(ii) roomid, cname, days
(iii) pickle.dump(hotellst,f)