Solution of File's Question of QBASIC
1. Create a sequential data file "std.dat" to store Name and Mark obtained in English, Math and Science Subjects for a few students.
OPEN "std.dat" FOR OUTPUT AS #1
CLS
DO
INPUT "Enter Name";N$
INPUT "Enter Mark in English";E
INPUT "Enter Mark in Math";M
INPUT "Enter Mark in Science";S
WRITE #1,N$,E,M,S
INPUT "Do you want to enter another Record Y/N";c$
LOOP WHILE UCASE$(c$)="Y"
CLOSE #1
END
2. Write a program to create a data file "PERSON.DAT" to store person's Name, Address, Telephone number and district of N different students.
OPEN "PERSON.DAT" FOR OUTPUT AS #1
CLS
INPUT "Enter how many students";N
FOR I=1 TO N
INPUT "Enter Name";Na$
INPUT "Enter Address";A$
INPUT "Enter Telephone number";T$
INPUT "Enter district";D$
WRITE #1,Na$,A$,T$,D$
NEXT
CLOSE #1
END
3. Write a program to create a serial file having variable length records of name, department and telephone number. Telephone number should be in between 2000000 to 9999999.
OPEN "RECORD.DAT" FOR OUTPUT AS #1
CLS
DO
INPUT "Enter name";N$
INPUT "Enter department";D$
L1:
INPUT "Enter telephone number";T
IF T>2000000 AND T<9999999 THEN
WRITE #1,N$,D$,T
ELSE
GOTO L1
END IF
INPUT "Do you want to enter another data Y/N";c$
LOOP WHILE UCASE$(c$)="Y"
CLOSE #1
END
4. Write a program to create a data file STD.DAT which stores Roll number, Name, Class and age of 10 different students. Age of students must be in between 15 to 19.
OPEN "STD.DAT" FOR OUTPUT AS #1
CLS
FOR I=1 TO 10
INPUT "Enter Roll number";R
INPUT "Enter Name";N$
INPUT "Enter Class";C$
L1:
INPUT "Enter Age";A
IF A>15 AND A<19 THEN
WRITE #1,R,N$,C$,A
ELSE
GOTO L1
END IF
NEXT I
CLOSE #1
END
5. Write a program to create a data file named store.dat which stores the following data: Serial number, Book name, Author name and ISBN number. Add the data as user's choice.
OPEN "store.dat" FOR OUTPUT AS #1
CLS
DO
INPUT "Enter Serial number";SN
INPUT "Enter Name of Book";N$
INPUT "Enter Author name";A$
INPUT "Enter ISBN number";IN
WRITE #1,SN,N$,A$,IN
INPUT "Do you want to enter another data Y/N";c$
LOOP WHILE UCASE$(c$)="Y"
CLOSE #1
END
6. Write a program to create a data file named store.dat which stores the following data: Roll number, name and class of N number of students.
OPEN "store.dat" FOR OUTPUT AS #1
CLS
INPUT "Enter how many student";N
FOR I=1 TO N
INPUT "Enter Roll number";R
INPUT "Enter name";Na$
INPUT "Enter class";C$
WRITE #1,R,Na$,C$
NEXT I
CLOSE #1
END
7. Write a program to create a data file (MARK.DAT) and stores name, address and marks in any three subjects for five students.
OPEN "MARK.DAT" FOR OUTPUT AS #1
CLS
FOR I=1 TO 5
INPUT "Enter name";N$
INPUT "Enter address";A$
INPUT "Enter mark in subject 1";S1
INPUT "Enter mark in subject 2";S2
INPUT "Enter mark in Subject 3";S3
WRITE #1,N$,A$,S1,S2,S3
NEXT I
CLOSE #1
END
OPEN "std.dat" FOR OUTPUT AS #1
CLS
DO
INPUT "Enter Name";N$
INPUT "Enter Mark in English";E
INPUT "Enter Mark in Math";M
INPUT "Enter Mark in Science";S
WRITE #1,N$,E,M,S
INPUT "Do you want to enter another Record Y/N";c$
LOOP WHILE UCASE$(c$)="Y"
CLOSE #1
END
2. Write a program to create a data file "PERSON.DAT" to store person's Name, Address, Telephone number and district of N different students.
OPEN "PERSON.DAT" FOR OUTPUT AS #1
CLS
INPUT "Enter how many students";N
FOR I=1 TO N
INPUT "Enter Name";Na$
INPUT "Enter Address";A$
INPUT "Enter Telephone number";T$
INPUT "Enter district";D$
WRITE #1,Na$,A$,T$,D$
NEXT
CLOSE #1
END
3. Write a program to create a serial file having variable length records of name, department and telephone number. Telephone number should be in between 2000000 to 9999999.
OPEN "RECORD.DAT" FOR OUTPUT AS #1
CLS
DO
INPUT "Enter name";N$
INPUT "Enter department";D$
L1:
INPUT "Enter telephone number";T
IF T>2000000 AND T<9999999 THEN
WRITE #1,N$,D$,T
ELSE
GOTO L1
END IF
INPUT "Do you want to enter another data Y/N";c$
LOOP WHILE UCASE$(c$)="Y"
CLOSE #1
END
4. Write a program to create a data file STD.DAT which stores Roll number, Name, Class and age of 10 different students. Age of students must be in between 15 to 19.
OPEN "STD.DAT" FOR OUTPUT AS #1
CLS
FOR I=1 TO 10
INPUT "Enter Roll number";R
INPUT "Enter Name";N$
INPUT "Enter Class";C$
L1:
INPUT "Enter Age";A
IF A>15 AND A<19 THEN
WRITE #1,R,N$,C$,A
ELSE
GOTO L1
END IF
NEXT I
CLOSE #1
END
5. Write a program to create a data file named store.dat which stores the following data: Serial number, Book name, Author name and ISBN number. Add the data as user's choice.
OPEN "store.dat" FOR OUTPUT AS #1
CLS
DO
INPUT "Enter Serial number";SN
INPUT "Enter Name of Book";N$
INPUT "Enter Author name";A$
INPUT "Enter ISBN number";IN
WRITE #1,SN,N$,A$,IN
INPUT "Do you want to enter another data Y/N";c$
LOOP WHILE UCASE$(c$)="Y"
CLOSE #1
END
6. Write a program to create a data file named store.dat which stores the following data: Roll number, name and class of N number of students.
OPEN "store.dat" FOR OUTPUT AS #1
CLS
INPUT "Enter how many student";N
FOR I=1 TO N
INPUT "Enter Roll number";R
INPUT "Enter name";Na$
INPUT "Enter class";C$
WRITE #1,R,Na$,C$
NEXT I
CLOSE #1
END
7. Write a program to create a data file (MARK.DAT) and stores name, address and marks in any three subjects for five students.
OPEN "MARK.DAT" FOR OUTPUT AS #1
CLS
FOR I=1 TO 5
INPUT "Enter name";N$
INPUT "Enter address";A$
INPUT "Enter mark in subject 1";S1
INPUT "Enter mark in subject 2";S2
INPUT "Enter mark in Subject 3";S3
WRITE #1,N$,A$,S1,S2,S3
NEXT I
CLOSE #1
END
Comments