File Handling 2
File Handling 2
[SEE 2074]
FOR I = 1 TO 5
NEXT I
CLOSE #1
END
2. A sequential data file called “student.dat” contains same 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]
DO
CLS
CLOSE #1
END
3. A sequential data file “RECORD.DAT” and store Name, Address and Salary of employees of an office.
WAP to add some more records in the data file “RECODR.DAT”. The program should terminate with user
choice.
DO
CLS
CLOSE #1
END
4. Create a data file to store the records of few employees having Name, Address, Post, Gender and
Salary fields. [SEE 2073]
TOP:
CLS
CLOSE #1
END
5. Create a sequential data file ’Price.dat’ to store item name, quantity and Rate also calculate total
amount(total=Quantity X Rate).Program should terminate according to the user’s choice.
TOP:
CLS
CLOSE #1
END
6. Create a sequential data file’post.dat’ to store name and marks of any three subjects also calculate
total and percentages only for 15 students.
FOR I = 1 TO 15
T=A+B+C
P=T/3
NEXT I
CLOSE #1
END
7. Store SIDNO, name, address and Telephone number of five students and display the records on
monitor in sequential data file “STDINFO”
FOR I = 1 TO 5
CLS
NEXT I
CLOSE #1
CLS
FOR I = 1 TO 5
NEXT I
CLOSE #1
END
8. A sequential data file “Address.inf” contains serial no, name, address, telephone and email_id.WAP to
record as many records as the user wants. The serial number should be generated automatically like
5001,5003,5005.
DO
CLS
C = 5001
C=C+2
CLOSE #1
END
9. A Sequential data file called "SEE.DAT" has stored data under the field heading Symbol No., Name,
English, Nepali, and Computer. Write a program to display all the information of those students whose
marks in Computer is more than 80.
CLS
WEND
CLOSE #1
END
10. A sequential data file “STD.TXT” contains name and marks in three different subjects of some
students. Write a program to display only fail student’s records assuming pass marks 40.
CLS
WEND
CLOSE #1
END
11.Write a program which reads records from the file ”Result.DAT” having the fields name, and marks of
three different subjects and display only those records whose percentage is greater than 60 and less
than 80. Also count the total number of records presenting in that data files.
CLS
A=A+1
T=C+D+E
P=T/3
WEND
CLOSE #1
END
12. Write a program to read all the records from the data file “STUDENT.TXT” and display all the records
where the fields name are unknown.
CLS
PRINT A$
WEND
CLOSE #1
END
13. A data file "pabson.txt" contains the records composed of the fields like school, principal, address,
contact. Write a program in Qbasic to display records of the schools located in either Kathmandu or
Palpa
CLS
WHILE NOT EOF (1)
WEND
CLOSE #1
END
14. A data file “INFO.DAT” has numerous records in it with name, address age, and telephone numbers
in it. Write a program to read all the records and print those with address “NEPAL” and age >15
CLS
WEND
CLOSE #1
END
15. A sequential data file called 'ADDRESS.DAT' contains NAME, AGE, CITY and TELEPHONE fields. Write
a program to display all the contents of that data file.
CLS
WEND
CLOSE #1
END
16. A data file “lib.txt” consists of book’s name, author’s name and price of books. Write a program to
count and display the total number of records present in the file.
CLS
D=D+1
WEND
CLOSE #1
END
17. 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.
CLS
D=D+1
WEND
CLOSE #1
END
18. A sequential data file named “nabil.txt” contains record of clients of a bank including depositor’s
name, deposited amount, time and rate of interest. Wap to display detail of all depositors including
simple interest.
CLS
I=P*T*R/100
PRINT A$, B$, C, I
WEND
CLOSE #1
END
19. A sequential data file “SALARY.DAT” contains the information, Employee-Code, Employee-Name,
Post, Basic-Salary. Write a program to display those records whose Basic-salary is between 10000 to
15000 and Post is ‘OFFICER’.
CLS
IF UCASE$(P$) = “OFFICER” AND S >= 10000 AND S>= 15000 THEN PRINT A$, B$, C, D
WEND
CLOSE #1
END
20. A data file name “EMP.DAT”, contains number of records having fields name, post and salary. Write
a program to count total number of “Manager” in the data file. (hint: Manager is a post)
CLS
WEND
CLOSE #1
END
21. 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).
OPEN "EMP.DAT" FOR INPUT AS #1
CLS
T = 15 / 100 * S
WEND
CLOSE #1
END
22. A data file “Salary.Dat” contains the information of employee regarding their name, post and salary.
Write a program to display all the information of employee whose salary is greater than 15000 and less
than 40000.
CLS
WEND
CLOSE #1
END
23. Write a program that reads the ”INFO.DAT” file that has several record such as name, address,
gender, post, and salary .The program display those record whose sex is male and salary more than
10,000 and also the program counts the total number of records in that file.
CLS
C=C+1
IF UCASE$(G$)=”M” AND S >= 10000 THEN PRINT N$, A$, G$, P$, S
WEND
END
24. A sequential data file’post.dat’ has few records related to name, address, salary.WAP to display the
records whose address begins with ‘S’ or ‘D’
CLS
A$ = UCASE$(LEFT$(N$,1))
WEND
CLOSE #1
END
25. Write a program to open a data file “record.dat” that contains name, address, date of birth, email
and telephone number of some employees. Now display all those records whose date of birth is in
current month.
CLS
b$ = LEFT$(DATE$, 2)
c = VAL(b$)
e$ = LEFT$(d$, 2)
f = VAL(e$)
WEND
CLOSE #1
END
26. A sequential data file “Record.dat” has few records related to name, address, post and
DOB(mm/dd/yyyy). WAP to display the records of all those who were born between 1971 to 1999.
CLS
d$ = RIGHT$(d$, 4)
c = VAL(b$)
WEND
CLOSE #1
END
27. Write a Qbasic program that read the "EMP.DAT" file with Name, Address, Post and Salary columns
from E: drive that has 500 records of employees and displays only its last 50 records.
CLS
FOR i = 1 TO 500
IF i >= 450 AND i <= 500 THEN PRINT n$, a$, p$, s
NEXT i
CLOSE #1
END
28. A sequential data file has 100 records having field name, class and roll number. Write a program to
display from 50th to 60th records.
D=D+1
WEND
CLOSE #1
END
29. Write a program to display the first 10 records from a file named “resource.dat” having fields name,
phone and email.
CLS
FOR I = 1 TO 10
NEXT I
CLOSE #1
END
30. A data file named “EMP.DAT” contains some records with the fields Code, Name, Post and Salary.
Write a program to print odd position records of the data file.
CLS
D=D+1
WEND
CLOSE #1
END
31. A sequential data file named “abc.dat” has several records having fields name, roll and class. Write a
program to copy all the records of class 10 into a newly created file new.dat.
CLS
WEND
CLOSE #1, #2
END
32. A data file named “record.dat” contains name, age and salary for n number of persons. Write a
program to input a name to search data from a data file. If the data is not found, then display the
message “Data not found in the list”.
CLS
INPUT “Enter name to be searched”; S$
FLAG=0
IF UCASE$(S$)=UCASE$(N$) THEN
FLAG=1
END IF
WEND
CLOSE #1
END
33. A sequential data file 'Student.dat' contains registration number, student name, address and date of
birth of some students. Write a program that asks a user to input a registration number and displays the
record of the particular registration if present.
OPEN “STUDENT.DAT” FOR INPUT AS #1
CLS
FLAG=0
IF S = R THEN
FLAG=1
END IF
WEND
CLOSE #1
END
34. WAP that asks a post of the employee and displays his/her records from the sequential data file
“XYZ.REC” having fields Name, Post, Dept and Salary.
CLS
FLAG=0
IF UCASE$(S$)=UCASE$(P$) THEN
FLAG=1
END IF
WEND
CLOSE #1
END
35. Delete some records from “neps.dat” file where computer ask user to enter the record, which is to
be deleted. (Fields are name, address, and telephone number)
CLS
ELSE
END IF
WEND
CLOSE #1, #2
KILL “NEPS.DAT”
END
36. A sequential data file “marks.dat” contains information such as student’s name, marks obtained in
math, science and computer. Write a program that increase the marks of computer by 10 of those
student who secured less than 40
CLS
IF C > 40 THEN
ELSE
C = C + 10
END IF
WEND
CLOSE
KILL "D:\PATIENT.DAT"
END
37. A sequential data file “RECORD.DAT” contains different records under fields: name rollno., name,
address and percentage. Write a program to edit a record and display both edited and unedited records
on the screen to compare them side by side.
CLS
FLAG = 0
IF E <> R THEN
ELSE
FLAG = 1
END IF
WEND
IF FLAG = 0 THEN
ELSE
PRINT "---------------"
END IF
CLOSE
KILL "D:\SALARY.DAT"
END
Created By Amit
1. Write a program to store Roll no., Name, Class and Address of any five students. [SEE 2074]
NEXT I
CLOSE #1
END
2. A sequential data file called “student.dat” contains same 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]
DO
CLS
CLOSE #1
END
3. A sequential data file “RECORD.DAT” and store Name, Address and Salary of employees of an office.
WAP to add some more records in the data file “RECODR.DAT”. The program should terminate with user
choice.
DO
CLS
CLOSE #1
END
4. Create a data file to store the records of few employees having Name, Address, Post, Gender and
Salary fields. [SEE 2073]
TOP:
CLS
CLOSE #1
END
5. Create a sequential data file ’Price.dat’ to store item name, quantity and Rate also calculate total
amount(total=Quantity X Rate).Program should terminate according to the user’s choice.
TOP:
CLS
T=Q*R
CLOSE #1
END
6. Create a sequential data file’post.dat’ to store name and marks of any three subjects also calculate
total and percentages only for 15 students.
FOR I = 1 TO 15
T=A+B+C
P=T/3
NEXT I
CLOSE #1
END
7. Store SIDNO, name, address and Telephone number of five students and display the records on
monitor in sequential data file “STDINFO”
FOR I = 1 TO 5
CLS
NEXT I
CLOSE #1
CLS
FOR I = 1 TO 5
NEXT I
CLOSE #1
END
8. A sequential data file “Address.inf” contains serial no, name, address, telephone and email_id.WAP to
record as many records as the user wants. The serial number should be generated automatically like
5001,5003,5005.
DO
CLS
C = 5001
C=C+2
CLOSE #1
END
9. A Sequential data file called "SEE.DAT" has stored data under the field heading Symbol No., Name,
English, Nepali, and Computer. Write a program to display all the information of those students whose
marks in Computer is more than 80.
CLS
CLOSE #1
END
10. A sequential data file “STD.TXT” contains name and marks in three different subjects of some
students. Write a program to display only fail student’s records assuming pass marks 40.
CLS
WEND
CLOSE #1
END
11.Write a program which reads records from the file ”Result.DAT” having the fields name, and marks of
three different subjects and display only those records whose percentage is greater than 60 and less
than 80. Also count the total number of records presenting in that data files.
CLS
A=A+1
T=C+D+E
P=T/3
WEND
CLOSE #1
END
12. Write a program to read all the records from the data file “STUDENT.TXT” and display all the records
where the fields name are unknown.
CLS
PRINT A$
WEND
CLOSE #1
END
13. A data file "pabson.txt" contains the records composed of the fields like school, principal, address,
contact. Write a program in Qbasic to display records of the schools located in either Kathmandu or
Palpa
CLS
WEND
CLOSE #1
END
14. A data file “INFO.DAT” has numerous records in it with name, address age, and telephone numbers
in it. Write a program to read all the records and print those with address “NEPAL” and age >15
CLS
WEND
CLOSE #1
END
15. A sequential data file called 'ADDRESS.DAT' contains NAME, AGE, CITY and TELEPHONE fields. Write
a program to display all the contents of that data file.
CLS
WEND
CLOSE #1
END
16. A data file “lib.txt” consists of book’s name, author’s name and price of books. Write a program to
count and display the total number of records present in the file.
D=D+1
WEND
CLOSE #1
END
17. 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.
CLS
D=D+1
WEND
CLOSE #1
END
18. A sequential data file named “nabil.txt” contains record of clients of a bank including depositor’s
name, deposited amount, time and rate of interest. Wap to display detail of all depositors including
simple interest.
CLS
I=P*T*R/100
WEND
CLOSE #1
END
19. A sequential data file “SALARY.DAT” contains the information, Employee-Code, Employee-Name,
Post, Basic-Salary. Write a program to display those records whose Basic-salary is between 10000 to
15000 and Post is ‘OFFICER’.
CLS
IF UCASE$(P$) = “OFFICER” AND S >= 10000 AND S>= 15000 THEN PRINT A$, B$, C, D
WEND
CLOSE #1
END
20. A data file name “EMP.DAT”, contains number of records having fields name, post and salary. Write
a program to count total number of “Manager” in the data file. (hint: Manager is a post)
CLS
WEND
CLOSE #1
END
21. 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).
CLS
WHILE NOT EOF (1)
T = 15 / 100 * S
WEND
CLOSE #1
END
22. A data file “Salary.Dat” contains the information of employee regarding their name, post and salary.
Write a program to display all the information of employee whose salary is greater than 15000 and less
than 40000.
CLS
CLOSE #1
END
23. Write a program that reads the ”INFO.DAT” file that has several record such as name, address,
gender, post, and salary .The program display those record whose sex is male and salary more than
10,000 and also the program counts the total number of records in that file.
CLS
C=C+1
IF UCASE$(G$)=”M” AND S >= 10000 THEN PRINT N$, A$, G$, P$, S
WEND
CLOSE #1
END
24. A sequential data file’post.dat’ has few records related to name, address, salary.WAP to display the
records whose address begins with ‘S’ or ‘D’
CLS
A$ = UCASE$(LEFT$(N$,1))
WEND
CLOSE #1
END
25. Write a program to open a data file “record.dat” that contains name, address, date of birth, email
and telephone number of some employees. Now display all those records whose date of birth is in
current month.
OPEN "birth.dat" FOR INPUT AS #1
CLS
b$ = LEFT$(DATE$, 2)
c = VAL(b$)
e$ = LEFT$(d$, 2)
f = VAL(e$)
WEND
CLOSE #1
END
26. A sequential data file “Record.dat” has few records related to name, address, post and
DOB(mm/dd/yyyy). WAP to display the records of all those who were born between 1971 to 1999.
CLS
d$ = RIGHT$(d$, 4)
c = VAL(b$)
WEND
CLOSE #1
END
27. Write a Qbasic program that read the "EMP.DAT" file with Name, Address, Post and Salary columns
from E: drive that has 500 records of employees and displays only its last 50 records.
OPEN "E:\EMP.DAT" FOR INPUT AS #1
CLS
FOR i = 1 TO 500
IF i >= 450 AND i <= 500 THEN PRINT n$, a$, p$, s
NEXT i
CLOSE #1
END
28. A sequential data file has 100 records having field name, class and roll number. Write a program to
display from 50th to 60th records.
CLS
D=D+1
WEND
CLOSE #1
END
29. Write a program to display the first 10 records from a file named “resource.dat” having fields name,
phone and email.
CLS
FOR I = 1 TO 10
PRINT N$, C, R
NEXT I
CLOSE #1
END
30. A data file named “EMP.DAT” contains some records with the fields Code, Name, Post and Salary.
Write a program to print odd position records of the data file.
CLS
D=D+1
WEND
CLOSE #1
END
31. A sequential data file named “abc.dat” has several records having fields name, roll and class. Write a
program to copy all the records of class 10 into a newly created file new.dat.
CLS
WEND
CLOSE #1, #2
END
32. A data file named “record.dat” contains name, age and salary for n number of persons. Write a
program to input a name to search data from a data file. If the data is not found, then display the
message “Data not found in the list”.
CLS
IF UCASE$(S$)=UCASE$(N$) THEN
FLAG=1
END IF
WEND
CLOSE #1
END
33. A sequential data file 'Student.dat' contains registration number, student name, address and date of
birth of some students. Write a program that asks a user to input a registration number and displays the
record of the particular registration if present.
FLAG=0
IF S = R THEN
FLAG=1
END IF
WEND
CLOSE #1
END
34. WAP that asks a post of the employee and displays his/her records from the sequential data file
“XYZ.REC” having fields Name, Post, Dept and Salary.
CLS
FLAG=0
IF UCASE$(S$)=UCASE$(P$) THEN
FLAG=1
END IF
WEND
CLOSE #1
END
35. Delete some records from “neps.dat” file where computer ask user to enter the record, which is to
be deleted. (Fields are name, address, and telephone number)
CLS
ELSE
END IF
WEND
CLOSE #1, #2
KILL “NEPS.DAT”
END
36. A sequential data file “marks.dat” contains information such as student’s name, marks obtained in
math, science and computer. Write a program that increase the marks of computer by 10 of those
student who secured less than 40
IF C > 40 THEN
ELSE
C = C + 10
END IF
WEND
CLOSE
KILL "D:\PATIENT.DAT"
END
37. A sequential data file “RECORD.DAT” contains different records under fields: name rollno., name,
address and percentage. Write a program to edit a record and display both edited and unedited records
on the screen to compare them side by side.
CLS
FLAG = 0
IF E <> R THEN
ELSE
FLAG = 1
END IF
WEND
IF FLAG = 0 THEN
ELSE
PRINT "---------------"
END IF
CLOSE
KILL "D:\SALARY.DAT"
END