file handling जसै जान्नपर्ने अन्यथा LAB मा बस्न नपाइने
1. [SEE 2074]
Q: Write a program to store Roll no., Name, Class and Address of any five students.
OPEN "student.dat" FOR OUTPUT AS #1
FOR i = 1 TO 5
INPUT "Enter Roll No:"; R
INPUT "Enter Name:"; N$
INPUT "Enter Class:"; C$
INPUT "Enter Address:"; A$
WRITE #1, R, N$, C$, A$
NEXT i
CLOSE #1
2. [SLC 2068]
Q: A sequential data file called “student.dat” contains records under the fields name, english, nepali and computer. Write a program to add some more records in the same sequential data file.
OPEN "student.dat" FOR APPEND AS #1
DO
INPUT "Enter Name:"; N$
INPUT "Enter English:"; E
INPUT "Enter Nepali:"; Nep
INPUT "Enter Computer:"; C
WRITE #1, N$, E, Nep, C
INPUT "Do you want to continue (Y/N)?"; ans$
LOOP WHILE UCASE$(ans$) = "Y"
CLOSE #1
3.
Q: A sequential data file “RECORD.DAT” stores Name, Address and Salary of employees. WAP to add some more records in the data file “RECORD.DAT”. The program should terminate with user choice.
OPEN "RECORD.DAT" FOR APPEND AS #1
DO
INPUT "Enter Name:"; N$
INPUT "Enter Address:"; A$
INPUT "Enter Salary:"; S
WRITE #1, N$, A$, S
INPUT "Do you want to continue (Y/N)?"; ans$
LOOP WHILE UCASE$(ans$) = "Y"
CLOSE #1
4. [SEE 2073]
Q: Create a data file to store the records of few employees having Name, Address, Post, Gender and Salary fields.
OPEN "employee.dat" FOR OUTPUT AS #1
FOR i = 1 TO 5
INPUT "Enter Name:"; N$
INPUT "Enter Address:"; A$
INPUT "Enter Post:"; P$
INPUT "Enter Gender:"; G$
INPUT "Enter Salary:"; S
WRITE #1, N$, A$, P$, G$, S
NEXT i
CLOSE #1
5.
Q: Create a sequential data file ’Price.dat’ to store item name, quantity and Rate also calculate total amount (total = Quantity × Rate). Program should terminate according to the user’s choice.
OPEN "Price.dat" FOR APPEND AS #1
DO
INPUT "Enter Item Name:"; Item$
INPUT "Enter Quantity:"; Q
INPUT "Enter Rate:"; R
T = Q * R
WRITE #1, Item$, Q, R, T
INPUT "Do you want to continue (Y/N)?"; ans$
LOOP WHILE UCASE$(ans$) = "Y"
CLOSE #1
6.
Q: 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.
OPEN "post.dat" FOR OUTPUT AS #1
FOR i = 1 TO 15
INPUT "Enter Name:"; N$
INPUT "Enter Marks in English:"; E
INPUT "Enter Marks in Nepali:"; Nep
INPUT "Enter Marks in Computer:"; C
Total = E + Nep + C
Percent = Total / 3
WRITE #1, N$, E, Nep, C, Total, Percent
NEXT i
CLOSE #1
7.
Q: Store SIDNO, name, address and Telephone number of five students and display the records on monitor in sequential data file “STDINFO”.
OPEN "STDINFO" FOR OUTPUT AS #1
FOR i = 1 TO 5
INPUT "Enter SIDNO:"; SID
INPUT "Enter Name:"; N$
INPUT "Enter Address:"; A$
INPUT "Enter Telephone:"; T$
WRITE #1, SID, N$, A$, T$
NEXT i
CLOSE #1
OPEN "STDINFO" FOR INPUT AS #1
WHILE NOT EOF(1)
INPUT #1, SID, N$, A$, T$
PRINT SID, N$, A$, T$
WEND
CLOSE #1
8.
Q: 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.
OPEN "Address.inf" FOR APPEND AS #1
Sno = 5001
DO
INPUT "Enter Name:"; N$
INPUT "Enter Address:"; A$
INPUT "Enter Telephone:"; T$
INPUT "Enter Email:"; E$
WRITE #1, Sno, N$, A$, T$, E$
Sno = Sno + 2
INPUT "Do you want to continue (Y/N)?"; ans$
LOOP WHILE UCASE$(ans$) = "Y"
CLOSE #1
9.
Q: A Sequential data file called "SEE.DAT" has stored data under 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.
OPEN "SEE.DAT" FOR INPUT AS #1
WHILE NOT EOF(1)
INPUT #1, Sym, N$, Eng, Nep, Comp
IF Comp > 80 THEN
PRINT Sym, N$, Eng, Nep, Comp
END IF
WEND
CLOSE #1
10.
Q: 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.
OPEN "STD.TXT" FOR INPUT AS #1
WHILE NOT EOF(1)
INPUT #1, N$, M1, M2, M3
IF M1 < 40 OR M2 < 40 OR M3 < 40 THEN
PRINT N$, M1, M2, M3
END IF
WEND
CLOSE #1
11.
Q: 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 present in that data file.
OPEN "Result.DAT" FOR INPUT AS #1
count = 0
WHILE NOT EOF(1)
INPUT #1, N$, M1, M2, M3
Total = M1 + M2 + M3
Percent = Total / 3
count = count + 1
IF Percent > 60 AND Percent < 80 THEN
PRINT N$, M1, M2, M3, Percent
END IF
WEND
PRINT "Total Records = "; count
CLOSE #1
12.
Q: 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.
OPEN "STUDENT.TXT" FOR INPUT AS #1
WHILE NOT EOF(1)
INPUT #1, N$, Class$, Roll
IF UCASE$(N$) = "UNKNOWN" THEN
PRINT N$, Class$, Roll
END IF
WEND
CLOSE #1
13.
Q: 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.
OPEN "pabson.txt" FOR INPUT AS #1
WHILE NOT EOF(1)
INPUT #1, School$, Principal$, Address$, Contact$
IF UCASE$(Address$) = "KATHMANDU" OR UCASE$(Address$) = "PALPA" THEN
PRINT School$, Principal$, Address$, Contact$
END IF
WEND
CLOSE #1
14.
Q: A data file “INFO.DAT” has numerous records with name, address, age, and telephone numbers. Write a program to read all the records and print those with address “NEPAL” and age >15.
OPEN "INFO.DAT" FOR INPUT AS #1
WHILE NOT EOF(1)
INPUT #1, N$, Address$, Age, Tel$
IF UCASE$(Address$) = "NEPAL" AND Age > 15 THEN
PRINT N$, Address$, Age, Tel$
END IF
WEND
CLOSE #1
15.
Q: 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.
OPEN "ADDRESS.DAT" FOR INPUT AS #1
WHILE NOT EOF(1)
INPUT #1, N$, Age, City$, Tel$
PRINT N$, Age, City$, Tel$
WEND
CLOSE #1
Comments
Post a Comment