0% found this document useful (0 votes)
3 views25 pages

Program in QBASIC Using File Handling

The document provides a series of QBASIC programming exercises focused on file handling, including creating, reading, and updating sequential data files. Each exercise includes specific tasks such as storing book details, employee records, student marks, and implementing features like adding, displaying, and deleting records based on user input. The document serves as a guide for practicing file operations in QBASIC.

Uploaded by

boharajeevan00
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views25 pages

Program in QBASIC Using File Handling

The document provides a series of QBASIC programming exercises focused on file handling, including creating, reading, and updating sequential data files. Each exercise includes specific tasks such as storing book details, employee records, student marks, and implementing features like adding, displaying, and deleting records based on user input. The document serves as a guide for practicing file operations in QBASIC.

Uploaded by

boharajeevan00
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Writing a Program in QBASIC using File Handling

(It carries 4 marks)

1) SLC 2063
Write a program to store the book's name, writers name and the price of the
book in a sequential data file “[Link]”. The program provides the
facility to enter more records as long as the user wants.
OPEN “[Link]” FOR OUTPUT AS #2
TOP:
INPUT “Enter book’s name=”;b$
INPUT “Enter Writer’s name=”;w$
INPUT “Enter price of book=”;p
WRITE #2, b$, w$, p
INPUT “Do you want to add more records (Y/N)”;Ans$
IF Ans$=”Y” or Ans$=”y” THEN GOTO top
CLOSE #2
END

2) SLC 2064
Write a program in QBASIC to open a sequential data file “[Link]”
which contains the employee records, name, address and phone number and
display all the records as well as total number of records stored in the file.
OPEN “[Link]” FOR INPUT AS # 1
CLS
P=0
PRINT "Name", "Address", "Phone"
WHILE NOT EOF(1)
INPUT #1, n$, a$, p$
PRINT n$, a$, p$
P=p+1
WEND
PRINT “Total number of records=”;p
CLOSE #1
END
3) Specification Grid 2065
Create a sequential data file "[Link]" to store name and marks obtained
in Engish, Maths and Science subjects for few students.
OPEN "[Link]" FOR OUTPUT AS #2
Top:
CLS
INPUT "Enter name=";n$
INPUT "Enter marks of English=";e
INPUT "Enter marks of Maths=";m
INPUT "Enter marks of Science=";s
WRITE #2, n$, e,m,s
INPUT "Do you want to continue(Y/N)?";Ans$
IF Ans$="y" OR Ans$="Y" THEN GOTO top
CLOSE #2
END

4) SLC 2065
Write a program to store records regarding the information of book number,
book's name writer's name in a sequential data file called "[Link]".
OPEN "[Link]" FOR OUTPUT AS #1
Avn:
INPUT "Enter book number=";n
INPUT "Enter books name=";b$
INPUT "Enter authors name=";a$
WRITE #1,n,b$,a$
INPUT "Store more records?";Ans$
IF Ans$="Y" OR Ans$="y" THEN goto avn
CLOSE #1
END

5) SLC supplementary 2065


A sequential data file "[Link]" contains [Link], Name, English,
Nepali and Maths fields. Write a program to display all the contents of the
data file.
OPEN "[Link]" FOR INPUT AS #1
CLS
PRINT "Roll no", "Name", "English", "Nepali", "Maths"
DO WHILE NOT EOF(1)
INPUT #1, r, n$, e, n, m
PRINT r, n$, e,n,m
LOOP
CLOSE #1
END

6) SLC 2066
WAP to create a sequential data file “[Link]” to store employee’s
name, address, age, gender and salary.
OPEN “[Link]” FOR OUTPUT AS # 1
DO
INPUT “Enter name”;name$
INPUT “Enter address=”;add$
INPUT “Enter age=”;age
INPUT “Enter gender=”;g$
INPUT “Enter salary=”;sal
WRITE #!, name$, add$, age, g$, sal
INPUT “Do you want to continue..?”;Ans$
LOOP WHILE UCASE$(Ans$) =”y”
CLOSE #!
END
7) SLC supplementary 2066
A data file "[Link]" consists of Book's name, Author's name and price of
books. Write a program to count and display the total number of records
present in the file.
OPEN "[Link]" FOR INPUT AS #1
CLS
c=0
PRINT "Books name", "Authors name", "Price"
DO WHILE NOT EOF(1)
INPUT #1, b$,a$,p
c=c+1
LOOP
PRINT "Total number of records=";c
CLOSE #1
END

8) SLC 2067
A sequential data file "[Link]" contains name, post and salary fields of
information about employees. Write a program to display all the information
of employees along with tax amount also. (tax is 15% of salary)
OPEN "[Link]" FOR INPUT AS #1
CLS
PRINT "Name", "post", "salary", "tax"
DO WHILE NOT EOF(1)
INPUT #1, n$, p$, s
t = (s * 15) / 100
PRINT n$, p$, s, t
LOOP
CLOSE #1
END

9) A sequential data file "information. dat" have contains name, address and
phone no. WAP to display all the information whose address is Hasanpur or
Taranagar.
CLS
OPEN "[Link]" FOR INPUT AS #1
DO WHILE NOT EOF(1)
INPUT #1,n$,a$,p
IF a$="Hasanpur" or a$="Taranagar" THEN
PRINT "Name=";n$
PRINT "Address=";a$
PRINT "Phone no=";p
ENDIF
LOOP
CLOSE #1
END

10) A data file named "[Link]" contains name, designation and salary of
employees. WAP to display all the employees record whose salary is between
10000 to 15000.
CLS
OPEN "[Link]" FOR INPUT as #3
DO WHILE NOT EOF(3)
INPUT #3, n$,d$,s
IF s>=10000 and s<=15000 THEN
PRINT "Name="n$
PRINT "Designation=";d$
PRINT "Salary=";s
ENDIF
LOOP
CLOSE #3
END
11) A sequential data file "[Link]" contains name and marks secured by
students in 3 subjects. Assuming that pass marks of each subjects is 40, write
a program to count the number of passed students.
OPEN "[Link]" FOR INPUT AS #2
DO WHILE NOT EOF(2)
INPUT #2, n$,e,m,c
IF e>=40 and m>=40 and c>=40 THEN
p=p+1
ENDIF
LOOP
CLOSE #2
PRINT "Total number of passed students=";p
END

12) WAP to create a data file "[Link]" and store name, class, roll noand
any 3 subjects marks of five students.
Also read :"110 Crucial QBasic and C Programming Solutions for SEE and Grade
10 Students"
CLS
OPEN "[Link]" FOR OUTPUT AS #2
FOR x= 1 to 5
INPUT "Enter name=";n$
INPUT "Enter Roll no.=";r
INPUT "Enter Class=";c$
INPUT "Enter Marks of English=";e
INPUT "Enter Marks of Maths=";m
INPUT "Enter Marks of Computer=";c
WRITE #2, n$,r,c$,e,m,c
NEXT x
CLOSE #2
END
13) WAP to create a sequential file "[Link]" and store item code, item
name, rate. The program should prompt the user to enter more data.
OPEN "[Link]" FOR OUTPUT AS #4
DO
INPUT "Enter item code=";c
INPUT "Enter Item name=";n$
INPUT "enter rate=";r
WRITE #4, c, n$,r
PRINT
INPUT "Do you want to conti……(y/n)";Ans$
LOOP WHILE UCASE$(Ans$)="Y"
CLOSE #4
END

14) SLC 2068


A sequential data file called ‘[Link]’ contains some records under the
fields name, English, Nepali and Computer. Write a 3 program to add some
more records in the same sequential data file.
OPEN “[Link]” FOR APPEND AS #1
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 more data=”;Ans$
IF Ans$=”Y” OR Ans$= “y” THEN GOTO top
CLOSE #1
END
15) WAP to delete some records from data file "[Link]" which has
contents name, class, roll no, and address.
CLS
OPEN "[Link]" FOR INPUT AS #1
OPEN "[Link]" FOR OUTPUT AS #2
ab:
DO WHILE NOT EOF(1)
INPUT #1, r,n$,c$,a$
PRINT "Name=";n$
PRINT "Class=";c$
PRINT "Roll no=";r
PRINT "Address=";a$
INPUT "Do you want to delete this record (y/n)";y$
IF y$="Y" or y$="y" THEN GOTO ab
ELSE
WRITE #2, r, n$, c$, a$
GOTO ab
ENDIF
LOOP
CLOSE #1, #2
KILL "[Link]"
NAME "[Link]" AS "[Link]"
END

16) Write a program to create a data file "[Link]" to add and display the
records with the help of a menu base structure.
CLS
PRINT "MAIN MENU"
PRINT "1. Add records"
PRINT "2. Display records"
PRINT : PRINT
INPUT "Enter your choice: (1/2)";ch
SELECT CASE ch
CASE 1
CALL addrecord
CASE 2
CALL disprecord
END SELECT
END
SUB addrecord
CLS
OPEN "[Link]" FOR APPEND AS #1
DO
INPUT "Enter name=";n$
INPUT "Enter class=";c$
INPUT "Enter Roll no=";r
WRITE #1,n$,c$,r
INPUT "Do you need more records to add=";Ans$
LOOP WHILE UCASE$(Ans$)="Y"
CLOSE #1
END SUB
SUB disprecord
CLS
OPEN "[Link]" FOR INPUT AS # 1
PRINT "Students Name","Class", "Roll no"
DO WHILE NOT EOF(1)
INPUT #1,n$,c$,r
PRINT n$,c$,r
LOOP
CLOSE #1
END SUB
17) A sequential data file “[Link]” contains the details of students
such as Name, roll no, class, joining date etc. WAP to update the details of the
data file “[Link]”.
CLS
OPEN “[Link]” FOR INPUT AS#1
OPEN “[Link]” FOR OUTPUT AS #2
WHILE NOT EOF(1)
INPUT #1, name$, roll, class, date$
PRINT:PRINT
PRINT “Name of the student=”;name$
PRINT “Roll number”;roll
PRINT “Class=”;class
PRINT “Joining date=”;date$
PRINT:PRINT
PRINT “Do you want to Update this record(Y/N)”
INPUT ch$
IF ch$=”Y” OR ch$=”y” THEN
INPUT “New name=”;name$
INPUT “New roll number=”;roll
INPUT “New class=”;class
INPUT New date=”;date$
ENDIF
WRITE #2, name$, roll, class, date$
WEND
CLOSE #1, #2
KILL “[Link]”
NAME “[Link]” AS “[Link]”
END

18) A sequential data file “[Link]” contains name, address and


phone number of the students. WAP to enter a telephone number from the
keyboard, match the telephone number with the telephone number stored in
the file. If the telephone number matched then display “Record found”
otherwise display “Record not found”
OPEN “[Link]” FOR INPUT AS#1
CLS
INPUT “Enter telephone number=”;tel$
WHILE NOT EOF(1)
INPUT #1, n$, a$, ph$
IF(ph$=tel$) THEN
PRINT “Record found”
ELSE
PRINT “Record not found”
ENDIF
PRINT “Name=”;n$
PRINT “Address=”;a$
PRINT “Telephone number”;ph$
WEND
CLOSE #!
END
19) SLC 2069
Write a program to create a data file ‘[Link]’ to store Name, Address and
Telephone number of employee according to the need of the user.
OPEN “[Link]” FOR OUTPUT AS #1
DO
INPUT “Enter Name:”n$
INPUT “Enter address:”;a$
INPUT “Enter telephone no:”;t$
WRITE #1, n$,a$,t$
INPUT “Do you want to add more records (Y/N)?”;ch$
LOOP WHILE UCASE$(ch$)= “Y”
CLOSE #!
END

20) SLC 2070


A sequential data file called “[Link]” contains name, English, Nepali,
Math's and Science fields. Write a program to display all the contents of that
data file.
OPEN “[Link]” FOR INPUT AS #1
CLS
PRINT “Name”, “English”, “Maths”, “Science”, “Nepali”
WHILE NOT EOF(1)
INPUT #1, n$, eng, math, sci, nep
PRINT n$, eng, math, sci, nep
WEND
CLOSE #1
END
21) SLC 2067 Supp.
A sequential data file called “[Link]” contains Roll no, Name, English,
Nepali, and Maths fields. Write a program to display all the contents of the
data file.
OPEN “[Link]” FOR INPUT AS #1
CLS
PRINT “Roll no”,“Name”, “English”, “Maths”, “Science”, “Nepali”
DO WHILE NOT EOF(1)
INPUT #1, r, n$, eng, math, sci, nep
PRINT r, n$, eng, math, sci, nep
LOOP
CLOSE #1
END

22) SLC 2068 Supp.


WAP to view those records from “[Link]” sequential data file having
employee’s name, department, appointment data and salary whose salary is
more than Rs 5000.
OPEN “[Link]” FOR INPUT AS #2
CLS
WHILE NOT EOF(2)
INPUT #2, n$,d$,a$,s
IF s>=5000 THEN PRINT n$,d$,a$,s
WEND
CLOSE #2
END

23) SLC 2069 Supp.


A sequential data file “[Link]” contains the name, address, post and salary
of employees. Write a program to read and display all the records in the above
data file.
OPEN “[Link]” FOR INPUT AS #1
CLS
PRINT “Name”, “Address”, “Post”, “Salary”
DO WHILE NOT EOF(1)
INPUT #1, n$,a$,p$,s
PRINT n$,a$,p$,s
LOOP
CLOSE #1
END

24) SLC 2071


A data file “[Link]” contains the information of employee regarding their
name, post and salary. Write a program to display all the information of
employee whose salasy is greater than 15000 and less than 40000
OPEN “[Link]” FOR INPUT AS #1
CLS
DO WHILE NOT EOF(1)
INPUT #1 n$,p$,sa
IF sa>15000 AND sa<40000 THEN
PRINT “Name”;n$
PRINT “Post”;p$
PRINT “Salary”;sa
ENDIF
LOOP
CLOSE #1
END
25) SLC 2070 Supp.
A sequential data file “[Link]” has records with field name, address,
age and salary. Write a program to display only those records whose age is
greater than 26.
OPEN "[Link]" FOR INPUT AS #1
PRINT "Name", "Address", "Age", "Salary"
DO WHILE NOT EOF(1)
INPUT #1, n$, a$,age, sal
IF age>26 THEN PRINT n$,a$,age,sal
LOOP
CLOSE #1
END

26) A sequential data file “[Link]” consists of numerous records of


employees of a company on the following fields: employee’s name, post, salary
and status (i.e. permanent or temporary) Write a program to read records of
the “[Link]” file and display the records of permanent employees
whose post is manager.
OPEN “[Link]” FOR INPUT AS #1
CLS
WHILE NOT EOF(1)
INPUT #1, N$, P$, S, S$
IF UCASE$(P$)= “MANAGER” AND UCASE$(S$)= “PERMANENT” THEN
PRINT N$, P$, S, S$
WEND
CLOSE #1
END
27) Data file named “[Link]” contains name, age and salary for ‘n’
number of persons. Write a program to input a name to search data from
data file. If the data is not found, then display the message “Data not found in
the list.”
OPEN “[Link]” FOR INPUT AS #1
CLS
INPUT “Enter name to search data”; S$
FLAG=0
WHILE NOT EOF(1)
INPUT #1, N$, A, S
IF UCASE$(S$)=UCASE$(N$) THEN
PRINT N$, A, S
FLAG=1
END IF
WEND
IF FLAG=0 THEN PRINT “DATA NOT FOUND”
CLOSE #1
END

28) SEE 2072


A sequential data file called “[Link]” contains NAME, AGE, CITY, and
TELEPHONE fields. Write a program to display all the contents of the data
file.
OPEN “[Link]” FOR INPUT AS #1
CLS
DO WHILE NOT EOF(1)
INPUT #1, N$, A, C$, T#
PRINT N$, A, C$, T#
LOOP
CLOSE #1
END

29) SEE 2073


Create a data file to store the records of few employees having Name, Address,
Post, Gender and Salary fields.
OPEN “[Link]” FOR OUTPUT AS #1
DO
CLS
INPUT “Enter Name”; N$
INPUT “Enter Address”; A$
INPUT “Enter Post”; P$
INPUT “Enter gender”; G$
INPUT “Enter Salary”; S
WRITE #1, N$, A$, P$, G$, S
INPUT “Do you want to continue”; CH$
LOOP WHILE UCASE$(CH$)=”Y”
CLOSE #1
END

30) SEE 2073 Supp.


A sequential data file called "[Link]" contains NAME, AGE,
CITY and TELEPHONE fields. Write a program to display all the contents
of the data file.
OPEN "[Link]" FOR INPUT AS #1
DO WHILE NOT EOF(1)
INPUT #1, n$,a,c$,t$
PRINT n$,a,c$,t$
LOOP
CLOSE #1
END

31. SEE 2074


Write a program to store Roll no., Name, Class and Address of any five
students.
OPEN "[Link]" FOR OUTPUT AS #1
FOR I = 1 TO 5
INPUT "Enter Roll No.", r
INPUT "Enter Name", n$
INPUT "Enter Class", c
INPUT "Enter Address", a$
WRITE #1, r, n$, c, a$
NEXT I
CLOSE #1
END

32. SEE 2075


A data file “[Link]” has stored records of few employees with EMPID,
First name, Last name, post and salary. Write a program to display all the
records of the employees whose salary is more than 40,000.
OPEN “[Link]” FOR INPUT AS #1
CLS
Also read :"Key Questions about Modular Programming and File Handling in
QBasic for SEE and Grade 10 Students"
WHILE NOT EOF(1)
INPUT #1, A, B$, C$, D$, E
IF E > 40000 THEN PRINT A, B$, C$, D$, E
WEND
CLOSE #1
END
33. SEE 2075(state 2)
Write a program to create a sequential data file “[Link]” to store
programmer’s Name, salary and post according to the need of the user.
OPEN “[Link]” FOR OUTPUT AS #1
DO
CLS
INPUT “Enter Name”; N$
INPUT “Enter salary”; S
INPUT “Enter Post”; P$
WRITE #1, N$, S, P$
INPUT “Do you want to continue(Y/N)”; CH$
LOOP WHILE UCASE$(CH$)=”Y”
CLOSE #1
END

34. SEE 2079


A sequential data file called "[Link]" has stored data under the field
heading: Roll no, name, gender, English, Nepali, Math's, and Computer.
Write a program to display all the information of those students whose marks
in English is more than 40.
OPEN "[Link]" FOR INPUT AS #1
DO WHILE NOT EOF(1)
INPUT #1, rn, n$, g$, eng, nep, math, comp
IF eng > 40 THEN PRINT rn, n$, g$, eng, nep, math, comp
LOOP
CLOSE #1
END
35) SEE 2078 Grade Promotion
Student name, class, section, and address are stored in a data file called
"[Link]". Write a program to print all the records of students.
OPEN "student,dat" FOR INPUT AS #5
CLS
DO WHILE NOT EOF(5)
INPUT #5, name$,cl,s$,add$
PRINT name$,cl,s$,add$
LOOP
CLOSE #5
END

36) SEE 2078


Write a program to create a sequential data file “[Link]” to store
programmer’s name, salary and post according to the need of the user.
OPEN “[Link]” FOR OUTPUT AS #1
top:
INPUT “Enter programmers name”;n$
INPUT “Enter salary”;s
INPUT “Enter post”;p$
INPUT “Do you need more records”;ch$
IF UCASE$(ch$)=”Y” then GOTO top
CLOSE #1
END

37) A sequential data file "[Link]" contains name, address, age and
salary of employee. Write a program to display all the information whose
address is "Kathmandu" and salary is greater than 50000.
OPEN "[Link]" FOR INPUT AS #2
CLS
DO WHILE NOT EOF(2)
INPUT #1,name$, add$, age, sal
IF UCASE$(add$)="KATHMANDU" AND s > 50000 THEN
PRINT name$, add$, age, sal
ENDIF
WEND
CLOSE #1
END

38) SEE grade promotion 2079


Student name, class, section and address are stored in a data file called
"[Link]". Write a program to print all the records of students.
OPEN "[Link]" FOR INPUT AS #1
CLS
DO WHILE NOT EOF(1)
INPUT #1, n$,c,s$,a$
PRINT n$,c,s$,a$
LOOP
CLOSE #1
END

39) Npabson SEE Pre-Qualifying exam-2080


A sequential data file, "[Link]" contains several records with data items
name, address, age, and phone number. Write a program to display all the
records of students whose age is greater than or equal to 18.
Ans:
OPEN "[Link]" FOR INPUT AS #1
CLS
DO WHILE NOT EOF(1)
INPUT 31, n$,a$,age,ph
IF age>=18 THEN PRINT n$, a$, age, ph
LOOP
CLOSE #1
END
40. Pabson SEE pre-board examination 2080
A sequential data file "[Link]" contains the name, address, salary of
employee, and display the records of those whose salary is more than 37000
and whose name ends with "DHA"
CLS
OPEN "[Link]" for INPUT AS #1
DO WHILE NOT EOF(1)
INPUT #1, n$,a$,s
IF s>37000 AND RIGHT$(a$,3)="DHA" THEN
PRINT "Name:";n$
PRINT "Address: ";a$
PRINT "Salary:";s
ENDIF
LOOP
CLOSE #1
END

You might also like