Anjeev Singh Academy

Anjeev Singh Academy

CBSE XII Computer Science 083 Practical Question Paper Set 4 – Download in Word

AISSCE XII Computer Science 083 – Practical Question Paper Set #4 – Download Word File

All India Senior Secondary Certificate Examination
XII Computer Science 083 – Practical Question Paper Set #4

Are you looking for Answer Key? Please Scroll to the Down 👇

Answer Key of Set 4 Practical Examination Question Paper

Answer Key Set – 4

 Q1. LAB TEST                                                                                                                      [8+4=12]

  1. Write a program to write data into binary file marks.dat and display the records of students who scored more than 95 marks.

Answer:

# Solution of Que 1 A
#-----------------------------------
# Binary file

import pickle

def WriteScore():
    fout = open("marks.dat", "wb")           # opening of file
    while True:
        rec = {}
        rollno = int(input("Enter Roll Number : "))
        name = input("Enter Name : ")
        marks = float(input("Enter marks : "))
        rec['rollno'] = rollno
        rec['name'] = name
        rec['marks'] = marks
        pickle.dump(rec, fout)  #write one record in a file refered by fout
        print()
        wish = input("Wish to add more records y/n ")
        if wish.lower() != 'y':
            break
    fout.close()

def Display_95_above():
    fin = open("marks.dat", "rb")
    try:
        while True:    			# loop is required to read all records
            rec = pickle.load(fin)		# read only one record
                                  			# at a time refered by fin file object
            if rec['marks'] > 95 :
                print(rec['rollno'], rec['name'], rec['marks'])
    except:
        fin.close()


#__ main ___ block

print("Writing Records in Marks.dat")
WriteScore()

print("Reading Records from Marks.dat")
Display_95_above()

Output:

Writing Records in Marks.dat

Enter Roll Number : 1

Enter Name : Amrit

Enter marks : 99.9

Wish to add more records y/n y

Enter Roll Number : 2

Enter Name : Tanmay

Enter marks : 99

Wish to add more records y/n y

Enter Roll Number : 3

Enter Name : Ravi

Enter marks : 58

Wish to add more records y/n y

Enter Roll Number : 4

Enter Name : Sona

Enter marks : 67

Wish to add more records y/n y

Enter Roll Number : 5

Enter Name : Madhu

Enter marks : 76

Wish to add more records y/n n

Reading Records from Marks.dat

1 Amrit 99.9

2 Tanmay 99.0

OR

Write a program to copy the records of that student having marks more than 95 from binary file “marks.dat” into the “topper.dat” file.

Answer:

# Solution of Que 1 A OR
#-----------------------------------
# Binary file

import pickle

def WriteRecords():
    fout = open("marks.dat", "wb")           # opening of file
    while True:
        rec = {}
        rollno = int(input("Enter Roll Number : "))
        name = input("Enter Name : ")
        marks = float(input("Enter marks : "))
        rec['rollno'] = rollno
        rec['name'] = name
        rec['marks'] = marks
        pickle.dump(rec, fout)  #write one record in a file refered by fout
        print()
        wish = input("Wish to add more records y/n ")
        if wish.lower() != 'y':
            break
    fout.close()

def CopyTopper():
    fin = open("marks.dat", "rb")
    fout = open("topper.dat", "wb")
    try:
        while True:    			# loop is required to read all records
            rec = pickle.load(fin)		# read only one record
                                 			# at a time refered by fin file object
            if rec['marks'] > 95 :
                pickle.dump(rec, fout)
                print(rec['rollno'], rec['name'], rec['marks'])
    except:
        fin.close()
        fout.close()
        print("Copied successfully")


#__ main ___ block

print("Writing Records in marks.dat")
WriteRecords()

print("Copying Records from marks.dat to topper.dat")
CopyTopper()

Output:

Writing Records in Marks.dat

Enter Roll Number : 1

Enter Name : Amrit

Enter marks : 99.9

Wish to add more records y/n y

Enter Roll Number : 2

Enter Name : Tanmay

Enter marks : 99

Wish to add more records y/n y

Enter Roll Number : 3

Enter Name : Ravi

Enter marks : 58

Wish to add more records y/n y

Enter Roll Number : 4

Enter Name : Sona

Enter marks : 67

Wish to add more records y/n y

Enter Roll Number : 5

Enter Name : Madhu

Enter marks : 76

Wish to add more records y/n n

Copying Records from marks.dat to topper.dat

1 Amrit 99.9

2 Tanmay 99.0

Copied successfully

B.  Observe the following code and fill in the given blanks as directed: 

import mysql.connector as mycon

mydb=mycon.connect(_______________________________________)        # Statement 1

mycursor=mydb.___________                                                                           # Statemen 2

mycursor.execute(__________________________________________)         # Statement 3

myresult = mycursor.__________                                                                      # Statement 4

for x in myresult:

print(x)

The partial code is given for displaying all records from customer table created. The customer table is given as following:

CustomerIDCustomerNameCityBillAmtMobileNo
111AbhishekAhmedabad15009999999999
222Ram kumarChennai15018888888888

i. Write the parameters and values required to fill statement 1. The parameters values are as follows:

Database Server            :           localhost

User                               :           root

Pasword                         :           rootpass

Database                       :           customer

ii. Write function name to create cursor and fill in the gap for statement 2.

iii. Write a query to fill statement 3 to display all records from customer table.

iv. Write function to fill statement 4 to fetch all records from customer table.

Answer:

(i) Statement 1:

mydb = mycon.connect(host =localhost”, user =”root”, password = “rootpass”, database = “customer”)

(ii) Statement 2:

mycursor = mydb.cursor()

(iii) Statement 3:

mycursor.execute(“SELECT * FROM CUSTOMER”)

(iv) Statement 4:

myresult = mycursor.fetchall( )

Sorry! You cannot copy content of this page. Please contact, in case you want this content.

Scroll to Top