CBSE Class 12 Computer Science Binary File MCQs

Refer to CBSE Class 12 Computer Science Binary File MCQs provided below available for download in Pdf. The MCQ Questions for Class 12 Computer Science with answers are aligned as per the latest syllabus and exam pattern suggested by CBSE, NCERT and KVS. Multiple Choice Questions for Binary File are an important part of exams for Class 12 Computer Science and if practiced properly can help you to improve your understanding and get higher marks. Refer to more Chapter-wise MCQs for CBSE Class 12 Computer Science and also download more latest study material for all subjects

MCQ for Class 12 Computer Science Binary File

Class 12 Computer Science students should refer to the following multiple-choice questions with answers for Binary File in Class 12.

Binary File MCQ Questions Class 12 Computer Science with Answers

Question. Which is not the valid mode for binary files?
a) r
b) rb
c) wb
d) wb+

Answer : A

Question. Out of the followings which mode is used for both reading and writing in binary format in file?
a) wb
b) wb+
c) w
d) w+

Answer : B

Question. The pickle module in Python is used for:
a) Serializing any Python object structure
b) De-serializing Python object structure
c) Both a and b
d) None of these

Answer : C

Question. Which of the following function is used to read the data in binary file?
a) read()
b) open()
c) dump()
d) load()

Answer : D

Question. Which of the following is not true about binary files?
a) Binary files are store in terms of bytes
b) When you open binary file in text editor will show garbage values
c) Binary files represent ASCII value of characters
d) All of the above

Answer : C

Question. seek() function is used for _______.
a) positions the file object at the specified location.
b) It returns the current position of the file object
c) It writes the data in binary file
d) None of these

Answer : A

Question. What is pickling?
a) It is the process to read binary file
b) It is the process to position the file pointer
c) It is a process by which a Python object is converted to a byte stream
d) None of these

Answer : C

Question. Which method is used to convert Python objects for writing data in binary file?
a) write()
b) load()
c) store()
d) dump()

Answer : D

Question. This method returns an integer that specifies the current position of the file object.
a) seek()
b) load()
c) position()
d) tell()

Answer : D

Question. What is the difference between wb and wb+ mode?
a) wb mode is used to open binary file in write mode and wb+ mode open binary file both for read and write operation.
b) In wb mode file open in write mode and wb+ in read mode
c) File pointer is at beginning of file in wb mode and in wb+ at the end of file
d) No difference

Answer : A

Question. Suresh wants to open the binary file student.dat in read mode. He writes the following statement but he does not know the mode. Help him to find the same.
F=open(‘student.dat’, ____)
a) r
b) rb
c) w
d) wb

Answer : B

Case Study Based Question - 1

Now Mr. Zack has given the following code to modify the records of employees from employee.dat used in above code. He has to increase Rs. 2000 in the salary of those who are getting less than 15000. Mr. Zack has to find the records and change the salary in place. His teacher gave him partial code. Help him to complete the code.
import pickle as pk
found=False
emp={}
fin = ___________ #1 statement : open file both in read write mode
# read from file
try:
while true:
pos= _______ #2 store file pointer position before reading record
emp=_______ #3 to read the record in emp dictionary
if emp[‘salary’]<15000:
emp[‘salary’]+=10000
_________ #4 place file pointer at exact location of record
pickle.dump(emp,fin)
found=True
except EOFError:
if found==False:
print(“record not found”)
else:
print(“successfully updated”)
fin.close() 

Question. Choose the appropriate statement to complete #3 statement to read record in emp dictionary.
a) pk.read(fin)
b) pickle.load(fin,emp)
c) pk.dump(emp)
d) pk.load(fin)

Answer : D

Question. In #1 statement open the file in read and write mode. Which statement is used out of the followings?
a) open(“employee.dat”,’rb+’)
b) open(“employee.dat”,’r+’)
c) open(“employee.dat”,’a’)
d) open(“employee.dat”,’rb’) 

Answer : A

Question. Choose the appropriate statement to complete #4 statement to place file pointer at exact location of record
a) fin.seek(pos)
b) pos=fin.seek()
c) fin.position()
d) none of the above

Answer : B

 

Question. Choose the appropriate statement to complete #2 statement to store file pointer position before reading record.
a) pk.seek(pos)
b) fin.tell()
c) pk.position()
d) pk.tell()

Answer : B

Case Study Based Question - 2

Mr. Zack Sullivan loves programming. He joined an institute for learning. He is learning python. He learned all the python concepts like strings, lists, tuple , dictionaries etc. but he wants to learn file handling in python. He is trying to learn binary file handling. His teacher gave him partial code to write and read data from employee.dat having structure empno, name, salary. Help Zack to complete the code:
___________________ # statement 1
def addrecords():
fw= _____________ #statement 2
dict={}
ch=’y’
while ch==’y’:
eno=int(input(“enter employee number”))
nm= input(“enter employee name”)
sal=int(input(“enter employee salary”))
dict={‘empno’:eno,’name’:nm,’salary’:sal}
____________________ # statement 3
ch=input(“add more record”)
fw.close()
# function to diplay records
def display():
dict={}
fr= _____________ # statement 4
dict=____________ # statement 5
fr.close()
print(“data :”,dict) 

Answer questions 12-16 based on above case study

Question. Which statement is used from the following for statement 3 to write dictionary data created in above code, namely dict, is written in binary file employee.dat file?
a) pickle.dump(dict,fw)
b) pickle.write(dict,fw)
c) pickle.save(dict,fw)
d) pickle.store(dict)

Answer : A

Question. Help Zack to import the module to perform binary file operation in statement 1.
a) csv
b) random
c) pickle
d) file

Answer : C

Question. Compelete statement 5 to read data in dictionary namely dict from the opened binary file?
a) dict=pk.read(fr)
b) dict=pickle.load(fr)
c) pickle.load(dict,fr)
d) none of these

Answer : B

Question. Which statement is used from the following for statement 2 to open the binary file in write mode?
a) open(“employee.dat”,’w’)
b) open(“employee.dat”,’wb’)
c) open(“employee.dat”,’w+’)
d) open(“employee.dat”,’r’)

Answer : B

Question. Which statement is used from the following for statement 4 to open the binary file in read mode?
a) open(“employee.dat”,’r’)
b) open(“employee.dat”,’r+’)
c) open(“employee.dat”,’a’)
d) open(“employee.dat”,’rb’)

Answer : D

CASE STUDY QUESTIONS (R)

A function searchprod( pc) in python is created to display the record of a particular product from a file product.dat whose code is passed as an argument. Structure of product contains the following elements [product code , product price].There is some problem in completing the code,help to finish the code:
f = ________(‘d:/product.dat’,’rb’) #line1
flag = False
pc=input(“Enter product code to be searched”)
while True:
try:
rec = pickle.load(f)
if rec[‘pcode’] ==_____: #line2
print(‘Product code:’,rec[‘pcode’])
print(‘Price:’,rec[‘price’])
flag = True
except EOFError:
break
if flag == False:
print(‘No Records found’)
f.close() 

Question. The variable used to accept product code entered by the user for the line2
a) pcode
b) pc
c) code
d) None of these

Answer : B

Question. Identify the method in line1.
a) close
b) open
c) OPEN
d) None of the above

Answer : B
 

Ms. Suman is working on a binary file and wants to write data from a list to a binary file.
Consider list object as l1, binary file suman_list.dat, and file object as f

Question. Which option will be correct for reading file for suman?
a) f = open(„suman_list‟,‟rb‟)
b) f = open(„suman_list‟,‟r‟)
c) f = open(„suman_list‟,‟r+‟)
d) f = open(„suman_list‟,‟ab‟)

Answer : A

Question. Which one of the following is correct statement?
a) import – pickle
b) pickle import
c) import pickle
d) All of the above

Answer : C

Question. In which of the file mode existing data will be intact in binary file?
a) a
b) ab
c) w
d) wb

Answer : B

Question. Which of the following can be the correct statement for her?
a) f = open(“suman_list”,”wb”); pickle.dump(l1,f)
b) f = open(“suman_list”,”rb”); l1=pickle.dump(f)
c) f = open(“suman_list”,”wb”); pickle.load(l1,f)
d) f = open(“suman_list”,”rb”); l1=pickle.load(f)

Answer : A

Question. What are the binary files used for?
a) It is used to store data in the form of bytes.
b) To store data
c) To look folder good
d) None of these

Answer : A


A Binary file Stock.dat has a structure [pno,pname,qty,price].A user defined function Createfile() to input data for 3 records and add to stock.dat .There are some blanks help in filling the gaps in the code:
Incomplete Code :
Import ___________ # Statement 1
def createfile():
File=open(“d:\\Stock.dat”,‟____‟) #Statement 2
pno=input(“Enter product no:”)
pname= input(“Enter product name:”)
qty= input(“Enter product quantity:”)
price= input(“Enter product price:”)
record=[pno,pname,qty,price]
_______________ # Statement 3
Print(“Record inserted”)
File.close()
Createfile()

Question. Identify the suitable code for blank space in line marked as Statement-1.
a) csv
b) CSV
c) pickle
d) PICKLE

Answer : C

Question. Which method is used for object deserialization ?
a) Pickling
b) Unpickling
c) All of the above
d) None of the above

Answer : B

Question. select correct statement to write data into file for Statement-3.
a) pickle.dump(record,file)
b) pickle.dump(record)
c) pickle.dump(file,record)
d) pickle.load(record,file)

Answer : A

Question. What is the last action that must be performed on a file?
a) save
b) close
c) end
d) write

Answer : B

Question. Identify the suitable code for blank space in line marked as Statement-2.
a) wb
b) ab
c) w
d) a

Answer : B


Mr. Rohan wants to modify salary of employee having a structure[eid,ename ,salary],but unable to fill the gaps in the code. Help him to complete the code
Import pickle
f = open(‘d:/student.dat’,’rb’)
reclst = []
r=___________________________ # line 1 code to ask employee id
m=int(input(“enter correct salary”))
while True:
try:
rec = pickle.load(f)
reclst.append(rec) #line2 statement to add items in list at the end one by one
except EOFError:
break
f.close()
for i in range (len(reclst)):
if reclst[i][‘eid’]==r:
reclst[i][‘salary’] = m
f = open(‘d:/student.dat’,’___’) #line 3 mode to be used to copy the data
for x in reclst:
pickle.dump(x,f)
f.close()

Question. The module used in line2
a) PICKLE
b) pickling
c) pickle
d) None of these

Answer : C

Question. Identify the code in line1.
a) int(input(“Enter employee id”))
b) int(“Enter employee id”)
c) int(INPUT(“Enter employee id”))
d) None of the above

Answer : A

Question. Fill in the code marked as line-3.
a) w
b) wb
c) r
d) rb

Answer : B


Ms. Sejal is working on the sports.dat file but she is confused about how to complete the code to read the data from the binary file. Suggest a suitable line for her to fulfil her.
____________ # Statement 1
def sports_read ():
f1 = _______________ # Statement 2
_________________ # Statement 3
print(data)
f1. close ()
sports.read()

Question. Identify the suitable code for blank space in line marked as Statement-3.
a) data = pickle.load(f1)
b) data = pickle.dump(f1)
c) data = pickle.load(f)
d) data = pickle.dump(f)

Answer : A

Question. Identify the suitable code for blank space in line marked as Statement-1.
a) pickle import
b) import pickle
c) import.pickle
d) None of these Correct

Answer : B

Question. Which of the following file modes will not delete the existing data in binary file ?
a) wb
b) w
c) a
d) ab

Answer : D

Question. Identify the suitable code for blank space in line marked as Statement-2.
a) f1 =open(“sports.dat”,”wb”)
b) f1 =open(“sports.dat”,”r”)
c) f1 =open(“sports.dat”,”rb”)
d) None of these Correct

Answer : C

Question. What is the description of ‘r+b’ in binary mode?
a) read and write
b) write and read
c) read only
d) none of these

Answer : A


A binary file “salary.DAT” has structure [teacherid, teacher name, salary]. Complete the code in the blanks so that it would read contents of the file “salary.DAT” and display the details of those teachers whose salary is above 20000.
import pickle
____________________________ # line1
try:
print(“tr id\t tr Name\t tr Sal”)
while True:
rec=___________.load(fobj) #line2
if rec[2]>_______: #line3
print(rec[0],”\t\t”,rec[1],”\t\t”,rec[2])
except:
____.close() #line 4

Question. Which of the following File Modes creates a new file, if the file does not exist? (choose one/more)
a) “r”
b) “bw”
c) “w”
d) “a”

Answer : C

Question. To open the file for writing the data in line marked as line-1.
a) fobj=open(“salary.dat”,”rb”)
b) fobj=open(“salary.dat”,”r”)
c) fobj=open(“salary.dat”,”r+”)
d) fobj=open(“data.dat”,”rb”)

Answer : A

Question. Identify the salary to be checked in the code marked as line-3.
a) 50000
b) 20000
c) 24000
d) 10000

Answer : B

Question. What is true about Binary files
a) They are not human readable
b) the file extension is .dat
c) the file stores same format as held in memory.
d) All of the above

Answer : D

Question. The module used in line2
a) PICKLE
b) pickling
c) pickle
d) None of these

Answer : C


Sarita is trying to add data onto a existing binary file and is facing difficulty in completing the code.Help her to fill the gaps in the code.
Incomplete Code:
import pickle
print(“WORKING WITH BINARY FILES”)
_____________________________ # Statement 1
recno=1
print (“Enter Records of Employees”)
print()
#taking data from user and dumping in the file as list object
while True:
print(“RECORD No.”, recno)
eno=int(input(“\tEmployee number : “))
ename=input_____________________ # Statement 2
ebasic=int(input(“\tBasic Salary : “))
allow=int(input(“\tAllowances : “))
totsal=ebasic+allow
print(“\tTOTAL SALARY : “, totsal)
edata=[eno,ename,ebasic,allow,totsal]
pickle.dump(_____________) # Statement 3
ans=input(“Do you wish to enter more records (y/n)? “)
recno=recno+1
if ans.lower()==’n’:
print(“Record entry OVER “)
print()
break # retrieving the size of file
print(“Size of binary file (in bytes):”,
bfile.tell())
______() # Statement 4

Question. Identify the suitable code for blank space in line marked as Statement-4.
a) bfile.close()
b) bfile.close
c) file.close()
d) none of these

Answer : A

Question. To open the file for writing the data in line marked as Statement-1.
a) bfile=open(“empfile.dat”,”ab”)
b) bfile=open(“empfile.dat”,”a”)
c) bfile=open(“empfile.dat”,”wb”)
d) bfile=open(“empfile.dat”,”w”)

Answer : A

Question. Identify the suitable code for blank space in line marked as Statement-3.
a) edata,bfile()
b) edata,bfile
c) data,bfile
d) edata,file

Answer : B

Question. Which of the following is the correct syntax to read from a file using load function ?
a) pickle.load(<filehandle>)
b) <object> – load.pickle(<filehandle>)
c) <object> – pickle.load(<filehandle>)
d) All of the above

Answer : C

 

Question. To accept employee name from the user in line marked as Statement-2.
a) input(“\tEmployee Name : “)
b) input(Employee Name 🙂
c) input(“Employee Name )
d) None of these

Answer : A
 

A binary file sports.dat contains information in the following structure:( Event, Participant )
A code is shown below which is incomplete that would read contents from the sports.dat and creates a file named Athletic.dat copying only those records from sports.dat where the event name is “Athletics”.
import pickle
ath ( f1 , f2 ) :
l = pickle.load ( f1)
for t in l :
if ( t [ 0 ] == “________________” ) : #line 1
pickle.__________ ( t , f2 ) #line 2
f1 = open ( “ sports.dat “ , “ rb ” )
f2 = open ( “ athletics.dat “ , “ wb “ )
f.close()
f1.close()

Question. Information stored on a storage device with a specific name is called as __________.
a) array
b) dictionary
c) file
d) tuple

Answer : C

Question. Identify the code in line1.
a) Athletics
b) Sports
c) Games
d) None of the above

Answer : A

Question. Which of the follwong is not a valid mode to open a file?
a) ab
b) rw
c) r+
d) w+

Answer : B

 

Question. The function to copy the data into other binary file2
a) DUMP
b) close
c) dump
d) None of these

Answer : C


A binary file “STUDENT.DAT” has structure [admission_number, Name, Percentage]. Write a function countrec() in Python that would read contents of the file “STUDENT.DAT” and display the details of those students whose percentage is above 75. Also display number of students scoring above 75%.
________ pickle # line1
def countrec():
fobj=open(“_____________”,”rb”) # line2
num = 0
try:
while ______: # line3
rec=pickle.load(fobj)
if rec[2]>75:
num = num + 1
print(rec[0],rec[1],rec[2])
except:
fobj.close()
return num

Question. Identify the suitable code for blank space in line 2.
a) STUDENT.DAT
b) STUDENTS.DAT
c) SCHOOL.DAT
d) None of the above

Answer : A

Question. Identify the suitable code for blank space in line-1.
a) import
b) IMPORT
c) Import
d) None of the above

Answer : A

Question. select correct keyword to fill for line-3.
a) True
b) False
c) true
d) TRUE

Answer : A

 

Binary file: basic operations on a binary file: open using file open modes (rb, rb+, wb, wb+, ab, ab+), close a binary file

Question. Which of the following command is used to open a file “c:\path.txt” in read mode only?
a) Fin=open(“c\path.txt”,”r”)
b) fin=open(“c\\path.txt”,”r”)
c) Fin=open(file=”c:\path.txt”,”r+”)
d) fin=open(file=”c\\path.txt”,”r+”)

Answer : B

 

Question. Ms.Anita is unable understand what can be the output of the following code.Help her in getting the output.
Import pickle
L=[20,40,50]
f=open(“list.dat”,‟wb‟)
Pickle.dump(l,f)
Print(“Data added successfully”)
f.close()
f=open(“list.dat”,‟rb‟)
data=pickle.load(f)
f.close()
print(data)
a) Data added successfully
[20,40,50]
b) [20,30,50]
Data added successfully
c) [20,30,50]
d) No output

Answer : A

Question. If a file is opened for reading, which of the following statements is not true?
a) The file must exist on the disk on the specified path
b) If the file exists at the specified path, the file is successfully opened.
c) The file even if at a different location on disk other than the specified path, will get opened
d) Python gives error if the file does not exist at the specified path

Answer : C

Question. Which of the following command is used to open a file “c:\temp.txt” for writing in binary format only?
a) outfile = open(“c:\temp.txt”, “w”)
b) outfile = open(“c:\\temp.txt”, “wb”)
c) outfile = open(“c:\temp.txt”, “w+”)
d) outfile = open(“c:\\temp.txt”, “wb+”)

Answer : B

Question. Which of the following is not a valid mode to open a file.
a) ab
b) rw
c) wb
d) w+

Answer : B

Question. Which of the following is not a correct statement for binary files?
a) Easy for carrying data into buffer
b) Much faster than other file systems
c) Characters translation is not required
d) Every line ends with new line character „\n‟

Answer : D

Question. The readlines() method returns__________
a) a str
b) a list of integers
c) a lit of single characters
d) a list of lines

Answer : D

Question. Which of the following commands can be used to read the entire contents of a file as a string using the file object <tmpfile>?
a) tmpfile.read(n)
b) tmpfile.read()
c) tmpfile.readline()
d) tmpfile.readlines()

Answer : B

Question. Trying to open a binary file using a text editor will show:
a) Garbage values
b) ASCII values
c) Binary character
d) Unicodes

Answer : A

Question. To read 24 characters from a file object infi, we use
a) Infi.read()
b) infi.read(24)
c) Infi.readline()
d) infi.readlines

Answer : B

Question. Which of the following functions do you use to write data in the binary format?
a) Write()
b) output()
c) dump()
d) send()

Answer : C

MCQs for Binary File Computer Science Class 12

Expert teachers of studiestoday have referred to NCERT book for Class 12 Computer Science to develop the Computer Science Class 12 MCQs. If you download MCQs with answers for the above chapter you will get higher and better marks in Class 12 test and exams in the current year as you will be able to have stronger understanding of all concepts. Daily Multiple Choice Questions practice of Computer Science will help students to have stronger understanding of all concepts and also make them expert on all critical topics. After solving the questions given in the MCQs which have been developed as per latest books also refer to the NCERT solutions for Class 12 Computer Science. We have also provided lot of MCQ questions for Class 12 Computer Science so that you can solve questions relating to all topics given in each chapter. After solving these you should also refer to Class 12 Computer Science MCQ Test for the same chapter.

Where can I download latest CBSE MCQs for Class 12 Computer Science Binary File

You can download the CBSE MCQs for Class 12 Computer Science Binary File for latest session from StudiesToday.com

Are the Class 12 Computer Science Binary File MCQs available for the latest session

Yes, the MCQs issued by CBSE for Class 12 Computer Science Binary File have been made available here for latest academic session

Where can I find CBSE Class 12 Computer Science Binary File MCQs online?

You can find CBSE Class 12 Computer Science Binary File MCQs on educational websites like studiestoday.com, online tutoring platforms, and in sample question papers provided on this website.

How can I prepare for Binary File Class 12 MCQs?

To prepare for Binary File MCQs, refer to the concepts links provided by our teachers and download sample papers for free.

Are there any online resources for CBSE Class 12 Computer Science Binary File?

Yes, there are many online resources that we have provided on studiestoday.com available such as practice worksheets, question papers, and online tests for learning MCQs for Class 12 Computer Science Binary File