File Handling Programs

Print This Page
  • 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

 

 

Leave a Reply