File Handling Programs In QBASIC Class 10

File Handling Programs In QBASIC Class 10


File Handling Programs In QBASIC Class 10

1.      Write a program to store Roll no., Name, Class, and Address of a student in a sequential file named “Student.dat”.

OPEN “student.dat” FOR OUTPUT AS #1

CLS

INPUT” Enter roll number”; RN

INPUT” Enter name”; N$

INPUT” Enter class”; C

INPUT” Enter address”; A$

WRITE #1, RN, N$, C, A$

CLOSE #1

END

 

2.      Write a program to store Roll no., Name, Class, and Address of any five students.

OPEN “STD.DAT” FOR OUTPUT AS #1

CLS

FOR I = 1 TO 5

INPUT” Enter roll number”; RN

INPUT” Enter name”; N$

INPUT” Enter class”; C

INPUT” Enter address”; A$

WRITE #1, RN, N$, C, A$

NEXT I

CLOSE #1

END

 

3.      Write a program to store student name, class, and address of some students in a sequential file “Std.dat”. The user should be able to store as many records as he/she wants.  

OPEN “std.dat” FOR OUTPUT AS #1

CLS

DO

INPUT” Enter name”; N$

INPUT” Enter class”; C

INPUT” Enter address”; A$

WRITE #1, RN, N$, C, A$

INPUT” Do you want to continue? (Y/N)”; a$

LOOP WHILE UCASE$(a$) =”Y”

CLOSE #1

END

 

 

4.      Write a program to store employee name department, post, and salary in a sequential file “Emp.dat”

OPEN ”Emp.dat” FOR OUTPUT AS #1

CLS

INPUT “Enter name”; name$

INPUT” Enter department”; depart$

INPUT “Enter post”; post$

INPUT” Enter salary”; salary

WRITE #1, name$, depart$, post$, salary

CLOSE #1

END

 

 

5.      Write a program to create a data file ‘teldir.dat’ to store the Name, Address, and Telephone number of employees 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(Y/N)”; ans$

LOOP WHILE UCASE$(ans$) = ”Y”

CLOSE #1

END

 

6.      Create a data file to store the records of a few employees having Name, Address, Post, Gender, and Salary fields.

OPEN “std.dat” FOR OUTPUT AS #1

CLS

DO

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?(Y/N)”; ans$

LOOP WHILE UCASE$(ans$) = ”Y”

CLOSE #1

END

 

7.      Write a program to read and display the record of a student from the sequential file “std.dat” which has the fields as roll no, student name, class, and address.

OPEN “std.dat” FOR INPUT AS #1

CLS

PRINT “Roll No”, “Name”, “Class”, “Address”

INPUT #1, RN, N$, C, A$

PRINT RN, N$, C, A$

CLOSE #1

END

 

8.      Write a program to read and display all the records of a student from the sequential file “student.dat”. The file has the fields as roll no, student name, class, and address.

OPEN “student.dat” FOR INPUT AS #1

CLS

PRINT “Roll No”, “Name”, “Class”, “Address”

DO WHILE NOT EOF(1)

INPUT #1, RN, N$, C, A$

PRINT RN, N$, C, A$

LOOP

CLOSE #1

END

  

9.      A sequential data file called “Marks.dat” contains NAME, AGE, CITY, and TELEPHONE fields. Write a program to display all the contents of the data file.

OPEN “Marks.dat” FOR INPUT AS #1

CLS

PRINT “Name”, “Age”, “City”, “Telephone”

DO WHILE NOT EOF (1)

INPUT #1, N$, A, C$, T$

PRINT N$, A, C$, T$

LOOP

CLOSE #1

END

 

 

10.  A sequential data file “EMP.DAT” 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 “EMP.DAT” FOR INPUT AS #1

CLS

DO WHILE NOT EOF (1)

INPUT#1, NAME$, POST$, SALARY

TAX= (15/100) * SALARY

PRINT NAME$, POST$, SALARY, TAX

LOOP

CLOSE # 1

END

 

11.  A sequential data file called “Marks.dat” contains Name, English, Nepali, Math’s and Science Fields. Write a program to display all the contents of that data file. 

OPEN “Marks.dat” FOR INPUT AS #1

CLS

PRINT “NAME”, “ENGLISH”, “NEPALI”, “MATHS”, “SCIENCE”

DO WHILE NOT EOF (1)

INPUT #1, N$, E, N, M, S

PRINT N$, E, N, M, S

LOOP

CLOSE #1

END

 

 

 

12.  A data file “Salary.Dat” contains the information of employees regarding their name, post, and salary. Write a program to display all the information of employees whose salary is greater than 15000 and less than 40000.

OPEN “Salary.dat” FOR INPUT AS #1

CLS

DO WHILE NOT EOF (1)

INPUT #1, N$, P$, S

IF S>15000 AND S<40000 THEN

PRINT N$, P$, S

END IF

LOOP

CLOSE #1

END

 

13.  Write a program to add some more record in a sequential file “Student.dat”. It has fields as student name, age, class and address.

OPEN “Student.dat” FOR APPEND AS #1
CLS

DO

INPUT “Enter name”; N$

INPUT” Enter age”; A

INPUT” Enter Class”; C

INPUT” Enter Address”; Add$

WRITE #1, N$, A, C, Add$

INPUT” Do you want to add more?(Y/N)”; a$

LOOP WHILE UCASE$(a$)=”Y”

CLOSE #1

END

14.  Write a program to add few more record in an existing file “EMP.dat”. The fields are employee id, name, post, and salary

OPEN “EMP.dat” FOR APPEND AS #1
CLS

DO
INPUT “Enter employee id”; ID

INPUT” Enter name”; N$

INPUT” Enter post”; P

INPUT” Enter salary”; S

WRITE #1, ID, N$, P, S

INPUT” Do you want to add more? (Y/N)”; a$

LOOP WHILE UCASE$(a$)=”Y”

CLOSE #1

END

  

15.  A sequential data file called “student.dat” contains some records under the field’s name, English, Nepali, and Computer. Write a program to add some more records in the same sequential data file.

OPEN “student.dat” FOR APPEND AS #1
CLS

DO
INPUT “Enter name”; N$
INPUT “Enter marks in English”; E
INPUT “Enter marks in Nepali”; N
INPUT “Enter marks in Computer ”; C
WRITE #1, N$, E, N, C
INPUT “DO YOU WANT TO CONTINUE? (Y/N)”; c$
LOOP WHILE UCASE$(c$) = “Y”
CLOSE #1
END 

 

17.  A data file “STAFF.dat” 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 “STAFF.dat” FOR INPUT AS #1

CLS

DO WHILE NOT EOF (1)

INPUT #1, ID, F$, L$, P$, S

IF S > 40000 THEN

PRINT ID, F$, L$, P$, S

LOOP 

CLOSE #1

END

 

 18. Write a program to make a duplicate copy of the sequential file "Std.dat" having the fields student name, class, age, and address.


OPEN"Std.dat" FOR INPUT AS #1

OPEN"Duplicate.dat" FOR OUTPUT AS #2

CLS

DO WHILE NOT EOF(1)

INPUT #1, N$, C, A, ADD$

WRITE #2, N$, C, A, ADD$

LOOP

CLOSE #1

CLOSE #2

END

  

19. A sequential file "Marks.dat" has fields as English, Math, Computer. Write a program to update the marks of a Computer field by adding 10 marks in the previous marks of a Computer.


OPEN"Marks.dat" FOR INPUT AS #1

OPEN"Duplicate.dat" FOR OUTPUT AS #2

CLS

DO WHILE NOT EOF(1)

INPUT #1, ENG, MATH, COM

COM=COM+10

WRITE #2, ENG, MATH, COM

LOOP

CLOSE #1

CLOSE #2

KILL "Marks.dat"

NAME "Duplicate.dat" AS "Marks.dat"

END



20. Write a program to delete all the records whose address is butwal from the sequential file "Student.dat". The fields are student name, class, and address.


OPEN"Student.dat" FOR INPUT AS #1

OPEN"Duplicate.dat" FOR OUTPUT AS #2

CLS

DO WHILE NOT EOF(1)

INPUT #1, NAME$, CLASS, ADDRESS$

IF ADDRESS<> "butwal" THEN

WRITE #2, NAME$, CLASS, ADDRESS$

LOOP

CLOSE #1

CLOSE #2

KILL "Student.dat"

NAME "Duplicate.dat" AS "Student.dat"

END


Comments

Post a Comment