Tuesday, September 26, 2017

Debug the Qbasic Programs [SEE Qbasic Practice PART V]

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

2.      REM TO READ RECORDS FROM DATA FILE
OPEN STUD.DAT FOR OUTPUT AS #1
WHILE NOT EOF(2)
LINE INPUT #2, REC$
PRINT REC$
LOOP
CLOSE #3
END

3.      REM to read data from the data file and display them
OPEN “TEST.TXT” FOR OUTPUT AS #10
WHILE NOT EOF(1)
LINE INPUT R$
PRINT R$
WEND
CLOSE ALL

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

5.      REM to DISPLAY ALL THE RECORDS FROM DATA FILE ABC.DAT
OPEN”ABC.DAT” FOR OUTPUT #1
DO WHILE EOF (“ABC.DAT”)
INPUT N$, A
PRINT N$, A
CLOSE #1
END

6.      REM to display all records from the sequential data file.
CLS
OPEN "REC.DAT" FOR OUTPUT AS #1
WHILE NOT EOF()
INPUT A$,B$,C
PRINT  A$,B$,C
LOOP
CLOSE #1
END

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

8.      OPEN “MAAF.DOC” FOR OUTPUT AS #10
CLS
DO WHILE NOT EOF(MAAF.DOC)
INPUT #1, N$,R,M1,M2,M3
PRINT #1,N$,R,M1,M2,M3
LOOP
CLOSE#10
END

9.      REM display Records of students From Data File
OPEN “STDREC.DAT” FOR INP AS #1
PRINT “ROLL”,”NAME”,”ADDRESS”,”CLASS”,”SECTION”
DO WHILE NOT EOF
INPUT #1,RN,N$,AD$,CL,S$
PRINT RN,N$,AD$,CL,S$
NEXT
CLOSE #1
END

10.   Rem to display the contents of a data file.
OPEN “Marks.dat” FOR OUTPUT AS #1
CLS
WHILE EOF(1)
            INPUT #1, Name$, Age, Add$
            DISPLAY Name$, Age, Add$
WEND
CLOSE 1
END


11.   REM add data to existing data file
DIM n, p, c AS STRING
OPEN “file.txt” FOR OUTPUT AS 1
DO
INPUT “Enter name, post”; n, p
WRITE n, p
INPUT “Press y/Y to add more”; c
LOOP WHILE c = “Y” or c = “y”
CLOSE 1
END


12.   REM To add records in existing data file which contains some records
OPEN “Directory.txt” FOR INPUT AS #2
DO
INPUT “ENTER Name “; N$
INPUT “ENTER Address “; A$                                              
INPUT “ENTER Telephone”; T$
ADD #2, N$, A$, T
INPUT “Do you want to add more records (Y/N)” ; ANS
LOOP WHILE UCASE(ANS$) = Y
CLOSE
END

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

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

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

16.   REM To store Name, post and salary
OPEN EMP.DOC” FOR OUT AS #1
INPUT” Enter name”;N
INPUT” Enter post”;P$
INPUT “Enter salary”;S
WRITE #2, N$,P$, S
CLOSE #1
END

17.   REM to  add records in a sequential data file.
OPEN “STUDENT.DAT” FOR INPUT #1
DO
INPUT “Enter name, class and roll no.”; N$, C, R]
PRINT #1, N$, C, R$
INPUT “Do you have more records(y/n)”; y$
UNTIL LCASE$(Y)= “n”
END

18.   REM store records
CLS
OPEN "peaks.xls" FOR INPUT AS #75
DO
INPUT "Enter peak"; P$
INPUT "Enter district";D
INPUT "Height"; H
WRITE P$,D$,H
INPUT "Do U 1 2 add more";mor$
LOOP WHILE UCASE$(mor$)="y"

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

20.   REM to add records in “marks.dat” sequential data file
OPEN “A”, 2, “mark.dat”
DO
INPUT “Roll Number, Name, Class”; R, N$, C
WRITE#1, R, N$, C
INPUT “Want to continue(Y?N)”; H$
LOOP UNTIL UCASE$(H$) < > “Y”
TERMINATE
END

1 comment: