Chapter at a glance
Complete study guide and programming solutions for Class 10 Computer Science Unit 10 File Handling in QBASIC, covering file modes (OUTPUT, INPUT, APPEND), file I/O statements (WRITE#, INPUT#, LINE INPUT#), the EOF() function, and full programs for creating, reading, and filtering data records.
- Sequential File Modes: OUTPUT vs INPUT vs APPEND
- File Opening and Closing Statements: OPEN, CLOSE
- Data Writing and Reading: WRITE# vs PRINT#, INPUT#
- The EOF() Function and While Loops
- File Management Programs: Student Records and Filtering
Exam focus: Writing complete QBASIC programs to create and display sequential data files, explaining OUTPUT vs APPEND mode differences, and utilizing EOF() correctly.
Key formulas and definitions
- File loop template: WHILE NOT EOF(1) ... INPUT #1, vars ... WEND
On this page (9 sections)
- The lesson in short
- Section A: File Concepts, Modes, and File I/O Statements
- File ModesSequential File Opening Modes
- Section B: Complete Solved File Handling Programs
- Create FileProgram 1: Create a Sequential File and Store Student Records
- Read FileProgram 2: Read and Display All Records from File
- Filter FileProgram 3: Filter and Display High-Achieving Students
- Section C: Textbook Review Questions & Answers
- Review Q&AConceptual Review Q&A
Solutions and answers
The lesson in short
File handling in QBASIC provides persistent secondary storage capabilities, enabling programs to store, retrieve, update, and manage structured records on disk beyond temporary computer memory.
While variables vanish from RAM when a program terminates, data files preserve customer accounts, student databases, inventory stocks, and employee payrolls reliably across sessions.
This chapter covers file modes (OUTPUT, INPUT, APPEND), file manipulation statements (OPEN, CLOSE, WRITE#, PRINT#, INPUT#, LINE INPUT#), file status functions (EOF, LOF, LOC), and practical record-management programs aligned with the CDC Class 10 syllabus.
Section A: File Concepts, Modes, and File I/O Statements
File ModesSequential File Opening Modes
| Access Mode | Syntax Pattern | Operating Purpose & Pointer Behavior | Existing File Overwrite Risk |
|---|---|---|---|
| OUTPUT | OPEN "filename.dat" FOR OUTPUT AS #1 | Creates a new sequential file for writing data; positions pointer at beginning | Destructive: Overwrites existing file data completely |
| INPUT | OPEN "filename.dat" FOR INPUT AS #1 | Opens an existing sequential file for reading data; pointer at beginning | Read-only mode; runtime error if file does not exist |
| APPEND | OPEN "filename.dat" FOR APPEND AS #1 | Opens file for writing new records at the end of the existing file | Safe: Preserves existing records; appends new data to the end |
| Statement / Function | Syntax Template | Specific Functionality in File Handling |
|---|---|---|
| OPEN | OPEN file$ FOR mode AS #file_num | Associates an external disk file with an internal file stream buffer number |
| CLOSE | CLOSE #1, #2 (or CLOSE) | Flushes cached memory buffers to disk and terminates file association |
| WRITE # | WRITE #1, name$, roll%, marks! | Writes formatted records to disk, automatically inserting delimiters and quotes around strings |
| INPUT # | INPUT #1, name$, roll%, marks! | Reads delimited record values sequentially from disk file into designated variables |
| LINE INPUT # | LINE INPUT #1, line_str$ | Reads an entire line of text up to the carriage return into a single string variable |
| EOF() | WHILE NOT EOF(1) | End-of-File boolean function; returns True (-1) when the end of file is reached |
Section B: Complete Solved File Handling Programs
Create FileProgram 1: Create a Sequential File and Store Student Records
Write a QBASIC program to create a sequential data file named "STUDENT.REC" and store Name, Roll Number, Class, and Total Marks for N students.
CLS
OPEN "STUDENT.REC" FOR OUTPUT AS #1
INPUT "How many student records do you want to add? ", n%
FOR i% = 1 TO n%
PRINT "--- Student #"; i%; " ---"
INPUT "Enter Student Name: ", sname$
INPUT "Enter Roll Number: ", roll%
INPUT "Enter Class: ", cls%
INPUT "Enter Total Marks: ", marks!
WRITE #1, sname$, roll%, cls%, marks!
NEXT i%
CLOSE #1
PRINT "Records successfully written to STUDENT.REC."
END
Read FileProgram 2: Read and Display All Records from File
Write a QBASIC program to read and display all student records stored in "STUDENT.REC" in tabular format.
CLS
OPEN "STUDENT.REC" FOR INPUT AS #1
PRINT "========================================================="
PRINT "NAME ROLL CLASS MARKS"
PRINT "========================================================="
WHILE NOT EOF(1)
INPUT #1, sname$, roll%, cls%, marks!
PRINT sname$; TAB(22); roll%; TAB(33); cls%; TAB(44); marks!
WEND
PRINT "========================================================="
CLOSE #1
END
Filter FileProgram 3: Filter and Display High-Achieving Students
Write a program to display only those students from "STUDENT.REC" whose Total Marks are 80 or above.
CLS
OPEN "STUDENT.REC" FOR INPUT AS #1
PRINT "Distinction Students (Marks >= 80):"
PRINT "---------------------------------------------------------"
count% = 0
WHILE NOT EOF(1)
INPUT #1, sname$, roll%, cls%, marks!
IF marks! >= 80 THEN
PRINT "Name: "; sname$; " | Roll: "; roll%; " | Marks: "; marks!
count% = count% + 1
END IF
WEND
IF count% = 0 THEN PRINT "No student scored 80 or above."
CLOSE #1
END
Section C: Textbook Review Questions & Answers
Review Q&AConceptual Review Q&A
1. What is the difference between OUTPUT mode and APPEND mode in QBASIC file handling?
Both OUTPUT and APPEND modes are used to write data into a sequential data file. However, if a file already exists on disk, opening it in OUTPUT mode completely deletes and overwrites all existing data, starting fresh from the beginning. In contrast, opening an existing file in APPEND mode strictly preserves all previously stored records and places the write pointer at the very end of the file, allowing new records to be safely added without data loss.
2. What is the purpose of the EOF() function in QBASIC file processing?
The `EOF()` (End of File) function checks whether the file read pointer has reached the end of an open sequential data file. It returns a boolean value: False (0) as long as records remain to be read, and True (-1) when no further data exists. It is most commonly used in a `WHILE NOT EOF(file_number)` loop to read all records sequentially without triggering an "Input past end of file" runtime error.
Frequently asked questions
What is File Handling in QBASIC about?
Complete study guide and programming solutions for Class 10 Computer Science Unit 10 File Handling in QBASIC, covering file modes (OUTPUT, INPUT, APPEND), file I/O statements (WRITE#, INPUT#, LINE INPUT#), the EOF() function, and full programs for creating, reading, and filtering data records.
Which topics are covered in File Handling in QBASIC?
Class 10 Computer Science “File Handling in QBASIC” covers: Sequential File Modes: OUTPUT vs INPUT vs APPEND; File Opening and Closing Statements: OPEN, CLOSE; Data Writing and Reading: WRITE# vs PRINT#, INPUT#; The EOF() Function and While Loops; File Management Programs: Student Records and Filtering.
What should I focus on in File Handling in QBASIC for the exam?
Writing complete QBASIC programs to create and display sequential data files, explaining OUTPUT vs APPEND mode differences, and utilizing EOF() correctly.
What are the key formulas or definitions in File Handling in QBASIC?
File loop template: WHILE NOT EOF(1) ... INPUT #1, vars ... WEND.
Where can I read the Class 10 Computer Science “File Handling in QBASIC” solutions?
Right on this page. They are free and you do not need to sign up. For chapter quizzes and the AI tutor, install the Sikshya Plus app.
Study tips
Do not just read it. Practice it.
You have read the solutions for File Handling in QBASIC. Now test yourself, ask the AI tutor and keep your streak going.




- AI quizzes for this chapterTest yourself with instant feedback and explanations after every answer.
- AI tutor, free, 24/7Stuck on a question? Ask in your own words and get a step-by-step explanation.
- 14 AI tools in one appSummarizer, grammar checker, flashcards, essay help, math solver and more.
- Past questions and notesPast papers and your own notes organized chapter by chapter.