QBASIC FILE HANDLING COMPUTER SCIENCE SLC 2067, SLC 2068, SLC 2069, SLC 2070
1. A sequential data file “EMP.DAT” contains name, post and salary fields of information about employees. Write a program to display all the information of employees along with tax amount (also tax is 15% of salary). [SLC 2067]
OPEN “EMP.DAT” FOR INPUT AS #1
CLS
WHILE NOT EOF(1)
INPUT #1,N$,P$,S
T=15/100*S
PRINT N$,P$,S,T
WEND
CLOSE#1
END
2. A sequential data file called “student.dat” contains some records under the field’s name, English, Nepali and Computer. Write a program to add some more records in the same sequential data file. [SLC 2068]
OPEN “student.dat” FOR APPEND AS #1
DO
CLS
INPUT “ENTER NAME”;N$
INPUT “ENTER MARKS IN ENGLISH”;E
INPUT “ENTER MARKS IN NEPALI”;N
INPUT “ENTER COMPUTER”;C
WRITE #1, N$, E, N, C
INPUT “DO YOU WANT TO CONTINUE(Y/N)”;CH$
LOOP WHILE UCASE$(CH$)=”Y”
CLOSE#1
END
3. Write a program to create a data file ‘teldir.dat’ to store Name, Address and Telephone number of employees according to the need of the user. [SLC 2069]
OPEN “teldir.dat” FOR OUTPUT AS #1
DO
CLS
INPUT “ENTER NAME”;N$
INPUT “ENTER ADDRESS”;A$
INPUT “ENTER TELEPHONE”;T
WRITE #1, N$, A$, T
INPUT “DO YOU WANT TO CONTINUE(Y/N)”;CH$
LOOP WHILE UCASE$(CH$)=”Y”
CLOSE#1
END
4. A sequential data file called “Marks.dat” contains Name, English, Nepali, Maths and Science Fields. Write a program to display all the contents of that data file. [SLC 2070]
OPEN “Marks.dat” FOR INPUT AS #1
CLS
WHILE NOT EOF(1)
INPUT#1, N$, E, N, M, S
PRINT N$, E, N, M, S
WEND
CLOSE#1
END
Comments