CBSE Class 12 Computer Science Sample Question Paper (Solved)
CBSE Class 12 Computer Science Sample Question Paper (Solved)
General Instructions:
● This question paper contains 37 questions.
● All questions are compulsory. However, internal choices have been provided in some
questions. Attempt only one of the choices in such questions
● The paper is divided into 5 Sections- A, B, C, D and E.
● Section A consists of 21 questions (1 to 21). Each question carries 1 Mark.
● Section B consists of 7 questions (22 to 28). Each question carries 2 Marks.
● Section C consists of 3 questions (29 to 31). Each question carries 3 Marks.
● Section D consists of 4 questions (32 to 35). Each question carries 4 Marks.
● Section E consists of 2 questions (36 to 37). Each question carries 5 Marks.
● All programming questions are to be answered using Python Language only.
● In case of MCQ, text of the correct answer should also be written.
Ans. False
Page: 1/18
4. What is the output of the expression?
country='International' (1)
print(country.split("n"))
(A) ('I', 'ter', 'atio', 'al')
(B) ['I', 'ter', 'atio', 'al']
(C) ['I', 'n', 'ter', 'n', 'atio', 'n', 'al']
(D) Error
Ans. ce lo
6. What will be the output of the following code?
tuple1 = (1, 2, 3)
tuple2 = tuple1
tuple1 += (4,) (1)
print(tuple1 == tuple2)
(A) True
(B) False
(C) tuple1
(D) Error
Ans. (B) Removes the first occurrence of value x from the list
Page: 2/18
9. If a table which has one Primary key and two alternate keys. How many
Candidate keys will this table have?
(A) 1
(1)
(B) 2
(C) 3
(D) 4
Ans. (C) 3
Ans. False
Which SQL command can change the degree of an existing relation? (1)
13.
Ans. Alter (or Alter Table)
Page: 3/18
14. What will be the output of the query?
SELECT * FROM products WHERE product_name LIKE
'App%';
(A) Details of all products whose names start with 'App' (1)
(B) Details of all products whose names end with 'App'
(C) Names of all products whose names start with 'App'
(D) Names of all products whose names end with 'App'
Ans. (A) Details of all products whose names start with 'App'
15. In which datatype the value stored is padded with spaces to fit the specified
length.
(A) DATE
(1)
(B) VARCHAR
(C) FLOAT
(D) CHAR
Ans. (D) CHAR
16. Which aggregate function can be used to find the cardinality of a table?
(A) sum()
(B) count() (1)
(C) avg()
(D) max()
Ans. (B) count()
18. Which network device is used to connect two networks that use different
protocols?
(1)
(A) Modem
(B) Gateway
(C) Switch
(D) Repeater
Ans. (B) Gateway
19. Which switching technique breaks data into smaller packets for
transmission, allowing multiple packets to share the same network (1)
resources.
Ans. (B) Packet Switching
Page: 4/18
Q20 and Q21 are Assertion(A) and Reason(R) 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 for A
(C) A is True but R is False
(D) A is False but R is True
21. Assertion (A): A SELECT command in SQL can have both WHERE and
(1)
HAVING clauses.
Reasoning (R): WHERE and HAVING clauses are used to check
conditions, therefore, these can be used interchangeably.
Ans. (C) A is True but R is False
Q No Section-B ( 7 x 2=14 Marks) Marks
Page: 5/18
(II)
A) Write a statement to insert all the elements of L2 at the end of L1.
OR
B) Write a statement to reverse the elements of list L2.
Ans.
(I)
A) L1.count(4)
OR
B) L1.sort()
(II)
A) L1.extend(L2)
OR
B) L2.reverse()
25. Identify the correct output(s) of the following code. Also write the minimum
and the maximum possible values of the variable b.
import random
a="Wisdom"
b=random.randint(1,6)
(2)
for i in range(0,b,2):
print(a[i],end='#')
26. The code provided below is intended to swap the first and last elements of
a given tuple. However, there are syntax and logical errors in the code.
Rewrite it after removing all errors. Underline all the corrections made.
def swap_first_last(tup)
if len(tup) < 2:
return tup (2)
new_tup = (tup[-1],) + tup[1:-1] + (tup[0])
return new_tup
Page: 6/18
Ans.
def swap_first_last(tup):
if len(tup) < 2:
return tup
new_tup = (tup[-1],) + tup[1:-1] + (tup[0],)
return new_tup
27. (I)
A) What constraint should be applied on a table column so that
duplicate values are not allowed in that column, but NULL is
allowed.
OR
B) What constraint should be applied on a table column so that (2)
NULL is not allowed in that column, but duplicate values are
allowed.
(II)
A) Write an SQL command to remove the Primary Key constraint
from a table, named MOBILE. M_ID is the primary key of the
table.
OR
B) Write an SQL command to make the column M_ID the
Primary Key of an already existing table, named MOBILE.
Ans.
(I)
A) UNIQUE
OR
B) NOT NULL
(II)
A) ALTER TABLE MOBILE DROP PRIMARY KEY;
OR
B) ALTER TABLE MOBILE ADD PRIMARY KEY (M_ID);
Page: 7/18
28. A) List one advantage and one disadvantage of star topology.
OR (2)
B) Expand the term SMTP. What is the use of SMTP?
Ans.
A) Advantage: Network extension is easy.
OR
B) Write a Python function that finds and displays all the words longer than 5
characters from a text file "Words.txt".
Ans.
(B)
def display_long_words():
f = open("Words.txt", 'r')
data=file.read()
words=data.split()
for word in words:
if len(word)>5:
print(word,end=' ')
f.close()
Page: 8/18
30. A) You have a stack named BooksStack that contains records of books.
Each book record is represented as a list containing book_title,
author_name, and publication_year.
Write the following user-defined functions in Python to perform the
specified operations on the stack BooksStack:
(I) push_book(BooksStack, new_book): This function takes the stack
BooksStack and a new book record new_book as arguments and
pushes the new book record onto the stack.
(II) pop_book(BooksStack): This function pops the topmost book record
from the stack and returns it. If the stack is already empty, the function
should display "Underflow".
(III) peep(BooksStack): This function displays the topmost element of the (3)
stack without deleting it. If the stack is empty, the function should
display 'None'.
Ans.
(A)
def push_book(BooksStack,new_book):
BooksStack.append(new_book)
def pop_book(BooksStack):
if len(BooksStack) != 0:
return(BooksStack.pop())
else:
print("Underflow")
def peep(BooksStack):
if len(BooksStack) != 0:
print(BooksStack[-1])
else:
print("None")
OR
For example:
If the integers input into the list `VALUES` are: [10, 5, 8, 3, 12]
Page: 9/18
Ans.
(B)
EvenNumbers = []
def push_even(N):
for num in N:
if num % 2 == 0:
EvenNumbers.append(num)
def pop_even():
if len(EvenNumbers)!=0:
return(EvenNumbers.pop())
else:
print("Empty")
def Disp_even():
if len(EvenNumbers)!=0:
print(EvenNumbers[-1])
else:
print("None")
(A) 15@
7@
9
OR
Ans.
Page: 10/18
(B) 1 #2 #3#
1 #2 #3 #
1 #
OR
B) Write the output
(I) Select c_name, sum(quantity) as total_quantity
from orders group by c_name;
(II) Select * from orders where product like
'%phone%';
(III) Select o_id, c_name, product, quantity, price
from orders where price between 1500 and 12000;
(IV) Select max(price) from orders;
Page: 11/18
Ans.
(B)
(I)
C_Name | Total_Quantity
|
Jitendra |
1
Mustafa | 2
Dhwani |1
(II)
(IV)
MAX(Price)
12000
(IV)
33. A csv file "Happiness.csv" contains the data of a survey. Each record of the
file contains the following data:
● Name of a country
● Population of the country
● Sample Size (Number of persons who participated in the survey in
that country)
● Happy (Number of persons who accepted that they were Happy)
(4)
For example, a sample record of the file may be:
[‘Signiland’, 5673000, 5000, 3426]
Write the following Python functions to perform the specified operations on
this file:
(I) Read all the data from the file in the form of a list and display all
those records for which the population is more than 5000000.
(II) Count the number of records in the file.
Page: 12/18
Ans.
(I)
import csv
def show():
f=open("happiness.csv",'r')
data=csv.reader(f)
for i in data:
if int(i[1])>5000000:
print(i)
f.close()
(II)
import csv
def Count_records():
f=open("happiness.csv",'r')
data=csv.reader(f)
for i in data:
count+=1
print(count)
f.close()
34. Saman has been entrusted with the management of Law University
Database. He needs to access some information from FACULTY and
COURSES tables for a survey analysis. Help him extract the following
information by writing the desired SQL queries as mentioned below.
Table: FACULTY
F_ID FName LName Hire_Date Salary
102 Amit Mishra 12-10-1998 12000
103 Nitin Vyas 24-12-1994 8000 (4)
104 Rakshit Soni 18-5-2001 14000
105 Rashmi Malhotra 11-9-2004 11000
106 Sulekha Srivastava 5-6-2006 10000
Table: COURSES
C_ID F_ID CName Fees
C21 102 Grid Computing 40000
C22 106 System Design 16000
C23 104 Computer Security 8000
C24 106 Human Biology 15000
C25 102 Computer Network 20000
C26 105 Visual Basic 6000
(I) To display complete details (from both the tables) of those Faculties
whose salary is less than 12000.
(II) To display the details of courses whose fees is in the range of 20000
to 50000 (both values included).
(III) To increase the fees of all courses by 500 which have "Computer"
in their Course names.
(IV) (A) To display names (FName and LName) of faculty taking System
Page: 13/18
Design.
OR
(B) To display the Cartesian Product of these two tables.
Ans.
(I) Select * from FACULTY, COURSES where Salary<12000 and
facuty.f_id = courses.f_id;
(II) Select * from courses where fees between 20000 and 50000;
OR
Field Type
itemNo int(11)
itemName varchar(15)
price float
qty int(11)
(4)
Write the following Python function to perform the specified operation:
AddAndDisplay(): To input details of an item and store it in the table
STATIONERY. The function should then retrieve and display all records
from the STATIONERY table where the Price is greater than 120.
Ans.
import mysql.connector as mycon
Page: 14/18
def AddAndDisplay():
con=mycon.connect(host="localhost",user="root",passwd="Pencil",database="I
TEMDB")
cur= con.cursor()
no=int(input("Enter Item Number: "))
nm=input("Enter Item Name: ")
pr=float(input("Enter price: "))
qty=int(input("Enter qty: "))
query="INSERT INTO stationery VALUES ({},'{}',{},{})".format(no,nm,pr,qty)
cur.execute(query)
con.commit()
Ans.
(I)
import pickle
def addrecord():
f = open('candidates.', 'ab')
candidate_id = int(input("Enter Candidate ID: "))
candidate_name = input("Enter Candidate Name: ")
designation = input("Enter Designation: ")
experience = float(input("Enter Experience (in years): "))
L=[candidate_id, candidate_name, designation, experience]
pickle.dump(candidate, file)
f.close()
Page: 15/18
(II)
import pickle
def updaterecord():
f1 = open('candidates.dat', 'rb')
f2 = open('temp.dat', 'wb')
while True:
try:
data = pickle.load(f1)
if data[3] > 10:
data[2] = 'Senior Manager’
pickle.dump(data,f2)
except:
f1.close()
f2.close()
os.remove(f1)
os.rename('temp.dat','candidates.dat')
(III)
import pickle
def readrecord():
f = open('candidates.dat', 'rb')
while True:
try:
data = pickle.load(f)
if data[2] != 'Senior Manager':
print(data)
except:
f.close()
Page: 16/18
37. Event Horizon Enterprises is an event planning organization. It is planning
to set up its India campus in Mumbai with its head office in Delhi. The
Mumbai campus will have four blocks/buildings - ADMIN, FOOD, MEDIA,
DECORATORS. You, as a network expert, need to suggest the best
network-related solutions for them to resolve the issues/problems
mentioned in points (I) to (V), keeping in mind the distances between
various blocks/buildings and other given parameters.
ADMIN 30
FOOD 18
MEDIA 25
DECORATORS 20
DELHI HEAD
OFFICE 18
Page: 17/18
(I) Suggest the most appropriate location of the server inside the
MUMBAI campus. Justify your choice.
(II) Which hardware device will you suggest to connect all the
computers within each building?
(III) Draw the cable layout to efficiently connect various buildings
within the MUMBAI campus. Which cable would you suggest for
the most efficient data transfer over the network?
(IV) Is there a requirement of a repeater in the given cable layout?
Why/ Why not?
(V) A) What would be your recommendation for enabling live visual
communication between the Admin Office at the Mumbai campus
and the DELHI Head Office from the following options:
a) Video Conferencing
b) Email
c) Telephony
d) Instant Messaging
OR
B) What type of network (PAN, LAN, MAN, or WAN) will be set up
among the computers connected in the MUMBAI campus?
Ans.
(I) ADMIN Block as it has maximum number of computers.
(IV) There is no requirement of the Repeat as the optical fibre cable used
for the network can carry the data to much longer distances than within
the campus.
Page: 18/18