Class 12 CBSE COMPUTER SCIENCE Sample Question Paper Answer sheet
- Categories Sample Papers
Class XII
COMPUTER SCIENCE – NEW (083)
SAMPLE QUESTION PAPER (2021 – 22)
Max Marks: 70
Time: 3 hrs
General Instructions:
- This question paper contains two parts A and B. Each part is compulsory.
- Both Part A and Part B have choices.
- Part-A has 2 sections:
- Section – I is short answer questions, to be answered in one word or one line.
- Section – II has two case studies questions. Each case study has 4 case-based subparts. An examinee is to attempt any 4 out of the 5 subparts.
- Part – B is Descriptive Paper.
- Part- B has three sections
- Section-I is short answer questions of 2 marks each in which two questions have internal options.
- Section-II is long answer questions of 3 marks each in which two questions have internal options.
- Section-III is very long answer questions of 5 marks each in which one question has question has internal option.
Part-A
Section-I
Select the most appropriate option out of the options given for each question. Attempt any 15 questions from question no 1 to 21.
1 . Identify the Python data types?
a. “And” b. {‘name’: 26} c. [26, 24] d. (‘My’, ‘data’)
Ans. a. String, b. Dictionary c. List d. Tuple
2 . A twisted pair cable is a pair of_________ wires that are twisted together to improve electromagnetic capability
Ans. Insulated
3 . Rita wants to display a column “TYPE” in table ACCOUNT. Write SQL statement to show which command she should use to select the column and give it an alias “EVENT TYPE”?
Ans. SELECT TYPE as “EVENT TYPE” from ACCOUNT;
4 . Which is the default sorting order used in ORDER BY clause?
Ans. ASC
5 . Name the Python Library modules which need to be imported to invoke the following functions :
i. writerow( )
ii. dump ( )
Ans.
i . csv
ii . Pickle
6 . _____ is the amount of data transmitted via a given communications Channel in a given unit of time.
Ans. bandwidth
7 . What is the value of c after executing these statements?
c = 7//4
a. 3 b. 1 c. 1.75 d. The statement is incorrect
Ans. b is correct.
8 . Which command is used to view a table structure?
Ans. DESC or DESCRIBE
9 . What is an Alternate Key?
Ans. A candidate key that is not the primary key is called an Alternate Key.
For example in Student table if there are two candidate keys – StudId and Stud_Name and StudId is the primary Key then Stud_Name is the alternate key.
10 . Give 2 mutable and 2 immutable types in Python?
Ans. Mutable: list, dictionary
Immutable: string, int, tuples
11 . ___________ is a process of storing data into files and allows it to perform various tasks such as read, write, append, search and modify in files.
Ans. File Handling
12 . Which constraint makes sure that all values in a column satisfy a certain criteria?
Ans. CHECK
13 . Write an SQL query to print details of workers excluding FIRST_NAME, “Ronit” and “Nitin” from WORKER table.
Ans. Select * from WORKER where FIRST_NAME not in (‘Ronit’ ‘Nitin’);
14 . Which one of these is output of these Python commands?
L = [1,3,5,3,1]
print (L.index(3),L.count(3)))
a) 12
b) 1 2
c) 22
d) 2 2
Ans. b
15 . What is the output of these Python commands?
A = (1,2,(3,4),5)
print (len(A), A[2])
Ans. 4 (3, 4)
16 . __________command will test the connectivity between two host
Ans. Ping
17 . What is the output of the following commands?
score =20
while score > 1:
score=score//2-1
print(score,end=’ ‘)
Ans. 9 3 0
18 . Ronit downloaded a harmless looking game from internet. 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?
a. Trojan Horse
b. Spam Mail
c. Computer Bacteria
d. Hardware breakdown
Ans. a. Trojan Horse
19 . To read 4th line from text file, which of the following statement is true?
a. dt = f.readlines();print(dt[3])
b. dt=f.read(4) ;print(dt[3])
c. dt=f.readline(4);print(dt[3])
d. All of these
Ans. a. dt = f.readlines();print(dt[3])
20 . Which protocol is used for transferring files from one computer to another?
Ans. FTP
21 . Stack is _____ data structure.
a. FIFO
b. LIFO
c. POP
d. None of above.
Ans. b. LIFO
Section-II
Both the Case study based questions(22 & 23) are compulsory. Attempt any 4 sub parts from each question. Each sub question carries 1 mark.
22 .Observe the following table carefully and Answer the following questions.
Table: Store
Item code | Item | Qty | Rate |
---|---|---|---|
10 | Gel pen classic | 1150 | 25 |
11 | Sharpener | 1500 | 10 |
12 | Ball pen 0.5 | 1600 | 12 |
13 | Eraser | 1600 | 5 |
15 | Ball pen 0.25 | 800 | 20 |
a. In the above table, can we have Qty as primary key?
b. What is the cardinality and degree of the above table?
c. Write a query to display the structure of table store from Mall Database.
d. Give the output of following query.
Select distinct Item from Store;
e. If we want to display maximum rate in store from Mall Database. Which command will be use the following:
a. Select min(rent) from resort;
b. Select minimum(rent) from mall;
c. Select min(rent) from mall;
d. Select minimum(rent) from resort;
Ans.
a. We cannot use Qty as primary key because there is a duplication of values and primary key value cannot be duplicate.
b. Degree =4
Cardinality = 5
c. Describe store;
d.
Item |
---|
Gel pen classic |
Sharpener |
Ball pen 0.5 |
Eraser |
e. a. Select min(rent) from resort;
23 . Nyra has a branch1.csv file which has the name, class and section of students. She receives a branch2.csv which has similar details of students in second branch. She is asked to add the details of branch2,csv into branch1.csv. As a programmer, help her to successfully execute the given task.
__a__ csv
file = open('branch1.csv', __b__ , newline="");
writer = csv. __c__ (file)
with open('branch2.csv','r') as csvfile:
data = csv.reader(csvfile)
for row in data:
writer.writerow(__d__)
file. __e__ ()
a. Name the command she should use to include csv library.
b. In which mode she should open the file to add data into the file
c. Name the csv method which returns the object responsible for converting user’s data into delimited
strings
d. Fill in the blank with the information that needs to be written to csvfile.
e. Fill in the blank to close the file.
Ans.
import csv
file = open('branch1.cs','a', newline="");
writer = csv.writer(file)
with open('branch2.csv','r') as csvfile:
data = csv.reader(csvfile)
for row in data:
writer.writerow(row)
file.close()
Part-B
Section-I
24 . Rewrite the following code in python after removing all syntax error(s). Underline each correction done in the code.
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[i]
Ans.
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[i]
25 . Give full forms of the following?
1. VOIP, 2. ARPANET, 3. SMTP, 4. RFID
Ans.
1. VOIP- Voice over Internet Protocol
2. ARPANET – Advanced Research Projects Agency Network)
3. SMTP- Simple Mail Transfer Protocol
4. RFID-Radio Frequencies Identification
26 . Define String in Python?
Ans. String in Python is formed using a sequence of characters. Value once assigned to a string cannot be modified because they are immutable objects. String literals in Python can be declared using double quotes or single quotes.
Example:
print(“Simply Coding”)
print(‘ Simply Coding ‘)
27 . Find and write the output of the following python code:
a=['Cat','Dog','cat','Dog']
def manip(f1):
animal={}
for index in f1:
if index in animal:
animal [index] += 1
else:
animal[index] =1
return(animal)
ret = manip(a)
print (ret)
print (len(ret))
Ans. {‘Cat’: 1, ‘Dog’: 2, ‘cat’: 1}
3
28 . What is the difference between packet switching and circuit switching techniques?
Ans.Circuit Switching In this, first complete physical connection between two computers is established. After that data is transmitted from the source computer to the destination computer.
e.g. In telephone call, circuit switching is used.
Packet Switching In this, data is divided into packets. And they are sent without any reservation of resources. Each packet has destination address and transmission is done by intermediate routers. It makes it less reliable but there is less wastage of resources.
29 . Which option is NOT the possible outcome(s) executed from the following code?
import random
def main():
p = "MY PROGRAM"
i = 0
while p[i] != "R":
l = random.randint(0,3) + 5
print (p[l],end ="_")
i += 1
main()
Ans. (i) will not be printed
30 . Define the following terms :
i. Relation
ii. Tuple
iii. Attribute
iv. Domain
Ans.
i. Relation: A relation is a two-dimensional table. It contains number of rows (tuples) and columns (attributes).
ii. Tuple: This is the horizontal part of the relation. One row represents one record of the relation. The rows of a relation are also called tuples.
iii. Attribute: The columns of a table are also called attributes. The column is the vertical part of the relation.
iv. Domain: A domain is a pool of values from which the actual values present in a given column are taken.
31 . What is join in SQL? What is difference between Inner-join and Full join?
Ans. Join clause is used to combine rows from two or more tables, based on a related column between them. It is used to merge two tables or retrieve data from there.
Inner join: Inner Join in MySQL is the most common type of join. It is used to return all the rows from multiple tables where the join condition is satisfied.
Full Join: Full join returns all the records when there is a match in any of the tables. Therefore, it returns all the rows from the left-hand side table and all the rows from the right-hand side table.
32 . Evaluate the following postfix expression using stack and show the contents of stack after execution of each expression
120, 45, 20, + , 25, 15, – , + , *
Ans.Scanned Elements Operation Stack Status 120 Push 120 45 Push 120,45 20 Push 120,45,20 + Pop twice
45+20=65
Push120,45,20, 25 25 Push
120,6515 Push 120, 65, 25,15 – Pop Twice
25-15=10
Push
120,65,10+ Pop Twice
65+10=75
Push
120,75* Pop twice
120*75=9000
Push
9000
33 . Differentiate between CHAR and VARCHAR datatypes in SQL?
Ans.
char | var char |
---|---|
CHAR stands for “Character” | VARCHAR stands for “Variable Character” |
fixed length | variable length |
Uses Static memory Allocation | Uses Dynamic memory allocation |
use when data values in a column are of same length. | use when data values in a column are of Variable length. |
Section-II
34 . Write a python function to sum the sequence given below. Take the input n from the user.
Ans.
def fact(x):
j=1
res=1
while j<=x:
res=res*j
j=j+1
return res
n=int(input(" the number : "))
i=1
sum=1
while i<=n:
f=fact(i)
sum=sum+1/f
i+=1
print(sum)
35 . Write a function program to do a binary search in an array.
Ans.
def bsearch (AR,ITEM):
beg=0
last=len(AR)-1
while(beg<=last):
mid=(beg+last)//2
if(ITEM==AR[mid]):
return mid
elif(ITEM>AR[mid]):
beg=mid+1
else:
last=mid-1
else:
return False
AR= [2,5,6,7,8,10]
ITEM= int(input("Enter item to be searched"))
index=bsearch(AR,ITEM)
if index:
print("Found")
else :
print("Not Found")
36 .Write a program to count the number of upper-case alphabets present in a text file “PYTHON.TXT”
Ans.
string=input("Enter string:")
count=0
for i in string:
if(i.isupper()):
count=count+1
print("The number of uppercase characters is:")
print(count)
Or
Write a function which takes in an input file and output file. It copies all lines which starts with vowels from the input file to output file.
Ans.
def Lower(infile,outfile):
output=open("w")
file=open(infile)
for line in file:
if line[0] in "aeiouAEIOU":
output.write(line)
output.close()
file.close()
37 . Consider the following tables RESORT and OWNEDBY and answer questions.
Table : RESORTRCODE PLACE RENT TYPE STARTDATE R001 GOA 15000 5 STAR 12-JAN-02 R002 HIMACHAL 9000 4 STAR 20-DEC-07 R003 KERALA 12500 5 STAR 10-MAR-06 R004 HIMACHAL 10500 2 STAR 25-NOV-05 R005 GUJARAT 8000 7 STAR 01-JAN-03 R006 GOA 18000 4 STAR 30-MAR-08 R007 ORISSA 7500 2 STAR 12-APR-99 R008 KERALA 11000 5 STAR 03-MAR-03 R009 HIMACHAL 9000 2 STAR 15-OCT-08 R010 GOA 13000 5 STAR 12-APR-06
Table : OWNEDBYPlace Owner Goa Raj Resorts Kerala KTDC Himachal HTDC Gujarat MAHINDRA RESORTS Orissa OTDC
Give output for the following SQL queries:
1. Select min(rent) from resort where place = ‘KERALA’;
2. Select type, start date from resort where type ‘2 STAR’ orderby startdate,
3. Select place, owner from ownedby where place like “%a”;
Ans.
1 .
Min(rent) |
---|
11000 |
2 .
Type | Start Date |
---|---|
2 STAR | 1999-04-12 |
2 STAR | 2005-11-25 |
2 STAR | 2008-10-15 |
3 .
Place | Owner |
---|---|
Goa | Raj Resorts |
Kerala | KTDC |
Orissa | OTDC |
Section III
38 . Write answer of the following
Simply Coding is a computer institute aimed to uplift the standard of computer knowledge in the society. It is planning to setup its training centres in multiple towns and villages pan India with its head offices in the nearest cities. They have created a model of their network with A city, C Town and 3 Villages as given.
As a network consultant, you have to suggest the best network related solution for their issues/problems raised in (i) to (iv) keeping in mind the distance between various locations and given parameters.
Shortest distance between various locations:
Village 1, 2, 3 to C Town | 1 to 2 km |
Distance between the villages | 3 – 4 km |
City Head Office to C Town | 50 km |
Number of computers installed at various locations are as follows:
C Town | 50 |
Village 1 | 10 |
Village 2 | 15 |
Village 3 | 8 |
City Head Office | 25 |
1. Suggest the most appropriate location of the SERVER in the HUB (out of the 4 locations), to get the best and effective connectivity. Justify your answer.
2. Suggest the best wired medium for network.
3. Draw the cable layout (location to location) to efficiently connect various locations within the HUB
4. Which hardware device will you suggest to connect all the computers within each location of HUB?
5. Which server/protocol will be most helpful to conduct live interaction of Experts from Head office and people at HUB locations?
Ans.
1. C TOWN as it has the maximum number of computers and it is closest to all other locations.
2. Optical Fiber is recommended as there is going to be live interactions with head office
3. The cable layout:
4. Switch or Hub
5. Video conferencing or VoIP.
39 . Consider the following tables EMPLOYEE and SALGRADE and answer this question:
Table : EmployeeEcode Name Design SGrade DOJ DOB 101 Abdul Ahmad Executive S03 23-Mar-2003 13-Jan-1980 102 Ravi Chander Head-IT S02 12-feb-2010 22-Jul-1987 103 John Ken Receptionist S03 24-Jun-2009 24-Feb-1983 105 Nazar Ameen GM S02 11-Aug-2006 03-Mar-1984 108 Priyam Sen CEO S01 29-Dec-2004 19-Jan-1982
Table : SalGradeSgrade Salary HRA S01 56000 18000 S02 32000 12000 S03 24000 8000
Write SQL commands for the following statements
i. To display the details of all employees in descending order of DOJ.
ii. To display NAME and DESIGN of those employees, whose salary grade is either S02 or S03.
iii. To display the content of all EMPLOYEE table, whose DOJ is in between ’09-Feb-2006′ and ’08- Aug-2009′.
iv. To display the details of all employee who has joined before 1985 from employee table.
v. To add a new row with the following data:
109, ‘Harish Roy’, ‘Head-IT’, ‘S02, ’09-
Sep-2007′, ’21-Apr-1983’
Ans.
i. Select * from employee order by doj desc;
ii. Select name, design from employee where sgrade = “s02” or sgrade = “so3;
iii. Select * from employee where doj between ’09-feb-2006′ and ’08- aug -2009’
iv. select * from employee where joindate<’01-jan-1985′;
v. Insert into employee values(109, “Harish Roy”, “Head-IT”, “S02”, ’2007-09-09′, ’1983-04-21′);
40 . Write a function writefile() to write numbers into a binary file and another function readfile() to read and print the same.
Ans.
import pickle
def writefile():
file= open("data.dat",&'wb')
while True:
x= int(input("Enter number"))
pickle.dump(x,file)
ans=input("Want to enter more data Y/N")
if ans.upper()=='N':
break
file.close()
def readfile():
print ("Reading from file")
file=open("data.dat", 'rb')
while True:
try:
y=pickle.load(file)
print (y)
except EOFError:
break
file.close()
writefile()
readfile()
OR
A binary file “phonebook.dat” has structure [Name, PhoneNo].
i. Write a user defined function append_record() to input data for a record and add to phonebook.dat .
ii. Write a function search_record() in Python which takes in a name and prints only those records which matches that name.
Ans.
def append_record():
outfile = open('phonebook.dat', 'ab')
while True:
name = input("Enter name: ")
no = input("Enter Phone No: ")
phoneno = [name,no]
pickle.dump(phoneno, outfile)
ans=input("Want to enter more data Y/N")
if ans.upper()=='N':
break
#close the file
outfile.close()
def search_record():
infile = open('phonebook.dat','rb')
name = input("Enter name to search:")
while True:
try:
phoneno = pickle.load(infile)
if(phoneno[0] == name) :
print (phoneno[0], " ",phoneno[1])
except EOFError:
break
#close the file
infile.close()
append_record()
search_record()