Class 12 Computer Science Sample Paper Set 3
Class 12 Computer Science Sample Paper Set 3
Join School of Educators' exclusive WhatsApp, Telegram, and Signal groups for FREE access
to a vast range of educational resources designed to help you achieve 100/100 in exams!
Separate groups for teachers and students are available, packed with valuable content to
boost your performance.
Additionally, benefit from expert tips, practical advice, and study hacks designed to enhance
performance in both CBSE exams and competitive entrance tests.
Don’t miss out—join today and take the first step toward academic excellence!
COMPUTER SCIENCE
All questions are compulsory. However, internal choices have been provided in some questions. Attempt only one
of the choices in such questions.
Section A
1. State true or false: [1]
The expression int(x) implies that the variable x is converted to integer.
2. Which of the following queries contains an error? [1]
a) Select empid from emp where empid = b) Select * from emp where empid = 10003;
10006;
c) Select empid from emp; d) Select empid where empid = 1009 and
lastname = 'GUPTA';
3. fetchall() method fetches all rows in a result set and returns a: [1]
a) void b) None
c) bool d) int
5. What will be the output of the following code snippet? [1]
my_dict = {}
my_dict[(1,2,4)] = 8
my_dict[(4,2,1)] =10
my_dict[(1,2)]=12
sum = 0
for k in my_dict:
sum += my_dict[k]
print (sum)
print(my_dict)
6. Which of the following is the fastest media of data transfer? [1]
a) dump(myfile.obj1) b) write(obj1.myfile)
c) dump(obj1.myfile) d) load(myfile.obj1)
8. What does the special file called data dictionary contains? [1]
a) The data types of all data in all files. b) The names of all fields in all files.
a) IS b) BETWEEN
c) IN d) LIKE
10. What is the use of pickle module? [1]
11. State true or false: [1]
The clear() removes all the elements of a dictionary but does not delete the empty dictionary.
12. What is the conventional name of pointer associated with the stack? [1]
a) FIRST b) TOP
c) REAR d) FRONT
13. What is the following command doing? [1]
ALTER TABLE Persons
ADD CONSTRAINT chk_Person CHECK (P_ID>0 AND City = 'Shimla');
14. A ________ is a network spread across a small area connecting various related devices such as laptop, mobile [1]
phone, wifi, printers etc.
a) WAN b) MAN
c) PAN d) LAN
15. Which of the following will delete key:value pair for key="tiger" in dictionary? [1]
c) delete(di.["tiger"]) d) di["tiger"].delete()
16. Which of the following sublanguages of SQL is used to query information from the database and to insert tuples [1]
into, delete tuples from, and modify tuples in the database?
a) 2 b) 0
c) 3 d) 1
18. In which type of cloud an organization rents cloud services from cloud providers on-demand basis? [1]
a) Protected b) Hybrid
c) Public d) Private
19. Assertion (A): In python break is used to bring the program control out of the loop. [1]
Reason (R): The break is commonly used in the cases where we need to break the loop for a given condition.
a) Both A and R are true and R is the correct b) Both A and R are true but R is not the
explanation of A. correct explanation of A.
a) Both A and R are true and R is the correct b) Both A and R are true but R is not the
explanation of A. correct explanation of A.
a) Both A and R are true and R is the correct b) Both A and R are true but R is not the
explanation of A. correct explanation of A.
Fields Datatype
PID varchar(5)
PName char(30)
Price float
Rank varchar(2)
26. Write an algorithm to find out whether the given number is divisible by 3 or not. [2]
OR
Predict the output of the following code fragment.
b = 20
a = 90/b
print("value of a is :", a)
27. When a file is opened for output, what happens when [2]
i. the mentioned file does not exist
ii. the mentioned file does exist?
OR
Write method in Python to read lines from a text file DIARY.TXT, and display those lines, which are starting with an
alphabet 'P'.
28. Predict the output of the following code: [2]
def execute(x, y = 200, z = [23,]):
temp = x + y + z[0]
print(temp, x, y)
a, b = 50, 20
c = [10,]
execute(b)
execute(y = a, x = b)
execute (x = b, z = [a,], y = a)
Section C
29. Answer the questions (i) to (iv) based on the following: [3]
class Book
{
char Bno[20];
protected:
float Price;
public:
void GetB();
void ShowB();
};
class Member
{
char Mno[20];
protected:
char Name[20];
public:
void GetM();
void ShowM();
};
class Library : public Member, private Book
{
char Lname[20];
public:
void GetL();
void ShowL();
};
void main()
{
Library L;
}
i. Which type of Inheritance out of the following is illustrated in the above example?
- Single Level Inheritance, Multilevel Inheritance, Multiple Inheritance
ii. Write the names of all the data members, which are directly accessible by the member function GetL() of
class Library.
iii. Write the names of all the member functions, which are directly accessible by the member function
ShowL() of class Library.
iv. Write the names of all the members, which are directly accessible by the object L of class Library declared
in the main() function.
OR
How are following two statements different?
import math
from math import *
30. Consider the following SQL table MEMBER in a SQL Database CLUB: [3]
Table: MEMBER
Assume that the required library for establishing the connection between Python and MYSQL is already
imported in the given Python code. Also assume that DB is the name of the database connection for table
MEMBER stored in the database CLUB.
Predict the output of the following code:
MYCUR = DB.cursor()
MYCUR.execute("USE CLUB")
MYCUR.execute("SELECT * EROM MEMBER WHERE ACTIVITY= 'GYM' ")
R=MYCUR.fetchone()
for i in range (2):
R=MYCUR, fetchone()
print (R [0], R [1], sep = " # ")
OR
What are Tuples in a SQL Table? Write a suitable example with a SQL Table to illustrate your answer.
31. Write a function called removeFirst that accepts a list as a parameter. It should remove the value at index 0 from [3]
the list.
Note that it should not return anything (returns None). Note that this function must actually modify the list
passed in, and not just create a second list when the first item is removed. You may assume the list you are given
will have at least one element.
OR
What is the difference between a local variable and a global variable? Also, give a suitable Python code to illustrate
both.
Section D
32. Write a program to implement a stack for these book details (bookno, bookname). That is, now each item node [4]
of the stack contains two types of information -a bookno and its name. Just implement push and display
operations.
OR
A linear stack called status contains the following information:
Phone number of Employee
Name of Employee
Write the following methods to perform given operations on the stack status:
i. Push_element () To Push an object containing Phone number of Employee and Name of Employee into the stack.
ii. Pop_element () To Pop an object from the stack and to release the memory.
33. Write a point of difference between append (a) and write (w) modes in a text file. [4]
Write a program in Python that defines and calls the following user defined functions:
i. Add_Teacher() : It accepts the values from the user and inserts the record of a teacher to a csv file
'Teacher.csv'. Each record consists of a list with field elements as T_id, Tname and desig to store teacher ID,
teacher name and designation respectively.
ii. Search_Teacher() : To display the records of all the PGT (designation) teachers.
34. Write SQL commands for the queries (i) to (iv) and output for (v) to (viii) based on a table COMPANY and [4]
CUSTOMER.
COMPANY
CUSTOMER
i. To display those company name which are having price less than 30000.
ii. To display the name of the companies in reverse alphabetical order.
iii. To increase the price by 1000 for those customer whose name starts with S?
iv. To add one more column t_price with decimal(10, 2) to the table customer
v. SELECT COUNT(*), CITY FROM COMPANY GROUP BY CITY
vi. SELECT MIN(PRICE), MAX(PRICE) FROM CUSTOMER WHERE QTY>10
vii. SELECT AVG(QTY) FROM CUSTOMER WHERE NAME LIKE "%r%"
viii. SELECT PRODUCTNAME, CITY, PRICE FROM COMPANY, CUSTOMER WHERE COMPANY. CID =
CUSTOMER.CID AND PRODUCTNAME= "MOBILE"
OR
i. What possible output(s) are expected to be displayed on screen at the time of execution of the following code?
import random
S=["Pen","Pencil","Eraser","Bag","Book"]
for i in range (1,2):
f=random.randint(i,3)
s=random.randint(i+1,4)
print(S[f],S[s],sep=":")
Options :
I. Pencil:Book
II. Pencil:Book
Eraser:Bag
III. Pen:Book
Bag:Book
IV. Bag:Eraser
ii. The table Bookshop in MySQL contains the following attributes:
B_code - Integer
B_name - String
Qty - Integer
Price - Integer
Note the following to establish connectivity between Python and MySQL on a 'localhost' :
Username is 'shop'
Password is 'Book'
The table exists in a MySQL database named Bstore.
The code given below updates the records from the table Bookshop in MySQL.
Statement 1 - to form the cursor object.
Statement 2 - to execute the query that updates the Qty to 20 of the records whose B_code is 105 in the table.
Statement 3 - to make the changes permanent in the database.
mydb=mysql.connect(host="localhost",
user="shop",passwd="Book",database="Bstore")
mycursor=__________ # Statement 1
qry= "update Bookshop set Qty=20 where
B_code=105"
___________________ # Statement 2
___________________ # Statement 3
105 SUV 40
104 CAR 20
Note:
PERKM is Freight Charges per kilometre
TTYPE is Transport Vehicle Type
TABLE: TRIP
Note:
• NO is Driver Number
• KM is Kilometre travelled
• NOP is number of travellers travelled in a vehicle
• TDATE is Trip Date
i. To display NO, NAME, TDATE from the table TRIP in descending order of NO.
ii. To display the NAME of the drivers from the table TRIP, who are travelling by transport vehicle with code
101 or 103.
iii. To display the NO and NAME of those drivers from the table TRIP who travelled between 2015-02-10 and
2015-04-01.
iv. To display all the details from table TRIP in which the distance travelled is more than 100 KM in ascending
order of NOP
v. SELECT COUNT (*), TCODE From TRIP
GROUP BY TCODE HAVING COUNT (*) > 1;
vi. SELECT DISTINCT TCODE from TRIP;
vii. SELECT A.TCODE, NAME, TTYPE
FROM TRIP A, TRANSPORT B
WHERE A.TCODE = B. TCODE AND KM < 90;
viii. SELECT NAME, KM * PERKM
FROM TRIP A, TRANSPORT B
WHERE A. TCODE = B. TCODE AND A. TCODE = '105';
OR
Explain the Cartesian product of two relations.