Wednesday, May 5, 2021

Debugging - SLC / SEE Computer Science - Sequential File Handling - Qbasic Programs [Set 2]

 Debugging - SLC / SEE Computer Science - Sequential File Handling - Qbasic Programs [Set 1]

11.

REM to read data from a sequential data file

OPEN STUDENT.DAT FOR INPUT #1

DO WHILE EOF (2)

INPUT NAME$, ADD$, TELNO$, AGE

IF AGE IS GREATER THAN 15 THEN

PRINT NAMES$, ADD$, TELNO$, AGE

LOOP

CLOSE #1

END

12.

REM Program to display name,address and age
CLS
OPEN "season.dat" FOR OUTPUT AS #1
While EOF(1)
INPUT #1,Name $ add$ Age
DISPLAY Name$ add$ Age
LOOP
CLOSE #1
END

13.

REM program to copy data from exam.dat to test.dat
OPEN "exam.dat" FOR OUTPUT AS #1
OPEN "test.dat" INPUT AS #2
DO UNTIL EOF (#2)
INPUT #2,N$,A$,A
WRITE #2,N$,A$,A
LOOP
CLOSE #1,#2
END

14.

OPEN”SALARY.DAT” FOR INPUT AS #1

CLS

ANS$=”Y”

DO WHILE ANS=”Y”

INPUT “ENTER NAME,POST AND SALARY ;N$,P$,S

PRINT #1,N$,P$,S

PRINT “ANY MORE DATA (Y/N)”:ANS$

WEND   

CLOSE #1

END

15.

REM Program to store data in a sequential data file.
CLS
DO
OPEN "Address.txt" FOR INPUT AS #1
INPUT "Name"; N$
INPUT "Address"; A$
INPUT "Age"; A
Input "Phone"; P$
WRITE N$,A$,A,P$
INPUT "Do you want some more…."; ans$
LOOP WHILE UCASE(ans$)=”Y”
CLOSE #1
END

16.

OPENexam.dat FOR OUTPUT AS#1

CLS

PRINT “Name’’, “Faculty” , “Post” , “Salary”

WHILE NOT EOF (1)

        INPUT1, N$,F$,P$,S$

LOOP

END

17.

REM To add records in an existing file
CLS
OPEN "record.dat" FOR OUTPUT AS #1
aa:
INPUT "Name, class & roll"; n$, c, r
INPUT #2, n$, c, r
INPUT "more records"; y$
IF y$="y" THEN GOTO aa
CLOSE "record.dat"
END

18.

REM To add more records in the existing data file which contains some records

OPEN “ABC.TXT” FOR INPUT AS #2
DO
            INPUT “ENTER NAME”; N$
            INPUT ”ENTER POST”; P$
            INPUT “ENTER SALARY”; S
                        ADD #2, N$, P$, S
            INPUT ”Want to add more records (Y/N)”; YN$
LOOP WHILE UCASE(YN$)=Y
CLOSE
END

19.


OPEN info.dat FOR OUTPUT AS #2

CLS

PRINT “NAME”, “POST”, “DEPT”, “SALARY”

WHILE NOT EOF (1)

INPUT 1, N$, P$, D$, S

PRINT N$, P, D$, S$

LOOP

KILL #2

END

20.

Rem to overwrite existing data in a sequential file with new data

            OPEN “MYFILE.DAT” FOR INPUT AS #1

            DO

            INPUT “ENTER NAME”; N$

            INPUT “ENTER ADDRESS”; A$

            INPUT “TEL NO.”; T$

            INPUT #1, N$, A$, T$

            PRINT “CONTINUE”; C$

            LOOP WHILE C$(UCASE$)=”Y”

            CLOSE #1

            END



No comments:

Post a Comment