Full width home advertisement

Grade 10 Revision

Post Page Advertisement [Top]

File Handling Solutions

1.Write a program to input the name of a person, post and salary and store them in a sequential data file “SAL.DAT”

OPEN “SAL.DAT” FOR OUTPUT AS #1
CLS
DO
INPUT “ENTER THE NAME ” ; N$
INPUT “ENTER THE POST” ; P$
INPUT “ENTER THE SALARY” ; S$
WRITE#1 , N$,P$,S$
INPUT “DO YOU WANT TO STORE MORE RECORDS ? (Y/N)” ; CH$
LOOP WHILE UCASE(CH$)=”Y”
CLOSE#1
END

2.Write a program to add some data in an existing sequential data file “emp.dat” having fields name ,post and salary

OPEN “EMP.DAT” FOR APPEND AS #1
CLS
DO
INPUT “ENTER NAME” ; N$
INPUT “ENTER POST” ;P$
INPUT “ENTER SALARY” ; S
WRITE #1, N$,P$,S
INPUT “ADD MORE DATA ? (Y/N)” ; C$
CH$=UCASE$(C$)
LOOP WHILE UCASE(CH$)=”Y”
CLOSE#1
END

3.Write a program to read all the data from the data file named “sal.dat” having fields name , post and salary and display only those records where the salary is equal or greater than 5000 and post is “manager”

OPEN “SAL.DAT” FOR INPUT AS#1
CLS
WHILE NOT EOF(1)
INPUT #1, N$,P$,S
IF S>=5000 AND P$=”MANAGER” THEN
PRINT N$,P$,S
END IF
WEND
CLOSE#1
END


4.Write a program to display all the records from “rec.dat” also count how many records have been displayed.

OPEN “REC.DAT” FOR INPUT AS #1
WHILE NOT EOF(1)
LINE INPUT #1,A$
C=C+1
WEND
CLOSE#1
PRINT “NO. OF RECORDS DISPLAYED=”;C
END


5. Write a program in QBASIC to open a sequential data file “EMP.DAT”, which contains employees records: Name, address and phone number and display all the records as well as total number of records stored in the file.

OPEN “EMP.DAT” FOR INPUT AS #1
CLS
WHILE NOT EOF(1)
INPUT #1,N$,A$,P#
C=C+1
PRINT N$,A$,P#
WEND
PRINT “TOTAL NUMBER OF RECORDS=”;C
CLOSE#1
END


6. Write a program to store records regarding the information of Book number, Book’s name and Writer’s name in a sequential data file called “Library.dat”.

OPEN “Library.dat” FOR OUTPUT AS #1
DO
CLS
INPUT “ENTER BOOK’S NUMBER”;BN
INPUT “ENTER BOOK’S NAME”;BN$
WRITE #1, BN, BN$
INPUT “DO YOU WANT TO CONTINUE(Y/N)”;CH$
LOOP WHILE UCASE$(CH$)=”Y”
CLOSE#1
END

7. Write a program to create a sequential data file “Employee.Dat” to store employees’ name, address, age, gender and salary.

OPEN “Employee.dat” FOR OUTPUT AS #1
DO
CLS
INPUT “ENTER EMPLOYEE’S NAME”;N$
INPUT “ENTER EMPLOYEE’S ADDRESS”;A$
INPUT “ENTER AGE”;A
INPUT “ENTER GENDER”;G$
INPUT “ENTER SALARY”;S
WRITE #1, N$,A$,A,G$,S
INPUT “DO YOU WANT TO CONTINUE(Y/N)”;CH$
LOOP WHILE UCASE$(CH$)=”Y”
CLOSE#1
END


1 comment:

Bottom Ad [Post Page]