Grade 12 CS Board Practicals BINARY
Grade 12 CS Board Practicals BINARY
Using user defined functions, write a Menu Based Program to perform the following
operations on a binary file called “EMP.DAT”.
1. Add a new Record. (Retain previous data)
2. Display all Records.
3. Search by EmpNo.
4. Exit
Each record has the following structure:
[empNo, ename, Salary]
import pickle as p
def add () : #function to add new record into the binary file
f = open ( "EMP.DAT" , "ab" )#binary file opened in append mode
empNo = int ( input ( "Enter Employee Number: " ) )
ename = input ( "Enter Employee Name: " )
Salary=float(input("Enter the Salary: "))
rec = [empNo, ename, Salary]
p.dump ( rec , f )
print("Record added into the file successfully")
f.close ( )
#__main__
while True :
print ( "********** ------ **********" )
print ( "\t\t\tMenu" )
print ( "********** ------ **********" )
print ( '''
1.Add Records
2.Modify
3.Display
4.Break''' )
x = int ( input ( "Enter your choice : " ) )
Using user defined functions, write a Menu Based Program to perform the following
operations on a pickled file called “Student.info”.
1. Add a new Record. (Retain previous data)
2. Display all Records.
3. Display Student Name of particular age value entered by the user.
4. Exit
import pickle as p
def add () : #function to add new record into the binary file
f = open ( "Student.info" , "ab" ) #opened in append mode
Studentid = int ( input ( "Enter the student ID: " ) )
stuname = input ( "Enter the student Name: " )
age = int(input("Enter the age of the student: "))
rec = [Studentid, stuname, age]
p.dump ( rec , f )
print("Record added into the file successfully")
f.close ( )
Using user defined functions, write a Menu Based Program to perform the following
operations on a binary file called “EMP.DAT”.
1. Add a new Record. (Retain previous data)
2. Display all Records.
3. Modify Salary of a given employee number.
4. Exit
Each record has the following structure:
[empNo, ename, Salary]
The program should execute as long as the user wants. Also Handle all file-based
exceptions/errors.
import pickle as p
def add () : #function to add new record into the binary file
f = open ( "EMP.DAT" , "ab" ) #binary file opened in append mode
empNo = int ( input ( "Enter Employee Number: " ) )
ename = input ( "Enter Employee Name: " )
Salary= float(input("Enter the salary"))
rec = [empNo, ename, Salary]
p.dump ( rec , f )
print("Record added into the file successfully")
f.close ( )
#__main__
while True :
print ( "********** ------ **********" )
print ( "\t\t\tMenu" )
print ( "********** ------ **********" )
print ( '''
1.Add Records
2.Display
3.Modify
4.Break''' )
x = int ( input ( "Enter your choice : " ) )