File Handling Model Questions Solution (SEE Computer)

File Handling

Programs of file handling

A sequential data file called “Record.dat” has stored data under the field heading Roll No, Name, Gender, English, Nepali, Maths and Computer. WAP to display all the information of those students whose gender is “F” and obtained marks in computer is more than 90.
OPEN "Record.dat" FOR INPUT AS #1
CLS
WHILE NOT EOF(1)
INPUT #1,R,Name$,G$,E,N,M,C
IF (UCASE$(G$))="F" AND C>90 THEN
PRINT R, Name$, G$, E, M,C
END IF
WEND
CLOSE #1
END
A sequential data file called “class.dat” has several records with fields students name , roll , address and class. WAP that reads all the records and display only those records whose class is 10.
OPEN "class.dat" FOR INPUT AS #1
CLS
WHILE NOT EOF(1)
INPUT #1, N$,R,Ad$,C
IF C=10 THEN
PRINT N$,R,Ad$,C
END IF
WEND
CLOSE #1
END
A sequential data file “class.dat” has several records with fields student’s name, roll no, address, and class. WAP that reads all the records and display only those records whose address is “Pokhara”.
OPEN "class.dat" FOR INPUT AS #1
CLS
WHILE NOT EOF(1)
INPUT #1,Name$,R,Ad$,C
IF (UCASE$(Ad$))="Pokhara" THEN
PRINT Name$,R,Ad$,C
END IF
WEND
CLOSE #1
END
A sequential data file “class.dat” has several records with fields student’s name , roll no, address, fee and class. WAP that reads all the records and display only those records whose fee is greater than 5000.
OPEN "class.dat" FOR INPUT AS #1
CLS
WHILE NOT EOF(1)
INPUT #1,Name$,R,Ad$,fee,C
IF fee>5000 THEN
PRINT Name$,R,Ad$,fee,C
END IF
WEND
CLOSE #1
END
A sequential data file “student.dat” consists of book’s name, author’s name and price and book. WAP to count and display the total number of records present in the file.
OPEN "student.dat" FOR INPUT AS #1
CLS
WHILE NOT EOF(1)
INPUT #1,bname$,aname$,price
D=D+1
WEND
PRINT "Total number of records in a file is:",D
CLOSE #1
END
A sequential data file called “Record.txt” has stored data under the file heading Roll no, Name , Gender, English, Nepali, Maths and Computer. WAP to display all the female students who pass in all subjects.[Note: Assume pass marks in each subjects is 40.]
OPEN "Record.txt" FOR INPUT AS #1
CLS
WHILE NOT EOF(1)
INPUT #1,R,Name$,Gender$,E,N,M,C
IF (UCASE$(Gender$))="F" AND E>=40 AND N>=40 AND M>=40 AND C>=40 THEN
PRINT R,Name$,Gender$,E,N,M,C
END IF
WEND
CLOSE #1
END
WAP to create a sequential data file named “employee.dat” to store Name, Post, Address and Salary for the number of employees. The program should be terminated on user’s choice.
OPEN "employee.dat" FOR OUTPUT AS #1
CLS
DO
INPUT "Enter name, post, address and salary";name$,post$,address$,salary
WRITE #1,name$,post$,address$,salary
INPUT" Do you want to add more records?(Y/N)",ch$
LOOP WHILE(UCASE$(ch$))="Y"
CLOSE #1
END
A sequential data file “emp.dat” contains name, post and salary fields of the information about employees. WAP to display all the information of employees along with tax amount.[ Tax is 15% of Salary]
OPEN" emp.dat " FOR INPUT AS #1
CLS
WHILE NOT EOF(1)
INPUT #1, name$,post$, salary
T=salary*(15/100)
PRINT name$,post$,salary,T
WEND
CLOSE #1
END
WAP to store Roll no, Name, Class and Address of any five students.
OPEN "std.dat" FOR OUTPUT AS #1
CLS
FOR I=1 To 5
INPUT" Enter Roll, Name,Address of the students";R,Name$,Address$
WRITE #1,R,Name$,Address$
NEXT I
CLOSE #1
END
A sequential data file called “student.dat” contains some records under the field’s Name, English, Nepali and Computer. WAP to add some more record in the same sequential data file.
OPEN "student.dat" FOR APPEND AS #1
CLS
DO
INPUT "Enter name and marks in English, Nepali and Computer";name$,E,N,C
WRITE #1,name$,E,N,C
INPUT" Do you want to add more records?(Y/N)";ch$
LOOP WHILE(UCASE$(ch$))="Y" 
CLOSE #1
END
Facebook Comments Box

Read This

Scroll to Top