Sei sulla pagina 1di 2

Worksheet-Binary Files

1) Given a class TRAIN as follows,


class TRAIN:
def __init__(self):
self.trainno=0
self.trainname=''
self.start=''
self.dest=''
def get(self): //get all details
def display(self): // display all details
Write a function to:
i)
To search and display details of trains starting from MUMBAI
ii)
To search and display details of trains whose destination in DELHI
2) Write a function in Python to read and display the detail of all the users whose status is A
(i.e. Active) from a binary file USER.DAT. Assuming the binary file USER.DAT is
containing objects of class USER, which is defined as follows :
class USER
def __init__(self):
self. Uid=0 //User Id
self.Uname = //User Name
self.Status=A // User Type : A Active I Inactive
def Register(); //Function to enter the content
def show(); //Function to display all data members
def Getstatus ()
3) Write a function in Python which will increase the qty of a particular type of item from the
file stock.dat. Assuming that the binary file is containing the records of following class
Products (id, name, type, qty). Accept the item type from user whose qty has to be
increased .
4) Write a function in Python to search for a camera from a binary file "CAMERA.DAT"
containing the objects of class" CAMERA (ModelNo, MegaPixel, Zoom, Details). The user
should enter the Model No and the function should search display the details of the
camera.
5) Following is the structure Vehicle(Vehicle_Code , Vehicle_Name , cost) of each record in a
data file named VEHICLE.DAT.
Write a function in Python to update the tile with a new value of cost for a particular
Vehicle. The value of Vehicle_Code and cost are read during the execution of the program.

6)

Write a function in Python to search for BookNo from a binary file BOOK.DAT, assuming the
binary file is contained the objects of the class BOOK with attributes Bno and Title:

Write another function in Python to modify a book, where the object is sent to the function
as an argument
7)

Write a function to search and display all flights whose destination is Mumbai from the binary file
Flights.dat. Assuming the binary file is containing the objects of the following class.
class Flight:
def __init__(self):
self.fno=570
self.To=Mumbai
self.From=Dubai
def enter(self):
self.no,self.To,self.From=raw_input(Enter no,To and From:)
def display(self):
print self.no,self.To,self.From

8) Given a binary file PHONE.DAT, containing records of the following structure type
class Phonlist (Name, Address,AreaCode, PhoneNo)
Write a function TRANSFER ( ) in Python that would copy all those records which are having
AreaCode as DEL from PHONE.DAT to PHONBACK.DAT.
9) Assuming the class ANTIQUE as declared below, write a function in python to read the

objects of ANTIQUE from binary file ANTIQUE.DAT and display those antique items, which
are priced between 10000 and 15000.
class ANTIQUE:
def __init__(self):
self.Ano=1
self.Aname=
self.price=0.0
10) Write a function in Python to read and display the records of candidate ( Id, votes) of those
candidates who have scored more than 1000 votes from a binary file election.dat.
Assuming that this binary file contains records/objects of class Candidate. Note: If none of
the candidates scored more than 1000, display appropriate message.

Potrebbero piacerti anche