File Handling Important questions and Solutions



                                            Jaya Ganeshya

1.    A sequential data file “std.dat” contains Name, class, Roll No. and Address of some students. Write a program to read records and display only those students record whose name starts with alphabet “A” of “a”.
2.    Create a sequential data file “std.dat” to store Name and Mark obtained in English, Math and Science subjects for a few students.
3.    A sequential data file called “MARKS.DAT” contains Roll no. Name, English,Nepali and Maths fields. Write a program to display all the contains of the data file.
4.    Write a program to create a sequential data file “Employee.Dat” to store employees’ Name, Address, Age, Gender and Salary.
5.    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.
6.    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 25 of salary).
7.    A sequential data file called ‘MARKS.DAT’,contains ROLLNO,NAME,English,Nepali and Maths fields. Write a program to display all the contents of the data file.
8.    A sequential data file called ‘student.dat’ contains same records under the fields Name, English, Nepali and computer. Write a program to add some more records in the same sequential data file.
9.    Write a program to view those records from “Employee.dat” sequential data file having employee’s name, department, appointment data and salary whose salary is more than Rs.5000.
10.                       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.
11.                       A sequential data file “Staff.dat” contains the name, address, post and salary of employees. Write a program to read and display all the records stored in the above data file.
12.                       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.
13.                       A sequential data file “Record.dat” has records with field Name, Address , Age and salary. Write a program to display only those records whose Age is greater the 26.
14.                       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 15,000 and less than 40,000.
15.                       A sequential data file called ‘marks.dat’ has stored data under the field heading Roll NO.,Name, English, Nepali and Maths. Write a program to display all the information of those students whose marks in Nepali is more than 50.
16.                       A sequential data file called “Marks.dat” contains NAME,AGE,CITY and TELEPHONE fields. Write a program to display all the contents of that data file.
17.                       Create a data file to store the records of few employees having Name, Address, Post, Gender and Salary fields.
18.                       Write a program to store Roll no., Name, Class , Address of any five students.
19.                       Create a sequential data file “std.dat” to store names and marks obtained in English, Math and Science subjects for a few students.
20.                       A data file “STAFF.dat” has stored records of few employees with EmpID. First name, Last name, post and salary. Write a program to display all the records of the employees whose salary is more than 40,000.

1.    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. [SLC 2064]
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

2. Write a program to store records regarding the information of Book number, Book’s name and Write’s name in a sequential data file called “Library.dat”. [SLC 2065]
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





3. Write a program to create a sequential data file “Employee.Dat” to store employees’ name, address, age, gender and salary. [SLC 2066]

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

4. 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


5. 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

6. 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



7.  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

8. A sequential data file called “Marks.dat” contains roll number, name, English, Nepali, and Maths field. Write a program to display all the content of the data file. [SLC 2065 SUPPLEMENTARY]

OPEN “Marks.dat” FOR INPUT AS #1
CLS
WHILE NOT EOF(1)
INPUT#1, R, N$, E, N, M
PRINT  R, N$, E, N, M
WEND
CLOSE#1
END








9.  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. [SLC 2066 SUPPLEMENTARY]

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

10.  A sequential data file called ‘MARKS.DAT’ contains ROLL NO, NAME, English, and Nepali and Maths fields. Write a program to display all the contents of the data file. [SLC 2067 SUPPLEMENTARY]

OPEN “MARKS.DAT” FOR INPUT AS #1
CLS
WHILE NOT EOF(1)
INPUT#1, R, N$, E, N, M
PRINT  R, N$, E, N, M
WEND
CLOSE#1
END






11.  Write a program to view those records from “Employee.dat” sequential data file having employee’s name, department, appointment date and salary whose salary is more than Rs.5000.[SLC 2068 SUPPLEMENTARY]

OPEN “Employee.dat” FOR INPUT AS #1
CLS
WHILE NOT EOF(1)
INPUT#1, N$, D$, A$,S
IF S>5000 THEN
PRINT  N$, D$, A$, S
END IF
WEND
CLOSE#1
END

12.  A sequential data file “Staff.dat” contains the name, address, post and salary of the employees. Write a program to read and display all the records stored in the above data file. [SLC 2069 SUPPLEMENTARY]

OPEN “Staff.dat” FOR INPUT AS #1
CLS
WHILE NOT EOF(1)
INPUT#1, N$, A$, P$, S
PRINT  N$, A$, P, S
WEND
CLOSE#1
END





13.Write a program to create a sequential data file “RESULT.DAT” to store name, address and marks obtained in 3 different subjects of students. [PABSON SEND UP 2066]
- OPEN “RESULT.DAT” FOR OUTPUT AS #1
DO
CLS
INPUT “Enter name”; N$
INPUT “Enter address”; A$
INPUT “Enter marks in three different subjects”; M1, M2, M3
WRITE #1, N$, A$, M1, M2, M3
INPUT” Do you want to continue(Y/N)”;CH$
LOOP WHILE UCASE$(CH$)=”Y”
CLOSE #1
END

14. Write a program to search and display only those record whose percentage is more than 60% from the data “RESULT.DAT” which contain Student’s Symbol number, Date of birth, Total Marks, Percentage and Division. [PABSON SEND UP 2067]
-          OPEN “RESULT.DAT” FOR INPUT AS #1
CLS
WHILE NOT EOF(1)
INPUT #1, SN, D$, T, P, DA$
IF P>60 THEN PRINT SN, D$, T, P, DA$
WEND
CLOSE #1
END







15. A data file name “STUDENT.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) [SLC SEND UP 2067]
- OPEN “STUDENT.DAT” FOR INPUT AS #1
CLS
WHILE NOT EOF(1)
INPUT #1, N$, P$, S
IF UCASE$(P$)=”MANAGER” THEN
C=C+1
END IF
WEND
PRINT “The total numbers of managers are”; C
CLOSE #1
END

16. WAP to create sequential file “Person.DAT” containing information like Name, age, DOB and sex. Add records in this data file as per the users choice. [PABSON SLC 2064]
-  OPEN “PERSON.DAT” FOR OUTPUT AS #1
DO
CLS
INPUT” Enter name”; N$
 INPUT” Enter age”; A$
INPUT” Enter date of birth”; D$
INPUT” Enter Sex”; S$
WRITE #1, N$, A$, D$, S$
INPUT “Do you want to continue(Y/N)”; CH$
LOOP WHILE UCASE$(CH$)=”Y”
CLOSE #1
END



17. Write a program to store SIDNO, name, address and Telephone number of five students and display the records on monitor in sequential data file “STDINFO”. [MAAF SLC SEND UP 2068]
- OPEN “ STDINFO.DAT” FOR OUTPUT AS #1
DO
CLS
INPUT “Enter SID NO. “; N
INPUT “Enter name”; N$
INPUT “Enter address”; A$
INPUT “Enter telephone number”; T#
WRITE #1, N, N$, A$, T#
INPUT “Do you want to continue(Y/N)”; CH$
LOOP WHILE UCASE$(CH$)=”Y”
CLOSE #1
END

18.  Write a program to create a data file “SLC.dat” to store Name,Class,and marks in three subjects of 15 students. [PABSON SLC SEND UP 2068]
- OPEN “SLC.DAT” FOR OUTPUT AS #1
FOR I = 1 TO 15
CLS
INPUT “Enter name”; N$
INPUT “Enter class”; C
INPUT “Enter marks in three different subjects”; M1, M2, M3
WRITE #1, N$,C,M1,M2,M3
NEXT I
CLOSE #1
END





19. Write a program to create a data file “result.dat” to store name, address and obt. Marks in three different subjects of students. [SLC SEND UP 2069]
-  OPEN “RESULT.DAT” FOR OUTPUT AS #1
DO
CLS
INPUT “Enter name”; N$
INPUT “Enter address”; A$
INPUT “Enter marks in three different subjects”; M1, M2, M3
WRITE #1, N$, A$, M1, M2, M3
INPUT “Do you want to continue(Y/N)”; CH$
LOOP WHILE UCASE$(CH$)=”Y”
CLOSE #1
END

20.  Write a program to open a data file “STUDENT.DAT”that contains Name, Address, Telephone number and Parent’s Name of some students. Now display all those records whose address is “LALITPUR”. [JM SECOND TERM 2068]
-          OPEN “STUDENT.DAT” FOR INPUT AS #1
CLS
WHILE OT EOF(1)
INPUT #1, N$, A$, T#, PN$
IF UCASE$(A$)=”LALITPUR” THEN PRINT N$, A$, T#, PN$
WEND
CLOSE #1
END






21. A data file”STUDENT.DAT” has several records in it.Write a program to read existing record from the file and display the total number or records.
-          OPEN “STUDENT.DAT” FOR INPUT AS #1
CLS
WHILE NOT EOF(1)
LINE INPUT #1, R$
C=C+1
WEND
PRINT “Total number of records=”; C
CLOSE #1
END

22.    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.
-          OPEN “PRICE.DAT” FOR OUTPUT AS #1
DO
CLS
INPUT “Enter item name”; N$
INPUT “Enter quantity”; Q
INPUT “Enter rate”; R
T= Q*R
WRITE #1, N$, Q, R
INPUT “Do you want to continue(Y/N)”;CH$
LOOP WHILE UCASE$(CH$)=”Y”
CLOSE #1
END





23.    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
CLS
INPUT “Enter your name”; N$
INPUT “Enter marks in three different subjects”; M1, M2, M3
T=M1+M2+M3
P= T/3
WRITE #1, N$, M1, M2, M3, T, P
NEXT I
CLOSE #1
END

24.    A sequential data file’post.dat’ has few records related to name,address,salary and DOB (mm/dd/yyyy).WAP to:
 i.  Display all the records as well as count and display he total number of records also.
 ii. Display the records whose address begins with ‘S’ or ‘D’

- i)
-  OPEN “POST.DAT” FOR INPUT AS #1
CLS
WHILE NOT EOF(1)
INPUT #1, N$, A$, S, D$
PRINT N$, A$, S, D$
C=C+1
WEND
PRINT “Total number of records=”; C
CLOSE #1
END   
     


-  ii)
-   OPEN “POST.DAT” FOR INPUT AS #1
CLS
WHILE NOT EOF(1)
INPUT #1, N$, A$, S, D$
B$=LEFT$(A$,1)
IF UCASE$(B$)=”S” OR UCASE$(B$)=”D” THEN PRINT N$, A$, S, D$
WEND
CLOSE #1
END

25. A sequential data file named”rec.dat”contains name,post and salary.  Write a program to display all the records for the employees whose Salary is more than 8000. [MAAF PRE SEND UP 2069 SET B]
  OPEN “REC.DAT” FOR INPUT AS #1
CLS
WHILE NOT EOF(1)
INPUT #1, N$, P$, S
IF S>8000 THEN PRINT N$, P$, S
WEND
CLOSE #1
END

25. A sequential data file named “record.dat” contains first name, last name and age. Write a program to display all the records whose age is more than 60. [MAAF PRE SEND UP 2069 SET A]
  OPEN “RECORD.DAT” FOR INPUT AS #1
CLS
WHILE NOT EOF(1)
INPUT #1, FN$, LN$, A
IF A>60 THEN PRINT FN$, LN$, A
WEND
CLOSE #1
END

26. 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. [PABSON PRE SEND UP 2070]
 OPEN “RECORD.DAT” FOR INPUT AS #1
CLS
WHILE NOT EOF(1)
INPUT #1, N$, A$, D$, E$, T#
B$=LEFT$(D$, 2)
C=VAL(B$)
E$=LEFT$(DATE$, 2)
F=VAL(E$)
IF C=F THEN PRINT N$, A$, D$, E$, T#
WEND
CLOSE #1
END

27. Write a program to display all records having salary less than 2500 from the data file “ADD.INF” having the field’s name, post and salary. [PABSON PRE SEND UP 2066]
OPEN “ADD.INF” FOR INPUT AS #1
CLS
WHILE NOT EOF(1)
INPUT #1, N$, P$, S
IF S<2500 THEN PRINT N$, P$, S
WEND
CLOSE #1
END




28. WAP to 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). [NEPS PRE SEND UP 2066]
  OPEN “NEPS.DAT” FOR INPUT AS #1
OPEN “TEMP.DAT” FOR OUTPUT AS #1
CLS
INPUT “Enter name which is to be deleted”; D$
WHILE NOT EOF(1)
INPUT #1, N$, A$, T#
IF UCASE$(D$)<>UCASE$(N$) THEN
WRITE #2, N$, A$, T#
ELSE
PRINT “Deleted data=”; N$, A$, T#
END IF
WEND
CLOSE #1, #2
 KILL “NEPS.DAT”
NAME “TEMP.DAT” AS “NEPS.DAT”
END

29. Write a program to open a data file “STUDENT.DAT” that contains Name, Address, Telephone number and Parent’s Name of some students. Now display all those records whose Address is “LALITPUR”. [PABSON PRE SEND UP 2064]
  OPEN “STUDENT.DAT” FOR INPUT AS #1
CLS
WHILE NOT EOF(1)
INPUT #1, N$, A$, T#, PN$
IF UCASE$(A$) =”LALITPUR” THEN PRINT N$, A$, T#, PN$
WEND
CLOSE #1
END

30. Create a sequential data file “std.dat” to store name and marks obtain in English, Maths and Science for a few students. [SLC MODEL QUESTION 2065]
  OPEN “STD.DAT” FOR OUTPUT AS #1
DO
CLS
INPUT “Enter name”; N$
INPUT “Enter marks in English”; E
INPUT “Enter marks in Maths”; M
INPUT “Enter marks in Science”; S
WRITE #1, N$, E, M, S
INPUT “Do you want to continue(Y/N)”; CH$
LOOP WHILE UCASE$(CH$) =”Y”
CLOSE #1
END

31. Create a sequential data file “HOTEL.DAT” to store customers name, address, and phone number. Program should terminate with user’s choice. [SLC MODEL QUESTION 2]
 OPEN “HOTEL.DAT” FOR OUTPUT AS #1
DO
CLS
INPUT “Enter customers name”; CN$
INPUT “Enter address”; A$
INPUT “Enter phone number”; P#
WRITE #1, CN$, A$, P#
INPUT “Do you want to continue(Y/N)”; CH$
LOOP WHILE UCASE$(CH$) = “Y”
CLOSE #1
END




32. A sequential data file “SALARY.DAT” contains the information, Employee-Code, Employee-Name, Post, and Basic-Salary. Write a program to display those records whose Basic-salary is in between 10000 to 15000 and Post is ‘OFFICER’. [SLC MODEL QUESTION 1]
OPEN “SALARY.DAT” FOR INPUT AS #1
CLS
WHILE NOT EOF(1)
INPUT #1, EC, EN$, P$, S
IF B$>=10000 AND B$<=15000 AND UCASE$(P$)= “OFFICER” THEN
PRINT EC, EN$, P$, S
END IF
WEND
CLOSE #1
END

33.  A data file named “Staff.dat” contains staff name, Department, Post and Salary  of some staffs. Write a program to count and display total number of records    in a file. [PABSON SLC Q.EXAM 2069]
OPEN “STAFF.DAT” FOR INPUT AS #1
CLS
C=0
WHILE NOT EOF(1)
INPUT #1, N$, D$, P$, S
C=C+1
WEND
PRINT “Total number of records=”; C
CLOSE #1
END




34. 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. [SLC Q. PABSON 2070]
OPEN “NABIL.TXT” FOR INPUT AS #1
CLS
WHILE NOT EOF(1)
INPUT #1, N$, A, T, R
I=(A*T*R)/100
PRINT N$, A, T, R, I
WEND
CLOSE #1
END

35. 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. [SLC P.QUAL. PABSON 2069]
OPEN “XYZ.REC” FOR INPUT AS #1
CLS
INPUT “Enter post to be searched”; S$
FLAG=0
WHILE NOT EOF(1)
INPUT #1, N$, P$, D$, S
IF UCASE$(S$)=UCASE$(P$) THEN
PRINT N$, P$, D$, S
FLAG=1
END IF
WEND
IF FLAG=0 THEN PRINT “Data not found”
CLOSE #1
END



36.Write a program to create a sequential data file “RESULT.DAT” to store name, address and marks obtained in 3 different subjects of students. [PABSON SEND UP 2066]
-  OPEN “RESULT.DAT” FOR OUTPUT AS #1
DO
CLS
INPUT “Enter name”; N$
INPUT “Enter address”; A$
INPUT “Enter marks in three different subjects”; M1, M2, M3
WRITE #1, N$, A$, M1, M2, M3
INPUT” Do you want to continue(Y/N)”;CH$
LOOP WHILE UCASE$(CH$)=”Y”
CLOSE #1
END

37. Write a program to search and display only those record whose percentage is more than 60% from the data “RESULT.DAT” which contain Student’s Symbol number, Date of birth, Total Marks, Percentage and Division. [PABSON SEND UP 2067]
OPEN “RESULT.DAT” FOR INPUT AS #1
CLS
WHILE NOT EOF(1)
INPUT #1, SN, D$, T, P, DA$
IF P>60 THEN PRINT SN, D$, T, P, DA$
WEND
CLOSE #1
END

38. A data file name “STUDENT.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) [SLC SEND UP 2067]
OPEN “STUDENT.DAT” FOR INPUT AS #1
CLS
WHILE NOT EOF(1)
INPUT #1, N$, P$, S
IF UCASE$(P$)=”MANAGER” THEN
C=C+1
END IF
WEND
PRINT “The total numbers of managers are”; C
CLOSE #1
END

39. WAP to create sequential file “Person.DAT” containing information like Name, age, DOB and sex. Add records in this data file as per the users choice. [PABSON SLC 2064]
 OPEN “PERSON.DAT” FOR OUTPUT AS #1
DO
CLS
INPUT” Enter name”; N$
 INPUT” Enter age”; A$
INPUT” Enter date of birth”; D$
INPUT” Enter Sex”; S$
WRITE #1, N$, A$, D$, S$
INPUT “Do you want to continue(Y/N)”; CH$
LOOP WHILE UCASE$(CH$)=”Y”
CLOSE #1
END

40. Write a program to store SIDNO, name, address and Telephone number of five students and display the records on monitor in sequential data file “STDINFO”. [MAAF SLC SEND UP 2068]
OPEN “ STDINFO.DAT” FOR OUTPUT AS #1
DO
CLS
INPUT “Enter SID NO. “; N
INPUT “Enter name”; N$
INPUT “Enter address”; A$
INPUT “Enter telephone number”; T#
WRITE #1, N, N$, A$, T#
INPUT “Do you want to continue(Y/N)”; CH$
LOOP WHILE UCASE$(CH$)=”Y”
CLOSE #1
END

41. Write a program to create a data file “SLC.dat” to store Name,Class,and marks in three subjects of 15 students. [PABSON SLC SEND UP 2068]
 OPEN “SLC.DAT” FOR OUTPUT AS #1
FOR I = 1 TO 15
CLS
INPUT “Enter name”; N$
INPUT “Enter class”; C
INPUT “Enter marks in three different subjects”; M1, M2, M3
WRITE #1, N$,C,M1,M2,M3
NEXT I
CLOSE #1
END

42. Write a program to create a data file “result.dat” to store name, address and obt. Marks in three different subjects of students. [SLC SEND UP 2069]
OPEN “RESULT.DAT” FOR OUTPUT AS #1
DO
CLS
INPUT “Enter name”; N$
INPUT “Enter address”; A$
INPUT “Enter marks in three different subjects”; M1, M2, M3
WRITE #1, N$, A$, M1, M2, M3
INPUT “Do you want to continue(Y/N)”; CH$
LOOP WHILE UCASE$(CH$)=”Y”
CLOSE #1
END

43.Write a program to open a data file “STUDENT.DAT”that contains Name, Address, Telephone number and Parent’s Name of some students. Now display all those records whose address is “LALITPUR”. [JM SECOND TERM 2068]
OPEN “STUDENT.DAT” FOR INPUT AS #1
CLS
WHILE OT EOF(1)
INPUT #1, N$, A$, T#, PN$
IF UCASE$(A$)=”LALITPUR” THEN PRINT N$, A$, T#, PN$
WEND
CLOSE #1
END

44. A data file”STUDENT.DAT” has several records in it.Write a program to read existing record from the file and display the total number or records.
OPEN “STUDENT.DAT” FOR INPUT AS #1
CLS
WHILE NOT EOF(1)
LINE INPUT #1, R$
C=C+1
WEND
PRINT “Total number of records=”; C
CLOSE #1
END

45. 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.
OPEN “PRICE.DAT” FOR OUTPUT AS #1
DO
CLS
INPUT “Enter item name”; N$
INPUT “Enter quantity”; Q
INPUT “Enter rate”; R
T= Q*R
WRITE #1, N$, Q, R
INPUT “Do you want to continue(Y/N)”;CH$
LOOP WHILE UCASE$(CH$)=”Y”
CLOSE #1
END

46. 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
CLS
INPUT “Enter your name”; N$
INPUT “Enter marks in three different subjects”; M1, M2, M3
T=M1+M2+M3
P= T/3
WRITE #1, N$, M1, M2, M3, T, P
NEXT I
CLOSE #1
END
                        *************Jaya Ganeshya*******


Comments

Post a Comment

Popular posts from this blog

Test Result 2077/78

Full Form