CBSE Class 12 Computer Science Question 40 of 42

Solved 2024 Sample Question Paper CBSE Class 12 Computer Science (083) — Question 3

Back to all questions
3
Question

Question 34(b)

(i) How are text files different from binary files?

(ii) A Binary file, CINEMA.DAT has the following structure:

{MNO:[MNAME, MTYPE]}

Where

MNO – Movie Number
MNAME – Movie Name
MTYPE is Movie Type

Write a user defined function, findType(mtype), that accepts mtype as parameter and displays all the records from the binary file CINEMA.DAT, that have the value of Movie Type as mtype.

Answer

(i)

Text filesBinary Files
Extension is .txtExtension is .dat
Data is stored in ASCII format that is human readable.Data is stored in binary form (0s and 1s), that is not human readable.

(ii)

def Searchtype(mtype):
    fobj = open("CINEMA.DAT", "rb")
    try:
        while True:
            data = pickle.load(fobj)
            if data[2] == mtype:
                print("Movie number:", data[0])
                print("Movie Name:", data[1])
                print("Movie Type:", data[2])

    except EOFError:
        fobj.close()