Solution of File's Question1 of QBASIC

1. A school Administrator has the following data i.e. staff name, department name and  salary in data file named "record.dat". Write a program to display all the data of school staff belongs to computer department.
OPEN "record.dat" FOR INPUT AS #1
CLS
WHILE NOT EOF(1)
INPUT  #1, SN$,DN$,S
IF UCASE$(DN$)="COMPUTER" THEN
PRINT SN$,DN$,S
WEND
CLOSE #1
END

2. Write a program to create data file "Suraj.dat" and store name, marks obtained in English, math, science and computer of students. The program terminates on user's choice.

OPEN "Suraj.dat" FOR OUTPUT AS #1
CLS
DO
INPUT "Enter store name";SN$
INPUT "Enter mark in English";E
INPUT "Enter mark in Math";M
INPUT "Enter mark in Science";S
INPUT "Enter mark in Computer";C
WRITE #1, SN$,E,M,S,C
INPUT "Do you want to enter another data Y/N";C$
LOOP WHILE UCASE$(C$)="Y"
CLOSE #1
END

3. Write a program to delete records, i.e. roll number, name and telephone number of a student from a data file "std.dat"

OPEN "std.dat" FOR INPUT AS #1
OPEN "temp.dat" FOR OUTPUT AS #2
WHILE NOT EOF(1)
INPUT  #1,RN,N$,TN
PRINT RN,N$,TN
INPUT "Do You want to delete this record Y/N";C$
IF UCASE$(C$)<>"Y" THEN
WRITE #2,RN,N$,TN
END IF
WEND
CLOSE #1,#2
KILL "std.dat"
NAME "temp.dat" AS "std.dat"
END

4. Write a menu driven BASIC program to handle the following cases:
 CASE 1: to enter data refer to name, address and phone number of 10 persons DAT into a data file ADD
 CASE 2: to display records from ADD.DAT data file


CLS
PRINT "1--> For Enter data"
PRINT "2--> For Display data"
INPUT "Enter a choice";C
SELECT CASE C
CASE 1
OPEN "ADD.DAT" FOR OUTPUT AS #1
FOR I=1 TO 10
INPUT "Enter name";N$
INPUT "Enter address";A$
INPUT "Enter phone number";PN
WRITE #1,N$,A$,PN
NEXT I
CLOSE #1
CASE 2
OPEN "ADD.DAT" FOR INPUT AS #1
WHILE NOT EOF(1)
INPUT #1,N$,A$,PN
PRINT N$,A$,PN
WEND
CLOSE #1
END SELECT
END

5. Write a program to search and display only those records whose percentage is more than 60% from the data file "RESULT.DAT" which contains student's Symbol number, Date of Birth, Total Marks, Percentage and Division.

OPEN "RESULT.DAT" FOR INPUT AS #1
CLS
WHILE NOT EOF(1)
INPUT  #1, SN,DOB$,TM,P,D$
IF P>60 THEN
PRINT  SN,DOB$,TM,P,D$
END IF
WEND
CLOSE #1
END

6. A data file "Exam.dat" has 100 records with student'name and marks in 3 subjects. Print records where marks in each subject>=45
OPEN "Exam.dat" FOR INPUT AS #1
CLS
WHILE NOT EOF(1)
INPUT #1, N$,M1,M2,M3
IF M1>=45 AND M2>=45 AND M3>=45 THEN
PRINT N$,M1,M2,M3
END IF
WEND
CLOSE #1
END

7. Write a program to count and display all the records existing in a sequential data file which name is input by the user.

OPEN "std.dat" FOR INPUT AS #1
CLS
INPUT  "Enter a name to be searched";N$
WHILE NOT EOF(1)

INPUT  #1,Na$,A$,S
IF Na$=N$ THEN
c=c+1
PRINT  Na$,A$,S
END IF
WEND
CLOSE #1
PRINT "Total record is: ";c
END

8. A data contains the names of students and marks of three subjects for N number of students. Write a program to display the data for only those students whose total marks is greater than 100 and less than 150.

OPEN "std.dat" FOR INPUT AS #1
CLS
WHILE NOT EOF(1)
INPUT #1, N$,S1,S2,S3
T=S1+S2+S3
IF T>100 AND T<150 THEN
PRINT  N$,S1,S2,S3
END IF
WEND
CLOSE #1
END

9. Write a program to store records regarding the information of Book number, Book's name and Writer's name in a sequential data file called "Library.dat".

OPEN "Library.dat" FOR OUTPUT AS #1
CLS
DO
INPUT "Enter  Book number";BN
INPUT "Enter Book's name";N$
INPUT "Enter Writer's name";WN$
WRITE #1,BN,N$,WN$
INPUT "Do you want to enter another data Y/N";C$
LOOP WHILE UCASE$(C$)="Y"
CLOSE #1
END

10. A sequential data file called "MARKS.DAT" contains Roll no, Name, English,Nepali and Maths fields. Write a program to display all the contents of the data file.

OPEN "MARKS.DAT" FOR INPUT AS #1
CLS
WHILE NOT EOF(1)
INPUT  #1,RN,N$,E,Ne,M
PRINT RN,N$,E,Ne,M

WEND
CLOSE #1
END

Comments

Unknown said…
No.4 To search the record(s) on the basis of first name

To exit from the program

Popular posts from this blog

PROGRAM TO FIND SQUARE, CUBE, SQUARE ROOT AND CUBE ROOT OF GIVEN NUMBER

PALINDROME AND ARMSTRONG PROGRAMS

PROGRAM TO DISPLAY SUM, PRODUCT, DIFFERENCE AND PRODUCT OF TWO / THREE NUMBERS