Written by students who passed Immediately available after payment Read online or as PDF Wrong document? Swap it for free 4.6 TrustPilot
logo-home
Exam (elaborations)

Computer Science – Binary Files – Exam Based Questions

Rating
-
Sold
-
Pages
7
Grade
A+
Uploaded on
03-09-2024
Written in
2024/2025

Computer Science – Binary Files – Exam Based Questions – 21 Questions – 7 Pages - Question Paper - For Board Examination – Helpful for Students and Teachers

Institution
Course

Content preview

Binary File –Exam based questions

A binary file “student.dat” has structure [rollno, A binary file “emp.dat” has structure [EID,
name, marks]. Ename, designation, salary].
i. Write a user defined function insertRec() to i. Write a user defined function CreateEmp() to
input data for a student and add to student.dat. input data for a record and create a file emp.dat.
ii. Write a function searchRollNo( r ) in Python ii. Write a function display() in Python to display
which accepts the student’s rollno as parameter the detail of all employees whose salary is more
and searches the record in the file “student.dat” than 50000.
and shows the details of student i.e. rollno, name (i)
and marks (if found) otherwise shows the import pickle
message as ‘No record found’. def CreateEmp():
f1=open("emp.dat",'wb')
(i) eid=input("Enter E. Id")
import pickle ename=input("Enter Name")
def insertRec(): designation=input("Enter Designation")
f=open("student.dat","ab") salary=int(input("Enter Salary"))
rollno = int (input("Enter Roll Number : ")) l=[eid,ename,designation,salary]
name=input("Enter Name :") pickle.dump(l,f1)
marks = int(input("Enter Marks : ")) f1.close()
rec = [rollno, name, marks ] (ii)
pickle.dump( rec, f ) import pickle
f.close() def display():
(ii) f2=open("emp.dat","rb")
def searchRollNo( r ): try:
f=open("student.dat","rb") while True:
flag = False rec=pickle.load(f2)
while True: if rec[3]>5000:
try: print(rec[0],rec[1],rec[2],rec[3])
rec=pickle.load(f) except:
if rec[0] == r : f2.close()
print(rec[‘Rollno’])
print(rec[‘Name’])
print(rec[‘Marks])
flag == True
except EOFError:
break
if flag == False:
print(“No record Found”)
f.close()

Write a python program to append a new records Write a python program to search and display the
in a binary file –“student.dat”. The record can record of the student from a binary file
have Rollno, Name and Marks. “Student.dat” containing students records
import pickle (Rollno, Name and Marks). Roll number of the
while True: student to be searched will be entered by the
rollno = int(input("Enter your rollno: ")) user.
name = input("Enter your name: ")

, marks = int(input("enter marks obtained: ")) import pickle
d = [rollno, name, marks] f1 = open("Student.dat", "rb")
f1 = open("Student.dat", "wb") rno = int(input(“Enter the roll no to search: ”))
pickle.dump(d, f1) flag = 0
choice = input("enter more records: y/n") try:
if choice== "N": while True:
break r = pickle.load(f1)
f1.close() if rno == r[0]:
print (rollno, name, marks)
flag = 1
except:
if flag == 0:
print(“Record not found…”)
f1.close()

i. A binary file “emp.DAT” has structure (EID, A binary file named “EMP.dat” has some records
Ename, designation,salary). Write a function to of the structure [EmpNo, EName, Post, Salary]
add more records of employes in existing file (a) Create a binary file “EMP.dat” that stores the
emp.dat. records of employees and display them one by
ii. Write a function Show() in Python that would one.
read detail of employee from file “emp.dat” and (b) Display the records of all those employees
display the details of those employee whose who are getting salaries between 25000 to
designation is “Salesman”. 30000.
(i) (a)
import pickle import pickle
def createemp: f1 = open('emp.dat','rb')
f1=open("emp.dat",'ab') try:
eid=input("Enter E. Id") while True:
ename=input("Enter Name") e = pickle.load(f1)
designation=input("Enter Designation") print(e)
salary=int(input("Enter Salary")) except:
l=[eid,ename,designation,salary] f1.close()
pickle.dump(l,f1)
f1.close() (b)
(ii) import pickle
def display(): f1 = open('emp.dat','rb')
f2=open("emp.dat","rb") try:
try: while True:
while True: e = pickle.load(f1)
rec=pickle.load(f2) if(e[3]>=25000 and e[3]<=30000):
if (rec[2]=='Manager'): print(e)
print(rec[0],rec[1], rec[2],rec[3]) except:
except: f1.close()
break
f2.close()

A binary file “Book.dat” has structure [BookNo,
Book_Name, Author, Price].

Written for

Course

Document information

Uploaded on
September 3, 2024
Number of pages
7
Written in
2024/2025
Type
Exam (elaborations)
Contains
Questions & answers

Subjects

$3.49
Get access to the full document:

Wrong document? Swap it for free Within 14 days of purchase and before downloading, you can choose a different document. You can simply spend the amount again.
Written by students who passed
Immediately available after payment
Read online or as PDF

Get to know the seller
Seller avatar
kbzone

Also available in package deal

Get to know the seller

Seller avatar
kbzone ICSE
Follow You need to be logged in order to follow users or courses
Sold
-
Member since
3 year
Number of followers
0
Documents
284
Last sold
-
Notes On All Subjects

A Store where Notes, Presentations, Questions &amp; Answers, Classnotes, Study mqaterials and Studyguides are available at a very nominal preice. The notes are very useful for both the Students and Teachers.

0.0

0 reviews

5
0
4
0
3
0
2
0
1
0

Recently viewed by you

Why students choose Stuvia

Created by fellow students, verified by reviews

Quality you can trust: written by students who passed their tests and reviewed by others who've used these notes.

Didn't get what you expected? Choose another document

No worries! You can instantly pick a different document that better fits what you're looking for.

Pay as you like, start learning right away

No subscription, no commitments. Pay the way you're used to via credit card and download your PDF document instantly.

Student with book image

“Bought, downloaded, and aced it. It really can be that simple.”

Alisha Student

Working on your references?

Create accurate citations in APA, MLA and Harvard with our free citation generator.

Working on your references?

Frequently asked questions