File handling on QBASIC:SOLVED

1.       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 2074]
-          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

2.       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 2075]
-          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

3.       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 2073]
-          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

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

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

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

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

8.       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 2067]
-          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

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

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

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

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




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

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

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

4.        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 2071]
è  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

5.        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 2072]
è  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

6.        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 2074]
è  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

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

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

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

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

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

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


1. A sequential data file called salary.dat contains s.no, name, post and salary fields. WAP to update the salary of all the employees if post is manager and salary is more than 25000 by 15% otherwise by 10%.

OPEN "D:\SALARY.DAT" FOR INPUT AS #1
OPEN "D:\TEMP.DAT" FOR OUTPUT AS #2
CLS
WHILE NOT EOF(1)
INPUT #1, N$, P$, S
IF S > 25000 AND UCASE$(P$) = "MANAGER" THEN
WRITE #2, N$, P$, S + (15 / 100) * S
ELSE
WRITE #2, N$, P$, S + (10 / 100) * S
END IF

WEND
CLOSE
KILL "D:\SALARY.DAT"
NAME "D:\TEMP.DAT" AS "D:\SALARY.DAT"


 END

1.    2.   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.
OPEN "D:\RECORD" FOR INPUT AS #1
OPEN "d:\TEMP.DAT" FOR OUTPUT AS #2
CLS
INPUT "ENTER ROLL NUMBER TO EDIT DATA"; E
FLAG = 0
WHILE NOT EOF(1)
INPUT #1, R, N$, A$, P
IF E <> R THEN
WRITE #2, R, N$, A$, P
ELSE
INPUT "ENTER ROLL NUMBER"; ER
INPUT "ENTER NAME"; EN$
INPUT "ENTER ADDRESS"; EA$
INPUT "ENTER PERCENTAGE"; EP
WRITE #2, ER, EN$, EA$, EP
FLAG = 1
END IF
WEND
IF FLAG = 0 THEN
PRINT "DATA NOT FOUND"
ELSE
PRINT "NON EDITED DATA"
PRINT "ROLL NUMBER= "; R
PRINT "NAME= "; N$
PRINT "ADDRESS= "; A$
PRINT "PERCENTAGE= "; P
PRINT "---------------"
PRINT "EDITED DATA"
PRINT "ROLL NUMBER: "; ER
PRINT "NAME: "; EN$
PRINT "ADDRESS: "; EA$
PRINT "PERCENTAGE: "; EP
END IF

CLOSE

KILL "D:\SALARY.DAT"
NAME "D:\TEMP.DAT" AS "D:\SALARY.DAT"
END

 f
 f                                                                          for more practice go below:                                                                                     
  • Write a program to input the name of a person, post and salary and store them in a sequential data file “SAL.DAT” 
OPEN “SAL.DAT” FOR OUTPUT AS #1
CLS
DO
INPUT “ENTER THE NAME ” ;  N$
INPUT “ENTER THE POST” ; P$
INPUT “ENTER THE SALARY” ; S$
WRITE#1 , N$,P$,S$
INPUT “DO YOU WANT TO STORE MORE RECORDS ? (Y/N)” ; CH$
LOOP WHILE UCASE(CH$)=”Y”
CLOSE#1
END
  • WRITE A PROGRAM TO ADD SOME DATA IN AN EXISTING SEQUENTIAL DATA FILE “EMP.DAT” HAVING FIELDS NAME ,POST AND SALARY
OPEN “EMP.DAT” FOR APPEND AS #1
CLS
DO
INPUT “ENTER NAME” ; N$
INPUT “ENTER POST” ;P$
INPUT “ENTER SALARY” ; S
WRITE #1, N$,P$,S
INPUT “ADD MORE DATA ? (Y/N)” ; C$
CH$=UCASE$(C$)
LOOP WHILE UCASE(CH$)=”Y”
CLOSE#1
END
  • WRITE A PROGRAM TO READ ALL THE DTA FROM THE DATA FILE NAMED “SAL.DAT” HAVING FIELDS NAME , POST AND SALARY AND DISPLAY ONLY THOSE RECORDS WHERE THE SALARY IS EQUAL OR GREATER THAN 5000 AND POST IS “MANAGER”
OPEN “SAL.DAT” FOR INPUT AS#1
CLS
WHILE NOT EOF(1)
INPUT #1, N$,P$,S
IF S>=5000 AND P$=”MANAGER” THEN
PRINT N$,P$,S
END IF
WEND
CLOSE#1
END
  • WRITE A PROGRAM TO DISPLAY ALL THE RECORDS FROM “REC.DAT” ALSO COUNT HOW MANY RECORDS HAVE BEEN DISPLAYED.
OPEN “REC.DAT” FOR INPUT AS #1
WHILE NOT EOF(1)
LINE INPUT #1,A$
C=C+1
WEND
CLOSE#1
PRINT “NO. OF RECORDS DISPLAYED=”;C
END

Qbasic Program: Sequential Data File



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


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


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


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


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


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


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


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


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


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


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


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


-          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





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


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


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


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


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


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


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


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


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


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


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


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



13. A sequential data file called salary.dat contains s.no, name, post and salary fields. WAP to update the salary of all the employees if post is manager and salary is more than 25000 by 15% otherwise by 10%.


OPEN "D:\SALARY.DAT" FOR INPUT AS #1
OPEN "D:\TEMP.DAT" FOR OUTPUT AS #2
CLS
WHILE NOT EOF(1)
INPUT #1, N$, P$, S
IF S > 25000 AND UCASE$(P$) = "MANAGER" THEN
WRITE #2, N$, P$, S + (15 / 100) * S
ELSE
WRITE #2, N$, P$, S + (10 / 100) * S
END IF

WEND
CLOSE
KILL "D:\SALARY.DAT"
NAME "D:\TEMP.DAT" AS "D:\SALARY.DAT"


 END


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

OPEN "D:\RECORD" FOR INPUT AS #1
OPEN "d:\TEMP.DAT" FOR OUTPUT AS #2
CLS
INPUT "ENTER ROLL NUMBER TO EDIT DATA"; E
FLAG = 0
WHILE NOT EOF(1)
INPUT #1, R, N$, A$, P
IF E <> R THEN
WRITE #2, R, N$, A$, P
ELSE
INPUT "ENTER ROLL NUMBER"; ER
INPUT "ENTER NAME"; EN$
INPUT "ENTER ADDRESS"; EA$
INPUT "ENTER PERCENTAGE"; EP
WRITE #2, ER, EN$, EA$, EP
FLAG = 1
END IF
WEND
IF FLAG = 0 THEN
PRINT "DATA NOT FOUND"
ELSE
PRINT "NON EDITED DATA"
PRINT "ROLL NUMBER= "; R
PRINT "NAME= "; N$
PRINT "ADDRESS= "; A$
PRINT "PERCENTAGE= "; P
PRINT "---------------"
PRINT "EDITED DATA"
PRINT "ROLL NUMBER: "; ER
PRINT "NAME: "; EN$
PRINT "ADDRESS: "; EA$
PRINT "PERCENTAGE: "; EP
END IF

CLOSE

KILL "D:\SALARY.DAT"
NAME "D:\TEMP.DAT" AS "D:\SALARY.DAT"
END




Comments

Popular

Multimedia and its applications

Networking and Telecommunication