XII - CS SET-B - MS - CbeSSC - DEC 1984
XII - CS SET-B - MS - CbeSSC - DEC 1984
General Instructions:
1. This question paper contains five sections, Section A to E.
2. All questions are compulsory.
3. Section A has 18 questions carrying 01 mark each.
4. Section B has 07 Very Short Answer type questions carrying 02 marks each.
5. Section C has 05 Short Answer type questions carrying 03 marks each.
6. Section D has 03 Long Answer type questions carrying 05 marks each.
7. Section E has 02 questions carrying 04 marks each. One internal choice is given in Q35
against Part-C only
8. All programming questions are to be answered using Python Language only.
(v)
32 (a) Predict the output for the following code: 2+3
num=123
f=0
s=0
while(num > 3):
rem = num % 100
if(rem % 2 != 0):
f += rem
else:
s+=rem
num /=100
print(f-s)
Ans. 23
(b) A library uses a database management system (DBMS) to store the details
of the books that it stocks, its registered members and the book-loans that the
library has made. These details are stored in a database using the following
three relations. Name of the Database: KVS Library. (NOTE: The library
does not stock more than one copy of the same book)
Book(BookID: Char(5), Title: Varchar(25), Author: Varchar(25),
Publisher: Varchar(100))
Member(MemberID: Char(5), FirstName: Varchar(25), LastName:
Varchar(25), Correspondance-Address: Varchar(100), Pincode: Char(6),
DateofBirth: Date, EmailID:Varchar(50))
Loan(MemberId: Char(5), BookID: Char(5), LoanDate: Date,
DueBackDate: Date, Returned: Boolean)
(i) Identify following types of keys from all the relations of the given
database: Foreign keys along with parent relations
(ii) Can a relation have multiple foreign keys? Give example.
(iii) Write a SQL query to retrieve the names and email addresses of the
members belonging to KVS (they have email ids as [email protected]) and who
have not returned their books.
Ans. (i) Foreign keys in relation loan: Member ID(Parent table Member)
Book ID(Parent table Book)
(ii) Yes, a relation can have multiple foreign keys. Eg., loan relation given
above has 2 foreign keys-MemberID and BookID
(iii) SELECT FIRSTNAME,LASTNAME,EMAILID FROM
MEMBER,LOAN WHER MEMNER.MEMBERID=LOAN.MEMBERID
AND EMAILID LIKE %@kvs.in AND RETURNED=”F”;
(OR)
(a) Predict the output for the following code:
def test(i, a =[]):
a.append(i)
return a
test(25)
test(32)
s = test(17)
print(s)
Ans. [25,32,17]
(b) The given program is used to connect with MYSQL and show the name of
all tables available in MySQL server ”TEST” database. You are required to
complete the statements so that the code can be executed properly.
import _______ (i)
# complete the statement with appropriate library name
db=mysql.connector. __________(ii)
(host=”localhost”, user=”root”, password=”smsmb”)
# fill the statement with appropriate method
cur=db._________( ) (iii)
# method to open the cursor object
data= ”______” (iv)
#complete the statement with the appropriate database name
cur.execute(“________”+data) (v)
# command to open the database
cur.execute(“______________________”) (vi)
#command to display name of all the tables
Ans. (i) mysql.connector (ii) connect (iii) cursor() (iv) “test” (v) use (vi) show
tables
33 What is stack type of data structure? List out its applications. 5
Write a function called authenticate(users,loginid,password) which takes
following three parameters:
users: a dictionary storing login ids and corresponding password values
loginid: a string for a login name
password: a string for a password
The function should do the following:
(i) if the user exists and the password is correct for the given loginid, it should
print “Access granted”
(ii) if the user exists and the password is incorrect for the given loginid, it
should print “Incorrect password”
(iii) if the user does not exist for the given loginid, it should print “Wrong
credentials”
Ans. Stack is a linear type of data structure which stores the data in LIFO
order. Applications: Reverse a string, polish strings.
def authenticate(users,loginid,password):
if loginid in users:
if users[loginid]==password:
res=”Access granted”
else:
res=”Incorrect password”
return res
users={‘j123:”12%%34”,”xyz1”:”aa@@123”,”kbc2020”:”kyc&12@20”}
uid=input(“Enter loginid:”)
pwd=input(“Enter password:”)
r=authenticate(users,uid,pwd)
print(r,”for”,uid)
(OR)
What is a file? How a text file is different from binary file?
A binary file “BOOK.dat” has structure [BookNo, Book_Name, Author,
Price]
(i) Write a user defined function Createfile( ) to input data for a record and add
to Book.dat
(ii) Write a function Countrec(Author) in python which accepts the Author
name as parameter and count and return number of books by the given Author
are stored in the binary file “Book.dat”
Ans. import pickle
def createfile():
fobj=open(“Book.dat”,”ab”)
BookNo=int(input(“Book number:”))
Book_Name=input(“Name:”)
Author=input(“Author:”)
Price=int(input(“Price:”))
rec=[BookNo,Book_Name, Author,Price]
pickle.dump(rec,fobj)
fobj.close( )
def Countrec(Author):
fobj=open(“Book.dat”,”rb”)
num=0
try:
while True:
rec=pickle.load(fobj)
if Author==rec[2]:
num=num+1
except:
fobj.close( )
return num
S.NO SECTION-E MARKS
34 Database name: Shop 1+1+2
Table name: Infant
Itemcode Item Datepurchase Unitprice Discount
101 Frock 2016-01-23 700 10
102 Cot 2015-09-23 5000 25
103 Soft Toy 2016-06-17 800 10
104 Baby Socks 2014-10-16 100 7
105 Baby Suit 2015-09-20 500 5
(i) Write a query to make Item code as primary key in the above existing table.
(ii) Write the command to remove the column Discount.
(iii) (a) Write the command to display the structure of the table infants which
is Shop database.
(b) Write the degree and cardinality of the table.
(OR) (Option given for part (iii) only)
(iii) (a) Add a new row with the following values in respective attributes.
Itemcode=106, Item=Bath Tub, Datepurchase=2015-10-22, Unitprice=1500
(b) Write the command to display Item, Unitprice in descending order.
Ans. (i) ALTER TABLE INFANT ADD PRIMARY KEY(ITEMCODE);
(ii) ALTER TABLE INFANT DROP DISCOUNT;
(iii)(a) DESC INFANTS; (b) Degree=5, Cardinality=5 (OR)
(iii) (a) INSERT INTO INFANTS(ITEMCODE,
ITEM,DATEPURCHASE,UNITPRICE) VALUES(106, ‘BATH TUB’, 2015-
10-22’,1500);
(b) SELECT ITEM ,UNITPRICE FROM INFANTS ORDER BY
UNITPRICE DESC;
35 Ariba Malik has been following incomplete code, which takes a student’s 4
details (rollnumber, name and marks) and writes into a binary file stu.dat using
pickling.
import pickle
sturno=int(input(“Enter roll number:”))
stuname=input(“Enter name:”)
stumarks=float(input(“Enter marks:”))
stu1={“RollNo.”:sturno,”Name”:stuname,”Marks”:stumarks}
with __________ as fh: # Fill_Line1
________________ # Fill_Line2
______________ as fin: # Fill_Line3
________________ # Fill_Line4
print(Rstu)
if Rstu[“Marks”]>=85:
print(“Eligible for merit certificate”)
else:
print(“Not eligible for merit certificate”)
(a) Complete Fill_Line1 so that the mentioned binary file is opened for writing
in fh object using a with statement.
(b) Complete Fill_Line2 so that the dictionary stu1’s contents are written on
the file opened in step(a)
(c) Complete Fill_line3 so that the earlier created binary file is opened for
reading in a file object namely fin, using a with statement.
(d) Complete Fill_line4 so that the contents of open file in fin are read into a
dictionary namely Rstu.
Ans. (a) with open(“Stu.dat”,”wb”) as fh:
(b) pickle.dump(Stu1,fh)
(c) with open(“Stu.dat”,”rb”) as fin:
(d) Rstu=pickle.load(fin)