Students must start practicing the questions from CBSE Sample Papers for Class 12 Computer Science with Solutions Set 4 are designed as per the revised syllabus.

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

Time Allowed: 3 hours
Maximum Marks: 70

General Instructions:

  • This question paper contains five sections, Section A to E.
  • All questions are compulsory.
  • Section A have 18 questions carrying 01 mark each.
  • Section B has 07 Very Short Answer type questions carrying 02 marks each.
  • Section C has 05 Short Answer type questions carrying 03 marks each.
  • Section D has 03 Long Answer type questions carrying 05 marks each.
  • Section E has 02 questions carrying 04 marks each. One internal choice is given in Q35 against part c only.
  • All programming questions are to be answered using Python Language only.

Section – A

Question 1.
State True or False.
2ndNAme is an invalid identifier in Python [1]
Answer:
True

Explanation:
Identifier’s name cannot be start with number.

Answering Tip:
Memorise the rules and conventions for naming identifiers thoroughly.

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

Question 2.
Which of the following is a valid arithmetic operator in Python? [1]
(A) //
(B) ?
(C) <
(D) and
Answer:
(A) //

Explanation:
// is used for floor division

Question 3.
Which of the following commands is not a data manipulation language? [1]
(A) SELECT
(B) INSERT
(C) UPDATE
(D) ALTER
Answer:
(D) ALTER

Explanation:
Data Manipulation language (DML) provides various commands used to access and manipulate data in existing database.

Question 4.
Which type of error occurs when rules of programming language are misused? [1]
(A) Syntax error
(B) Semantic error
(C) Run time error
(D) Logical error
Answer:
(A) Syntax error

Explanation:
When a formal set of rules defined for writing a program in a particular language is not followed then error raised is known as syntax error. Syntax errors occur when syntax rules of any programming language are violated.

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

Question 5.
Consider a declaration T = [1, ‘Python’, ‘3.14’]. [1]
Which of the following represents the data type of L?
(A) list
(B) tuple
(C) dictionary
(D) string
Answer:
(A) list

Explanation:
Elements enclosed in parentheses[] represents by list.

Question 6.
What will be the output of the following code? [1]
L = [‘a’/b’/’c’,’d’]
print (” “.join(L))
(A) Error
(B) abcd
(C) [‘a’/b’/c’/d’]
(D) None of these
Answer:
(B) abcd

Explanation:
Join() method is a string method and returns a string in which the elements of sequence have been joined by str separator.
Syntax stringName.join (iterable).

Commonly Made Error:
Many times students get confused in writing the correct syntax when declaring various data types.

Answering Tip:
Remember the return type of each function before finding the output.

Question 7.
Fill in the blank [1]
The valid sequence type of L is _____________ where : A i;
L = [‘Mon’, ’23’, ‘hello’, ‘60.5’]
(A) dictionary
(B) string
(C) tuple
(D) list
Answer:
(D) list

Explanation:
a list is a heterogeneous sequence of data.

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

Question 8.
Which of the following is not a comparison query? [1]
(A) IN
(B) BETWEEN
(C) LIKE
(D) AND
Answer:
(D) AND

Explanation:
AND is a logical operator used with SELECT, INSERT, UPDATE and DELETE statements to combine two conditions together

Question 9.
Stdout, stdin snd stderr are _____________ [1]
(A) Structure
(B) File pointer
(C) File descriptors
(D) Streams
Answer:
(B) File pointer

Explanation:
These three text streams are predefined. These streams are implicitly opened and unoriented at program startup.
(i) stdin: Associated with the standard input stream, used for reading conventional input.
(ii) stdout: Associated with the standard output stream, used for writing conventional output.
(iii) stderr: Associated with the standard error stream, used for writing diagnostic output.

Question 10.
Fill in the blank
_____________ function returns the sum of values of a column of numeric type [1]
(A) TOTAL ()
(B) ADD ()
(C) SUM ()
(D) All of these
Answer:
(C) SUM ()

Explanation:
SUM () function is used to find out the sum of a field in various records, e.g., SELECT SUM (total_working_hours) FROM employee

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

Question 11.
Which function helps us to randomize the items of a list? [1]
(A) shuffle()
(B) mean()
(C) choice()
(d) max()
Answer:
(A) shuffle()

Explanation:
shuffle () method randomly reorder the elements in a list. It can shuffle only list elements.
Syntax: random.shuffle (list)

Question 12.
Fill in the blank
_____________ is used to get the row-id of the last modified row? [1]
(A) cursor.getrwid
(B) cursor.endrwid
(C) cursor.batrowid
(D) cursor.exitrowid
Answer:
(C) cursor.batrowid

Explanation:
This read-only property returns the value generated for an AUTO_INCREMENT column by the previous INSERT or UPDATE statement

Question 13.
Fill in the blank
Bluetooth is an example of ______________ [1]
(A) personal area network
(B) local area network
(C) virtual private network
(D) wide area network
Answer:
(A) personal area network

Explanation:
Bluetooth is a personal area network (PAN) standard that is lower power than 802.11. It was originally specified to serve applications such as data transfer from personal computers to peripheral devices such as cell phones or personal digital assistants.

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

Question 14.
What is the output of “hello”+1+2+3 ? [1]
(A) he110123
(B) hello
(C) Error
(D) hello6
Answer:
(C) Error

Explanation:
It will give Type Error because string and integer objects cannot be concatenated

Question 15.
Which method of cursor class is used to insert or update multiple rows using a single query? [1]
(A) cursor.executeall(query, rows)
(B) cursor.execute(query, rows)
(C) cursor.executemultiple (query, rows)
(D) cursor.executemany(query, rows)
Answer:
(D) cursor.executemany(query, rows)

Explanation:
executemany() is like simple iteration that provides a repetitive execution of INSERT and UPDATE across multiple rows.

Question 16.
The clause places condition with aggregate functions. [1]
(A) HAVING
(B) WHERE
(C) IN
(D) BETWEEN
Answer:
(A) HAVING

Explanation:
The HAVING clause places condition on groups and aggregate functions. E.g. SELECT stu_name, per FROM student GROUP BY class HAVING class = ’12A’.
The above example will show the names and percentage of students from table STUDENT belonging to class 12A.

Assertion and Reason:
In the following questions, A statement of Assertion (A) is followed by a statement of Reason (R). Mark the correct choice as.
(A) Both A and R are true and R is the correct explanation of A.
(B) Both A and R are true and R is not correct explanation of A.
(C) A is true but R is false.
(D) A is false but R is true.

Question 17.
Assertion (A): Higher precedence operator is evaluated before the lower precedence operator. [1]
Reason (R): For operators with equal precedence, the expression is evaluated from right to left.
Answer:
(C) A is true but R is false.

Explanation:
Evaluation of the expression is based on precedence of operators. When an expression contains different kinds of operators, precedence determines which operator should be applied first. For operators with equal precedence, the expression is evaluated from left to right.

Question 18.
Assertion (A): CSV stands for comma separated value. [1]
Reason (R): CSV files are a common file format for transferring and storing data.
Answer:
(B) Both A and R are true and R is not correct explanation of A.

Explanation:
CSV stands for comma separated value. These files are common file format for transferring and storing data.

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

Section – B

Question 19.
Find the errors from the following code: [1]
c=dict()
n=input(Enter total number )
i=1
while i<=n:
a=input(“enter place”)
b=input(“enter number”)
c[a]=b
i = i+1
print (“place”,”\t”,”number”)
for i in c:
print (i, “\t” , c [a [i] ] )
Answer:

c=dict ()
n=int(input("Enter total number"))
i = 1
while i<=n:
a=input("enter place")
b=input("enter number")
c[a]=b
i = i + 1
print ( "place\t","number")
for i in c:
print (i,"\t",c [i])

Question 20.
Write the expanded names for the following abbreviated terms used in Networking and Communications: [1]
(i) SMTP
(ii) VoIP
(iii) GSM
(iv) WLL
OR
How is packet switching different from circuit switching?
Answer:
(i) Simple Mail Transfer Protocol
(ii) Voice over Internet Protocol (Voice over IP)
(iii) Global System for Mobile Communication
(iv) Wireless Local Loop

OR

Packet switching:

  • Uses store and forward concept to send messages
  • No physical path is actually establishes
  • Message is divided into smaller parts, known as packets and then sent forward
  • Tight upper limit on block size
  • Each data unit knows only the final receiver’s address

Circuit switching

  • Physical connection is established between sender and receiver
  • Each data unit knows the entire path from sender to receiver
  • It does not follow store and forward concept

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

Question 21.
(a) Find and write the output of the following Python code: [1]
def fun(s):
k=len(s)
m=” ”
for i in range(0,k):
if (s [ i] .isupper()) :
m=m+s[i].lower()
elif s[i] .isalpha():
m=m+s[i].upper()
else:
m=m+’bb
print(m)
fun(‘school2@com1)
Answer:
SCHOOLbbbbCOM

(b) Find and write the output of the following Python code: [1]
def Change(P ,Q=30):
P=P+Q
Q=P-Q
print( P, “#” ,Q) return (P)
R = 150
S = 100
R=Change(R,S)
print(R, “#” ,S)
S=Change(S)
Answer:
250 # 150
250 # 100
130 # 100

Question 22.
What is relation? Define the relational data model. [2]
Answer:
A relation is a table having atomic values, unique and unordered rows and columns. The relational model represent data and relationship among data by a collection of tables known as relation, each of which has a number of columns with unique names.

Question 23.
(a) Rahul got an assignment in which there is a question about website. But he does not know about it. Help him to get the information of website.
(b) What is the method of viewing the source code of the current page in web browser? [2]
Answer:
(a) Website is a collection of web pages belonging to a particular person or organisation.
(b) To see the source code, right click on the web page and then click on the view source option.

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

Question 24.
Identify the output of the following Python statements:
L1, L2 = [10, 15, 20, 25], []
for i in range (len(L1)) :
L2. insert(i,L1.pop())
print (L1, L2,sep=”&”) [2]
OR
What will be the output of the following code?
tup1 = (1, 2, [1, 2], 3)
tup1[2][1] = 3.14
print(tup1)
Answer:
[ ] & [25,20,15,10]
OR
(1,2,[1,3.14],3)

Question 25.
Define Equi join.
OR
Categorize following commands into DDL and DML commands.
INSERT INTO, DROP TABLE, ALTER TABLE, UPDATE ….SET
Answer:
Equi join is a simple SQL join condition that uses equal sign as a comparison operator.
Syntax
SELECT column1, column2, column3 FROM Table1, Table2 WHERE Table1. column1 = Table2. column1 ,
OR
DDL: DROP TABLE, ALTER TABLE
DML: INSERT INTO, UPDATE….SET

Section – C

Question 26.
(a) Consider the table given below
CBSE Sample Papers for Class 12 Computer Science Set 4 with Solutions 1

Table: Posting

P_ID Department Place
1 History Agra
2 Mathematics Raipur
3 Computer Science Delhi

Write SQL query to show all information about the teacher of History department.

(b) Find output for SQL queries (i) to (iv), Which are based on the tables GIVEN BELOW.
CBSE Sample Papers for Class 12 Computer Science Set 4 with Solutions 2
Answer:
(a) SELECT * FROM Teacher WHERE Department = “History”;

(b)
(i)

TID TNAME
103 DEEPTI
106 MANIPRABHA

(ii)
DISTINCT TID
101
103
102
104
105

(iii)

TID COUNT (*) MIN (FEES)
101 2 12000

(iv)

COUNT (*) SUM (FEES)
4 65000

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

Question 27.
Write a method in Python to read lines from a text file DIARY.TXT, and display those lines, which are starting with the letter ‘P’. [3]
OR
Write a function in Python to count the number of lowercase and uppercase characters in a text file “Book.txt”.
Answer:

def countP ( ) :
fname = "DIARY.txt"
with open (fname, ' r' ) as f:
1=f.readlines()
for line in 1:
if 1. strip == 1 p 1 :
print (line)
f.close()

OR

def lowerupper () :
fname = "Book.txt"
1count=ucount=0
with open(fname, 'r') as f:
for line in f:
for word in line:
for char in word:
if char.islower():
1count=1count + 1
if char.isupper():
ucount = ucount + 1
print ("No. of lower case letters =",1count)
print ("No. of upper case letters =",ucount)

Question 28.
(a) Consider the following relation Mobile Master & mobile Stock
CBSE Sample Papers for Class 12 Computer Science Set 4 with Solutions 3

Write the output of SQL command for question from (i) to (iv) given below:
(i) SELECT M_Id, SUM(M_Qty) FROM Mobile Stock GROUP BY M_Id;
(ii) SELECT MAX(MMfDate), MIN(M_Mf_ Date) FROM MobileMaster;
(iii) SELECT M+Company, M_Price FROM Mobile Master WHERE M_Price>5000;
(iv) SELECT AVG(M_price) FROM MobileMaster;
(b) Which command is used to modify the records of the table? [3]
Answer:
(a)
(i)

M_Id SUM(M_Qty)
MB004 450
MB003 400
MB001 300
MB006 200

(ii)

MAX(M Mf Date) MIN(M_Mf Date)
2017-11-20 2010-08-21

(iii)

M_Company M_Price
Sony 7500
Oppo 8500

(b) UPDATE

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

Question 29.
Define a function overlapping () that takes two lists and returns true if they have at least one member in common, False otherwise. [3]
Answer:

def overlapping (listl, list2):
l1=len(listl)
l2=len(list2)
for i in range (11):
for j in range (12):
if listl [i]==list2 [j] :
return True
return False

Question 30.
Write
(i) Add new(Book) to Add a new Book
(ii) Remove(Book) to Remove a Book
from a List of Books, considering them to act as PUSH and POP operations of the data structure stack. [3]
OR
Arr is a stack implemented by a list of numbers.
(i) Write a function in Python PUSH(Arr). From this list push all numbers divisible by 5 into a stack implemented using a list. Display the stack if it has at least one element, otherwise display appropriate error message.
(ii) Write a function in Python POP(Arr), where The function returns the value deleted from the stack.
Answer:

books=[ ]
def Addnew (books,name):
books.append (name)
print("bookl:",name,"inserted" )
def Remove(books):
if books== [] :
print("stack is empty")
else:
print("book:", books.pop (), "deleted ")

OR

(i) def PUSH (Arr, value) :
s=[]
for x in range (0, len(Arr)):
if Arr [x] %5 == 0:
s.append (Arr[x])
if len(s)==0:
print ("EMPTY Stack")
else:
print(s)
(ii) def popstack (st) : #if stack is empty
if len (st) == NULL :
print ("Underflow")
else:
1 = len (st)
val=st (1-1)
print (val)
st.pop (1-1)
return val

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

Section – D

Question 31.
ABC Pvt. Ltd. is setting up the network in the Bengaluru. There are four departments named as Market, Finance, Legal and Sales.
Distance between various buildings is as follows:

Market to Finance 80 mt
Market to Legal 180 mt
Market to Sales 100 mt
Legal to Sales 150 mt
Legal to Finance 100 mt
Finance to Sales 50 mt

Number of computers in the building:

Market 20
Legal 10
Finance 08
Sales 42

(i) Suggest a cable layout of connections between the Departments and specify the topology.
(ii) Suggest the most suitable building to place the server by giving suitable reason.
(iii) Suggest the placement of (i) modem (ii) hub/switch in the network.
(iv) The organization is planning to link its sale counter situated in various part of the same city. Which type of network out of LAN, WAN, MAN will be formed?
Justify.
(v) What is the use of modem in networking? [5]
Answer:
(i)
CBSE Sample Papers for Class 12 Computer Science Set 4 with Solutions 4
Star topology should be used.
(ii) Sales is the most suitable building to place the server because it has maximum no. of computers.
(iii) Each building should have hub/switch and modem in case Internal connection is required.
(iv) MAN (Metropolitan Area Network) as this network can be carried out in a city network.
(v) A modem is used to convert digital signals produced by computers to analog signals that can be carried over the telephone networks.

Question 32.
(a) What will be the output of the following Python code and why ? age = raw_input(“Enter your age”) ageafterlO = age + 10
(b) Write Python code to insert following records into the OrderDetails table.
Database → sales
Userid Admin Password → salAd345
table name → OrderDetails [2 + 3]
CBSE Sample Papers for Class 12 Computer Science Set 4 with Solutions 5

OR

(a) What is the output of the following Python statements?
x = 2
while x < 9:
print(x, end=” 11)
x = x + 1

(b) Consider the following structure of table Hospital.
Hospital
HospitaMd(p)
Hospitalname
Bed_Count
Write Python code to create the above table structure
Answer:
(a) It will generate an error because raw_input() takes input as a string and the code is trying to add numeric value to a string.

(b) import MySQLdb
-db = MySQLdb.connect ( 'localhost' , 'Admin', 'salAd345', 'sales')
(cursor=db.cursor(prepared=True)
insert_query= "'"'INSERT INTO
OrderDetails (ORDNUMB, PARTNUMB,
NUMBORD, QUOTPRIC) VALUES('%S',
' % s' , ' %s', '%f')"""
rec_ins=[('12489', 'AX12', 'll', 14.95) ,
('12491', 'BT04' , '1', '402.99),
('12492', 'BZ66', '1', 311.95),
('12498', 'CX11', '2', 57.95)]
try:
cursor.executemany(insert_query, rec_ins)
print(cursor.rowcount, "Records inserted successfully'')
db.commit()
except:
db.rollback()
cursor.close()
db. close ()

OR

(a) 2345678

(b) import MySQLdb
db = MySQL.connect('localhost' , 'FacAdmin', ’FacAdmin@123','XYZHOS' )
cursor=db.cursor()
cursor.execute("DROP TABLE IF EXISTS Hospital")
sql = """Create Table Hospital
('Hospital_ id', INT NOTNULL, 'Hospital_name'
CHAR(50) NOTNULL
'Bed_Count' 'INT’ PRIMARY KEY
('Hospital_id')
)"""
cursor.execute(sql) c
ursor.close()
db. close ()

Commonly Made Error:
Students forget to commit the transactions and or to close the database.

Answering Tip:
Remember to commit the transactions. follow all the steps to create link to a database, table cursor and to commit all the queries.

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

Question 33.
What is the use of tell() function?
Write a program to print following type of statistics for the given file:
16824 Lines in the file
483 Empty lines
53.7 Average characters per line
65.9 average characters per non-empty line [5]

OR

What is the use of os.path module?
Write a function in Python
(i) that checks if the file exists. It gives an error message if the file exists. If not, it will create the file. R
(ii) to split a path completely into directory names.
Answer:
tell() method returns an integer giving the current position of file pointer in the file. The integer returned specifies the number of bytes from the beginning of the file till the current position of file object.

PROGRAM
fpl = open ("Read.txt",'r')
lines = fpl.readlines () 
totallines = len (lines) 
blanklines = 0 
for i in len(lines): 
if lines [i] == " ": 
blanklines + = 1 
fp.seek(0) 
str = fpl.read () 
characters = len(str) 
fpl.close()
print (totallines, "Lines in the file") 
print (blanklines, "Empty Lines") 
print (float (characters/totallines) ,"average character per line") 
print (float (characters/(totallines- 
blanklines)),"average characters per non- empty Line")

OR

It provides functions for manipulating paths

PROGRAM
(i) import os
if os .path, isfile ('test.txt'):
print ("You are trying to create a file that already exist!")
else:
f = open ("text.txt",'w')
(ii) def split_path (path) :
parent_path_name = os.path.split (path)
if name == " ":
return (parent_path)
else:
return (split_path (parent_ path)+name,)

Section – E

Question 34.
Consider a database with two tables STUDENTS and SPORTS as given below:
CBSE Sample Papers for Class 12 Computer Science Set 4 with Solutions 6

(i) Write the statement to delete a column phone from the table students.
(ii) name the columns in both the tables that can be made primary keys.
(iii) Write statements to
(a) display name and game of those students whose address is available in students’ table.
(b) display Name of the students who are studying in class 12 and their corresponding Coach names
(Only For part (iii) Only) [1 +1+2=4]
OR
(iii) WRITE COMMAND TO
(a) count the number of students who play volleyball
(b) Display name of all students of class 12 along with their coach names
Answer:
(i) ALTER TABLE STUDENTS DROP PHONE;
(ii) For the table Students primary key will be RNO and for the table sports primary key wll be admno.
(iii) (a) SELECT NAME, GAME FROM STUDENTS, SPORTS WHERE STUDENTS. ADMNO=SPORTS. ADMNO AND ADDRESS IS NOT NULL;
(b) SELECT NAME, COACHNAME FROM STUDENTS, SPORTS WHERE CLASS LIKE “\2%” AND STUDENTS.ADMNO = SPORTS. ADMNO; OR
(iii) (a) SELECT COUNT(*) FROM STUDENTS, SPORTS WHERE GAME=”VOLLEYBALL” AND STUDENTS.ADMNO = SPORTS. ADMNO;
(b) SELECT NAME, COACHNAME FROM Students, sports where dass like “12%” AND students, admno=sports.admno

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

Question 35.
Read the following passage and answer the question that follow.
Arun, during Practical Examination of Computer Science, has been assigned an incomplete search() function to search in a pickled file student.dat. The File student.dat is created by his-Teacher and the following information is known about the file.

  • File contains details of students in [roll_no,name,marks] format.
  • File contains details of 10 students (i.e. from roll_no 1 to 10) and separate list of each student is written in the binary file using dump().

Arun has been assigned the task to complete the code and print details of roll number 1.

def search ( ) :
f = open ("student.dat", _______________) # Statement-1
while True:
rec = pickle. _______________ # Statement-2
if ( _______________ ) : # Statement-3
print (rec)
except: pass
_______________ # Statement-4

(i) Write suitable code to be used a blank space in line marked as Statement-1.
(ii) Write the function (with argument), to be used blank apace in the line marked as statement-2?
(iii) Write the suitable for blank space in line marked as Statement-3 [1 + 1 + 2 = 4]
Answer:
(i) try
(ii) load(f).
(iii) rec[0] = = 1. f.dose()