Saturday, August 26, 2017

QBASIC file handling programs

1. Create a sequential file "std.dat" to store name and move obtained in English ,math and science subject for few student.

-> OPEN "std.dat" FOR OUTPUT AS #1
DO
CLS
INPUT "ENTER NAME"; N$
INPUT "ENTER ENGLISH MARKS";E
INPUT "ENTER MATH MARKS"; M
INPUT "ENTER SCIENCE MARKS ";S
WRITE #1, N$, E, M, S
INPUT "DO YOU WANT TO CONTINUE";CH$
LOOP WHILE UCASE$(CH$)="Y"
CLOSE #1
END


2.A data file "INFO.INF" has numerous records in it with name, address and telephone number in each record . WAP to scan all the records from the file and display only the record with address "bhaktapur".

-> OPEN "INFO.INF' FOR INPUT AS #1
CLS
WHILE NOT EOF(1)]
INPUT #1, N$, A$, T
IF A$="bhaktapur" THEN PRINT N$, A$, T
CLOSE #1
END


3. A sequential data file "text.txt" contain student name, marks of English, math and computer. WAP to display all the records of students whose percentage is mor than 60.

-> OPEN "text.txt" FOR INPUT AS #1
CLS
WHILE NOT EOF(1)
INPUT #1, N$, EN, MA, CO
TO= EN+MA+CO
PR= TO/3
IF PR>60 THEN PRINT N$, EN, MA, CO
WEND
CLOSE #1
END


4. WAP to add more records in a data file "ABC.DAT" having following fields patients name, address and age.

-> OPEN "ABC.DAT" FOR APPEND AS #1
DO
CLS
INPUT "ENTER NAME";N$
INPUT "ENTER ADDRESS";A$
INPUT "ENTER AGE";A
WRITE #1, N$, A$, A
INPUT"DO YOU WANT TO CONTINUE?"; CH$
LOOP WHILE UCASE$ (CH$)="Y"
CLOSE #1
END


5. A sequential data, file "std.dat" contains name, class, roll no and address of some students. WAP to record and display only those record whose name starts with "A"

->OPEN "std.dat" FOR INPUT AS #1
CLS
WHILE NOT EOF(1)
INPUT #1, N$, C, R, A$
A$= UCASE$( LEFT$(N$, 1)
IF A$= "A" THEN PRINT N$, C, R, A$
WEND
CLOSE #1
END


6. WAP to store records regarding the information of book number, name, and authors  name in a sequential data.

->OPEN "LIBRARY.DAT" FOR OUTPUT AS #1
DO
CLS
INPUT" ENTER BOOK'S NUMBER";N
INPUT" ENTER BOOK'S NAME";N$
INPUT" ENTER AUTHORS NAME ";A$
WRITE #1, N, N$, A$
INPUT" DO YOU WANT TO CONTINUE?"; CH$
LOOP WHILE UCASE$(CH$)="Y"
CLOSE#1
END


7. A sequential data file called" MARKS.DAT" contains roll no, name, English, Nepali, and Math fiels. WAP to display the contents.

-> OPEN "MARKS.DAT" AS INPUT AS #1
CLS
INPUT"ROLL NO", "NAME", "ENGLISH", "NEPALI", "MATH"
WHILE NOT EOF(1)
INPUT #1, R, N$, E, N, M
PRINT R, N$, E, N, M
WEND
CLOSE #1
END


8. WAP to create sequential data file "Employee.dat" to store employee's, name, address, gender and salary.

->OPEN"Employee.dat" FOR OUTPUT AS #1
TOP:
CLS
INPUT" ENTER NAME";N$
INPUT" ENTER ADDRESS";A$
INPUT" ENTER AGE";A
INPUT" ENTER GENDER"; G$
INPUT" ENTER SALARY";S
WRITE #1, N$, A$, A, G$, S
INPUT" DO YOU WANT TO CONTINUE"; CH$
IF UCASE$(CH$)="Y" THEN GOTO TOP
END


9. A data file" LIB.TXT" contain Book's name, authors name and price of books, WAP to count and display total number of record present in a file.

->OPEN "LIB.TXT" FOR INPUT AS #1
CLS
WHILE NOT EOF(1)
INPUT #1, B$, A$, P
C=C+1
WEND
CLOSE #1
PRINT" TOTAL NUMBER OF RECORD=";C
END


10. A sequential data file name" EMP.DAT" contain name, post, and salary fields. WAP to display all the information of employees along with 15% tax amount.

-> OPEN " EMP.DAT" FOR INPUT AS #1
CLS
WHILE NOT EOF(1)
INPUT #1, N$, P$,S, T
T= 15/100 *S
PRINT N$, P$, S, T
WEND
CLOSE #1
END


11.A  sequential data file called "MARKS.DAT" contain roll no, name, English, Nepali, and Math field. WAP to display all data.

-> OPEN " MARKS.DAT" FOR INPUT AS #1
CLS
WHILE NOT EOF(1)
INPUT #1, RN, N$, E, N, M
PRINT RN, N$, E, N, M
WEND
CLOSE #1
END


12. A sequential data file called "student.dat" contain record under the field name, English, Nepali, and Computer. WAP to add some more record to some field.

-> OPEN " student.dat" FOR APPEND AS #1
CLS
TOP:
INPUT" ENTER NAME";N$
INPUT" ENTER ENGLISH";E
INPUT" ENTER NEPALI''; N
INPUT" ENTER COMPUTER";C
WRITE #1, N$, E,N,C
INPUT" DO YOU WANT TO CONTINUE"; CH$
IF UCASE$(CH$) ="Y" THEN GOTO TOP
CLOSE #1
END


13. WAP to view those records from " Emlpoyee.dat" sequential data file having employees name, department, appointment data and salary whose salary is more than Rs 5000.

-> OPEN "Employee.dat" FOR INPUT AS #1
CLS
WHILE NOT EOF(1)
INPUT #1, N$, D$, A$, S
IF S>5000 THEN PRINT N$, D$, A$, S
WEND
CLOSE #1
END


14. WAP to create a data file " teldir.dat" to store name, address and telephone number according to the need of the user.

->OPEN"teldir.dat" FOR OUTPUT AS #1
DO
CLS
INPUT" ENTER NAME";N$
INPUT" ENTER ADDRESS";A$
INPUT" ENTER TELEPHONE NUMBER";T
WRITE #1, N$, A$, T
INPUT" DO YOU WANT TO CONTINUE";CH$
LOOP WHILE UCASE$(CH$) ="Y"
CLOSE #1
END


15.A sequential data file "marks.dat"; contain name, English, Nepali, Math and Science fields. WAP to display all the contents of files.

->OPEN" marks.dat" FOR INPUT AS #1
CLS
PRINT "NAME", "ENGLISH", "NEPALI", "MATHS", "SCIENCE"
WHILE NOT EOF(1)
INPUT #1, N$, E, N, M, S
PRINT N$, E, N, M, S
WEND
CLOSE #1
END


16. A data file "salary.dat" contain the information of employee whose salary is greater than 15000 and less than 40000.

-> OPEN"salary.dat" FOR INPUT AS #1
CLS
PRINT "NAME", "POST", "SALARY"
WHILE NOT EOF(1)
INPUT #1, N$, P$, S
IF S<40000 AND S>15000 THEN PRINT N$,P$,S
WEND
CLOSE #1
END


17. A sequential data file called "marks.dat" contain name, age, city and telephone fields. WAP to display all the records of that files.

-> OPEN"marks.dat" FOR INPUT AS #1
CLS
PRINT" Name", "Age", "City", "Telephone"
WHILE NOT EOF(1)
INPUT #1, N$,A,C$,T
PRINT  N$,A,C$,T
WEND
CLOSE #1
END

No comments:

Post a Comment

SLC Examination 2073

1 Q/Ans a) -> The advantage of bus topology:- It is easy to set up computers and other devices  It requires power cable media, ...