QBASIC FILE HANDLING PROGRAMS - PART I
[SEE COMPUTER SCIENCE 2077]
1. WAP to store name, post, address and salary for five
employees.
OPEN "SAL.DAT" FOR OUTPUT AS #1
FOR I = 1 TO 5
CLS
INPUT "Enter name “; N$
INPUT “Enter post”; P$
INPUT "Enter address"; A$
INPUT “Enter salary”; S
WRITE #1, N$, P$, A$, S
NEXT I
CLOSE #1
END
2. WAP to store name, post, address and salary. The
program should terminate according to user’s choice.
OPEN "SAL.DAT" FOR OUTPUT AS #1
DO
CLS
INPUT "Enter name "; N$
INPUT “Enter post”; P$
INPUT "Enter address"; A$
INPUT “Enter salary”; S
WRITE #1, N$, P$, A$, S
INPUT "Do you want to continue? (Y/N)" ; CH$
LOOP WHILE UCASE$(CH$) = "Y"
CLOSE #1
END
3. WAP to display all the records from the data file
"SAL.DAT"
OPEN "SAL.DAT" FOR INPUT AS #1
CLS
WHILE NOT EOF(1)
INPUT #1, N$, P$, A$, S
PRINT N$, P$, A$, S
WEND
CLOSE #1
END
4. WAP to display all information whose salary is greater
than 15,000 and less than 40,000 from the data file "SAL.DAT".
OPEN "SAL.DAT" FOR INPUT AS #1
CLS
WHILE NOT EOF(1)
INPUT #1,N$,P$,A$,S
IF S>15000 AND S<40000 THEN PRINT N$, P$, A$, S
WEND
CLOSE #1
END
5. WAP to count and display total number of records from
the data file "SAL.DAT"
OPEN "SAL.DAT" FOR INPUT AS #1
CLS
WHILE NOT EOF(1)
INPUT #1,N$,P$,A$,S
C=C+1
WEND
PRINT " Total number of records"; C
CLOSE #1
END
6. Wap to display all records as well as total number of
records from the data file "SAL.DAT"
OPEN "SAL.DAT" FOR INPUT AS #1
CLS
WHILE NOT EOF(1)
INPUT #1, N$, P$, A$, S
PRINT N$, P $, A$, S
C=C+1
WEND
PRINT " Total number of records"; C
CLOSE #1
END
7. Wap to display all records whose post is officer from
the data file "SAT.DAT"
OPEN "SAL.DAT" FOR INPUT AS #1
CLS
WHILE NOT EOF(1)
INPUT #1, N$, P$, A$, S
IF UCASE$(P$) = "OFFICER" THEN PRINT N$,P$,A$,S
WEND
CLOSE #1
END
8. Wap to display all the records whose salary is between
10000 to 15000 and post is officer from the data file "SAT.DAT"
OPEN "SAL.DAT" FOR INPUT AS #1
CLS
WHILE NOT EOF(1)
INPUT #1,N$,P$,A$,S
IF S>10000 AND S<15000 AND UCASE$(P$)="OFFICER" THEN PRINT
N$,P$,A$,S
WEND
CLOSE #1
END
9. WAP to count total number of managers from the data
file "SAL.DAT"
OPEN "SAL.DAT" FOR INPUT AS #1
CLS
WHILE NOT EOF(1)
INPUT #1,N$,P$,A$,S
IF UCASE$(P$)="MANAGER" THEN C=C+1
WEND
PRINT " Total number of managers = "; C
CLOSE #1
END
10. WAP to display all information along with tax from
the data file "SAT.DAT" (15% of salary)
OPEN "SAL.DAT" FOR INPUT AS #1
CLS
WHILE NOT EOF(1)
INPUT #1,N$,P$,A$,S
T=15/100 *S
PRINT N$,P$,A$,S,T
WEND
CLOSE #1
END
11. WAP to display all records whose address is Kathmandu
or Palpa from "SAL.DAT"
OPEN "SAL.DAT" FOR INPUT AS #1
CLS
WHILE NOT EOF(1)
INPUT #1, N$,P$,A$,S
IF UCASE$(A$) = "PALPA" OR UCASE$(A$)=
"KATHMANDU" THEN PRINT N$,P$,A$,S
WEND
CLOSE #1
END
12.WAP to display all records whose address is Bhaktapur
and salary is above 15000 from the data file "SAT.DAT"
OPEN "SAL.DAT" FOR INPUT AS #1
CLS
WHILE NOT EOF(1)
INPUT #1, N$, P$, A$, S
IF UCASE$(A$) = "BHAKTAPUR" AND S>15000 THEN
PRINT N$,P$,A$,S
WEND
CLOSE #1
END
13. WAP to display all the records whose address begins
with the letter S or D from the data file "SAL.DAT"
OPEN "SAL.DAT" FOR INPUT AS #1
CLS
WHILE NOT EOF(1)
INPUT #1, N$,P$,A$,S
IF UCASE$(LEFT$(A$,1))= "S" OR
UCASE$(LEFT$(A$,1)) = "D" THEN PRINT N$, P$, A$, S
WEND
CLOSE #1
END
14. WAP to store name, class and marks in three subject
for N number of records.
OPEN "RESULT.DAT" FOR OUTPUT AS #1
INPUT "Enter how many records"; N
FOR I = 1 to N
CLS
INPUT " Enter name "; N$
INPUT “Enter class”; C
INPUT "Enter marks in 3 subjects"; X,Y,Z
WRITE #1, N$,C,X,Y,Z
NEXT I
CLOSE #1
END
15. WAP to store a name, class and marks in 3 subjects in
the data file "RESULT.DAT" only whose class is 10.
OPEN "RESULT.DAT" FOR OUTPUT AS #1
DO
CLS
INPUT " Enter name "; N$
INPUT “Enter class”; C
INPUT " Enter marks in 3 subjects"; X, Y, Z
IF C=10 THEN WRITE #1, N$,C,X,Y,Z
INPUT 'Do you want to continue? (Y/N)"; CH$
LOOP WHILE UCASE$ (CH$) = "Y"
CLOSE #1
END
16. WAP to display only those records whose percentage is
greater that 60 and less that 80. Also count the total number of records.
(name, class, marks in 3 subject)
OPEN "RESULT.DAT" FOR INPUT AS #1
CLS
WHILE NOT EOF(1)
INPUT #1,N$,C,X,Y,Z
T= X+Y+Z
P= T/3
IF P>60 AND P<80 THEN PRINT N$,C,X,Y,Z
D=D+1
WEND
CLOSE #1
PRINT "Total number of records"; D
END
17. WAP to display only failed records assuming the pass marks
for each subject is 40. (name, class, marks in 3 subject)
OPEN "RESULT.DAT" FOR INPUT AS #1
CLS
WHILE NOT EOF(1)
INPUT #1,N$,C,X,Y,Z
IF X<40 AND Y<40 AND Z<40 THEN PRINT N$,C,X,Y,Z
WEND
CLOSE #1
END
18. WAP to create a sequential file
"RESULT.DAT" and store name, class and marks in 3 subjects along with
total and percentage.
OPEN "RESULT.DAT" FOR OUTPUT AS #1
DO
CLS
INPUT " Enter name"; N$
INPUT “Enter class”; C
INPUT " Enter marks in 3 subjects"; X,Y,Z
T= X+Y+Z
P=T/3
WRITE #1, N$,C,X,Y,Z,T,P
INPUT " Do you want to continue? (Y/N)"; CH$
LOOP WHILE UCASE$(CH$)= "Y"
CLOSE #1
END
19. Wap to display name, class and marks in 3 subject
from the data file “RESULT.DAT” along with total and percentage.
OPEN “RESULT.DAT” FROM INPUT AS #1
CLS
WHILE NOT EOF(1)
INPUT #1, N$, C, X, Y, Z
T= X+Y+Z
P= T/3
PRINT N$, C, T, P
WEND
CLOSE #1
END
20. Wap to display all records whose marks in computer is
more than 80 from the data file “RESULT.DAT” (name, class, marks in english,
nepali, computer).
OPEN “RESULT.DAT” FOR INPUT AS #1
CLS
WHILE NOT EOF(1)
INPUT #1, N$, C, X, Y, Z
IF Z= 80 THE PRINT N$, C, X, Y, Z
WEND
CLOSE #1
END
No comments:
Post a Comment