Students must start practicing the questions from CBSE Sample Papers for Class 12 Computer Science with Solutions Set 5 are designed as per the revised syllabus.
CBSE Sample Papers for Class 12 Computer Science Set 5 with Solutions
Time: 3 hrs Max.
Marks: 70
Instructions
1. Please check this question paper contains 35 questions.
2. The paper is divided into 5 Sections A, B, C, D and E.
3. Section A, consists of 18 questions (1 to 18). Each question carries 1 Mark.
4. Section B, consists of 7 questions (19 to 25). Each question carries 2 Marks.
5. Section C, consists of 5 questions (26 to 30). Each question carries 3 Marks.
6. Section D, consists of 2 questions (31 to 32). Each question carries 4 Marks.
7. Section E, consists of 3 questions (33 to 35). Each question carries 5 Marks.
8. All programming questions are to be answered using Python Language only.
Section – A
Question 1.
State True or False [1]
“Given a dictionary Studict. The statement Studict.items() displays the keys of the item only.”
Answer:
False
Question 2.
Which module is to be imported to use the floor() function? [1]
(a) statistics
(b) matplotlib
(c) random
(d) math
Answer:
(d) math
Question 3.
Given L=[2,3,4,5,6]. The output of print(L[-2]) is [1]
(a) 6
(b) Error
(c) 5
(d) 3
Answer:
(c) 5
Question 4.
This function is used to calculate total occurrence of given elements of list. [1]
(a) len()
(b) sum()
(c) count()
(d) extend()
Answer:
(c) count()
Question 5.
You can repeat the elements of the tuple using which operator? [1]
(a) *
(b) +
(c) **
(d) %
Answer:
(a) *
Question 6.
The method used to get the position of file pointer is [1]
(a) tell()
(b) get()
(c) seek()
(d) pos()
Answer:
(a) tell()
Question 7.
Which of the following command displays the attributes of a table along with their types and sizes? [1]
(a) Alter
(b) Show structure
(c) Show create table
(d) View structure
Answer:
(c) Show create table
Question 8.
Which of the following option can be the output for the following code? [1]
import random
List=[“Delhi”,“Mumbai”,”Chennai”,“Kolkata”]
for y in range(4):
x = random.randint(1,3)
print(List[x],end=”#“)
(a) Delhi#Mumbai#Chennai#Kolkata#
(b) Mumbai#Chennai#Kolkata#Mumbai#
(c) Mumbai#Mumbai#Mumbai#Delhi#
(d) Mumbai#Mumbai#Chennai#Mumbai
Answer:
(b) Mumbai#Chennai#Kolkata#Mumbai#
Question 9.
Which function is used to convert string into tuple? [1]
(a) string()
(b) tup()
(c) tuple()
(d) str_tuple()
Answer:
(c) tuple()
Question 10.
The purpose of the primary key in a database is to [1]
(a) unlock the database
(b) provide a map of the data
(c) uniquely identify a record
(d) establish constraints on database operations
Answer:
(c) uniquely identify a record
Question 11.
Fill in the blank : A file can be opened both for reading and writing using mode. [1]
(a) r
(b) r+
(c) a
(d) None of these
Answer:
(b) r+
Question 12.
The …….. clause can be used as an alternative to multiple OR. [1]
(a) IN
(b) BETWEEN
(c) NOT
(d) range
Answer:
(a) IN
Question 13.
State whether the following statement is True or False : In a bus topology, the nodes are connected by separate cables. [1]
Answer:
False
Question 14.
Given a list Lst=[45,100,20,30,50]. What will be the output of Lst[: :]?
(a) [45,100,20,30,50]
(b) []
(c) Error
(d) [45]
Answer:
(a) [45,100,20,30,50]
Question 15.
Fill in the blank : ………. is used to allocate and manage resources for a network.
Answer:
Server
Question 16.
What out of the following you will used to have an audio visual chat with an expert sitting in a far away place to fix-up technical issues? [1]
(a) E-mail
(b) VoIP
(c) FTP
(d) SMTP
Answer:
(b) VoIP
Directions In the question numbers 17 and 18, a statement of Assertion (A) is followed by a statement of Reason (R). Choose the correct option.
Question 17.
Assertion (A) Binary files are processed faster than text files. [1]
Reasoning (R) They are written in Binary format and are more close to the computer
(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.
Answer:
(a) Both A and R are true and R is the correct explanation for A.
Question 18.
Assertion (A) A function that is neither built in nor modular must be defined. [1]
Reason (R) The code of built in and modular functions are available for the Python compiler , but if the function is not defined anywhere the compiler cannot get the code.
(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.
Answer:
(a) Both A and R are true and R is the correct explanation for A.
Section – B
Question 19.
(i) Expand the following terms: [1+1=2]
WAN, VoIP
(ii) Two people, one knowing only English and other knowing only Chinese are talking to each other. Can we call it a communication?
Or
(i) Name any two components required for networking.
(ii) Give one suitable example of each URL and domain name.
Answer:
(i) WAN – Wide Area Network
VoIP – Voice over Internet Protocol
(ii) No, because only a meaningful exchange of information between two living beings is called communication.
Or
(i) Switch/hub and repeaters.
(ii) URL http://www.gabsclasses.com/abouts
Domain name www.gabsclasses.com
Question 20.
Observe the code given below and find the output. [2]
s=”OceanView” print(s[8] +s[2:] +str(len(s)))
Answer:
‘weanView9’
Question 21.
What is the output of below questions? [2]
l1 = [23, 45, 19, 77, 10, 22]
(i) l1.sort( )
(ii) max(l1)
Or
Find error in defination of the function given.
def finderrors(x=20,y) print(x+y*2)
Answer:
(i) [10,19, 22, 23, 45, 77]
(ii) 77
Or
Error 1 : default parameters must be assigned from right to left
Error 2 : Function deflation is missing
Correction:
def finderrors(x=20, y=10) : print(x+y*2)
Question 22.
List some commonly used DBMS software packages. [2]
Or
Explain the use of ORDER BY clause.
Answer:
Some commonly used DBMS software packages are
(i) MySQL
(ii) Oracle
(iii) Postgre
(iv) DB2
(v) MS-SQL
(vi) Sybase
Or
The ORDER BY keyword is used to sort the result set along a specified column with the SELECT command.
The ORDER BY keyword sorts the records in ascending order by default. If you want to sort the records in a descending order, you can use the DESC keyword.
Syntax
SELECT column_name(s) FROM table_name ORDER BY column_name(s) ASC/DESC;
Question 23.
Define reserved words. [2]
Answer:
Reserved words (keywords) are pre-defined by the programming language that have some special or pre-defined meanings. These are reserved for special purpose and must not be used as identifier names.
Question 24.
What output will the following code produce? [2]
empdict={ 'Eno':[1, 2, 3, 4], 'Ename' : [' Raj ', ' Seetna ', 'John', 'Smith'], 'Sal':[10000,20000, 30000,40000]) print(empdict['Ename'][0],empdict['Sal'][0])
Or
Write any two differences between Dictionary and Tuple.
Answer:
(‘Raj’, 10000)
Or
Differences between tuple and dictionary are as follows:
Tuple | Dictionary |
A tuple is a non-homogeneous data structure that can hold a single row as well as several rows and columns. | Dictionary is a non-homogeneous data structure that contains key-value pairs. |
Tuples are immutable i.e., we can not make changes | Dictionaries are mutable and keys do not allow duplicates. |
Question 25.
Write the value stored in the variable Num by each of the following statements. [2]
(i) Num = 2*3-4
(ii) Num = 2+3-1*3
(iii) Num = (2+3)*2
Answer:
(i) Num = 2
(ii) Num = 2
(iii) Num = 10
Section – C
Question 26.
Consider the tables Hotel and Room given below : [1 × 3 = 3]
Table: Hotel
Table: Room
With respect to the tables given above, write SQL commands for the following.
(i) Insert the 1st record.
(ii) Display the details of customers who have arrived after 01-05-2005.
(iii) Display names and room types of customers whose charges are between 2000 and 3000.
Answer:
(i) INSERT INTO Hotel VALUES(“T1”, ”Ri tesh”, ”R1”, ”2016-09-09”, 1800);
(ii) SELECT Cname FROM Hotel WHERE DtofArrival > “2005-05-01”:
(iii) SELECT Cname, RoomType FROM Hotel H.R00M R WHERE H. R00MID=R. R00MID AND (Charges BETWEEN 2000 AND 3000):
Question 27.
A binary file “data.dat” contains records of students as per following structure : [3]
Write a program in Python to search for a student whose number/id is input by the user. If not found appropriate message should be displayed.
Or
Write a program with method countand( ) to count the word ‘and’ or And’ as an independent word in a text file “status.txt”. e.g. if the content of the file “status, txt” is as follows:
Welcome to your one-step solutions for all your study, practice and assessment needs for various competitive and recruitment examinations and school segment. We have been working tirelessly for over a decade to make sure that you have best in class study resources because you deserve SUCCESS AND NOTHING LESS…
Then the output of the program should be: Count of _and_ in file is/are: 3
Answer:
import pickle fobj=open("data.dat"."rb") ano=input("Enter student no. to search :") stlst=[] found=0 while True: try: stlst=pickle.load(fobj) if ano==stlst[0]: print("Found”) print("Name :",stlst[1]) print("Marks :"stlst[2]) found=1 break except EOFError: print("Not found") break if found==0: print("Search Unsuccessful ") fobj.close( )
Or
import os def countand( ): if os.path.isfile(“status.txt”): fob=open(“status.txt”, ‘r’) c=0 while True: Str=fob.readline( ) if not Str: break Str=Str.rstrip().lower().split ( ) for i in range(len(Str)) : if (Str[i]==‘and’ or Str[i]== ‘AND’): c=c+1 print(“Count of_and_in file is/are : ”,c) else: print(‘‘File does not exist”) countand( )
Question 28.
Write the SQL commands for (i) to (iii) on the basis of the table HOSPITAL. [1 × 3 = 3]
TABLE: HOSPITAL
(i) To show all information about the patients of Cardiology Department.
(ii) To list the name of female patients, who are in Orthopaedic Department.
(iii) To list names of all patients with their date of admission in ascending order.
Answer:
(i) SELECT * FROM HOSPITAL WHERE Department = ‘Cardiology’;
(ii) SELECT Name FROM HOSPITAL WHERE Department = ‘Orthopaedic’ AND Sex = ‘F’;
(iii) SELECT Name FROM HOSPITAL ORDER BY Dateofadm;
Question 29.
Write user defined functions factors(num) and factorial(num) to find the factors and factorial of a number accepted from the user and passed to the functions from main function. [3]
Answer:
def factorial(num): f=1 for i in range(1, (num+1)): f*=i print("Factorial :”,f) def factors(num): print("Factors of ”,num) for i in ranged, (num+1)): if num%i==0: print(i) def main( ): n=int(input!"Enter a number :")) factorial(n) factors(n) main( )
Question 30.
Write the Push operation of stack containing person names. Note that the name should only accept characters, spaces and period(.) except digits. Assume that Pname is a class instance attribute. [3]
Answer:
def insert( ): name_pattern=re.compile (r “[A-Za-zs.]”) while True: n = input (‘‘Enter name:”) while name_pattern.search (n): print ("Invalid name”) print (“Enter name correctly”) n = input( ) Sname. append (n) c = input (“Enter more name <y/n)”).upper( ) if (c! = ‘y’); break
Section – D
Question 31.
Consider the following table Cab. [1 × 4 = 4]
Table: Cab
Write statements to :
(a) Add a new column Driver varchar(30)
(b) Change data type of Rate column to float(6, 1).
(c) To display the cab type whose rate is more than 25.
(d) To display cab id and Number of passengers for cab Sedan.
Answer:
(a) ALTER TABLE Cab ADD Driver varchar(30);
(b) ALTER TABLE Cab MODIFY Rate float(6, 1);
(c) SELECT CabType FROM Cab WHERE Rate>25;
(d) SELECT CabID, Nop FROM Cab WHERE CabType = “Sedan”;
Question 32.
Write a Python program for operating on a CSV file “people.csv” using following functions: [4]
addPeople() To input details of people and add them to a CSV file “people.csv” without removing the previous records. The record structure is as follows :
AdhrNo Name City Age
The file should store only those people whose age is greater than and equal to 18.
getPeople( ) To open the file “people.csv” and display records whose name starts with “P”
Answer:
import csv def addPeople() : with open(“people.csv”, "a") as f: dt = writer(f) while True: ano= int(input(”Enter aadhar No:")) pname = input("Enter person name:") city = input("Enter city:") age = int(input("Enter age:")) dt.writerow([ano, pname, city, age]) print("Record has been added.") print("Want to add more record?Type YES! ! !") ch = input( ) ch = ch.upper( ) if ch=="YES”: print ("_______________") else: break def getPeople(): with open(“people.csv”, 'r') as file: reader = csv.reader(file) for row in reader: if row[1][0]==’P’ : print(row) file.close( ) addPeople( ) getPeople( )
Section – E
Question 33.
Quick Learn University is setting up its academic blocks at Prayag Nagar and planning to set up a network. The university has three academic blocks and one human resource centre as shown in the diagram below: [1 × 5 = 5]
Centre to centre distance between various blocks/centre as follows:
Number of computers in each of the bolcks/centre are as follows:
Law Block | 15 |
Technology Block | 40 |
HR Centre | 115 |
Business Block | 25 |
(i) Suggest the most suitable place (i.e. block/centre) to install the server of this university with a suitable reason.
(ii) Suggest an ideal layout for connecting these blocks/centres for a wired connectivity.
(iii) Which device you will suggest to be placed/installed in each of these blocks/centre to efficiently connect all the computers with in these blocks/centre ?
(iv) The university is planning to connect its admission office in the closest big city, which is more than 250 km from university, which type of network out of LAN, MAN or WAN will be formed? Justify your answer.
(v) Expand the following
LAN
WAN
Answer:
(i) The most suitable place to install the server is HR centre because it has maximum number of computers.
(ii)
(iii) Switch
(iv) WAN as it is another city.
(v) Local Area Network; Wide Area Network
Question 34.
(a) Mention atleast two limitations of DBMS. [1 + 4 = 5]
(b) Here is a table Club.
Or
Write the Python code for the following.
Update the Address of member whose Memberld is M003 with Noida.
Or
(a) What are primary and alternate key in a database?
(b) Here is a table Club.
Write the Python code for the following:
Delete the record of those member whose name is Sachin.
Answer:
(a) Some limitations of DBMS are given below
(i) DBMS requires various software, hardware and highly intelligent people for operating and maintaining the
database system. It increases its cost.
(ii) If database is corrupted due to power failure or any other reason, our valuable data may be lost or whole system stops.
(b)
import mysql.connector mycon = mysql .connector.connect (host = "localhost”, user = “Admin”, passwd = “Admin@123”, database = “System”) cursor = mycon.cursor ( ) try: cursor.execute (“UPDATE Club SET Address = “Noida” WHERE Memberld = “M003”)”) mycon.commit ( ) except : mycon.rollback ( ) mycon.close ( )
Or
(a) Primary key is a column or set of columns which helps to identify row uniquely.
Alternate key is a column or set of columns that can act as a primary key but not selected as a primary key.
(b)
import mysql. connector mycon = mysql. connector.connect (host = “localhost”, user = “Admin”, passwd = "Admin@123”, database = “System”) cursor = mycon.cursor ( ) try: cursor.execute (“DELETE FROM Club WHERE MemberName = ‘Sachin’)” cursor.commit ( ) except: mycon.roll back ( ) mycon.close ( )
Question 35.
(i) What does csv.writer() function do? [2 + 3 = 5]
(ii) Given a file “dept.dat”, containing records of departments with following attributes:
Candidate: Name of the candidates Department: Department name like: Computer, Physics, Math, Biology, etc. Write a method copy that would read contents from the file “dept.dat” and creates a file named “com.dat” copying only those records from “dept.dat” where the department name is “Computer”. Assume that is a field separator in “dept.dat”.
Or
(i) What is the use of writerow() function?
(ii) A file “Toys.csv” exists storing details of toys as per following structure :
ToyID Toyname Category Cost
Or
Write a program in Python with functions as follows :
addToy() To append data of toys and store them to the file “Toys.csv” only if the Toy category is “Boys”. Also, display the number of toys added.
showToys() To open the file “Toys.csv” and display records of toys whose cost is above 1000.
Answer:
(i) The csv.writer() function returns a writer object that converts the user’s ‘data into a delimited string.
This string can later be used to write into CSV files using the writerow() function.
(ii)
import os def copy( ): f1=“dept.dat” if not os.path.isfile(f1): print(f1, “File does not exist”) else: dobj=open(“dept.dat”,“rb”) cobj=open(“com.dat”,"wb”) for c in dobj: status=c.rstrip( ) ncom=status.split (’-’) size=len(ncom) name=ncom[0] dept=n com[1] If(dept==’ Computer’): cobj.write(name.upper( ) + “-“ + dept.upper() + “\n”) dobj.close() cobj.close()
Or
(i) The writers () method is used to write a single row at a time into a CSV file. We can write a field row using this method.
(ii)
import csv def addToy() : with open(”Toys.csv”,”a") as f: dt = writer(f) tid=”” tname=”" cat ="" cost=0 while True: tid= int(input(”Enter toyid:”)) tname = input(”Enter toy name:”) cat = input(”Enter category:”) cost= int(input(”Enter cost:”)) dt.writerow([tid, tname, cat, cost]) print(”Record has been added.”) print(”Want to add more record? Type YES!!!”) ch = input() ch = ch.upper( ) if ch=="YES”: print(”__________") else: break f.close( ) def showToys( ): with open(”Toys.csv”, ‘r’) as tfile: reader = csv.reader(tfile) for row in reader: if int(row[3])>1000: print(row) tfile.cose( ) addToy() showToys()