0% found this document useful (0 votes)
2 views17 pages

Ss2 Week 8 Handling Computer Files Using Qbasic CTND

The document outlines the process of handling computer files using QBASIC, including file creation, reading, appending, and basic operations. It explains different file modes (OUTPUT, INPUT, APPEND) and provides practical activities for creating and displaying student records. Additionally, it highlights common file handling errors and includes classwork and assignment solutions related to file operations.

Uploaded by

chimoskyvibz.14
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)
2 views17 pages

Ss2 Week 8 Handling Computer Files Using Qbasic CTND

The document outlines the process of handling computer files using QBASIC, including file creation, reading, appending, and basic operations. It explains different file modes (OUTPUT, INPUT, APPEND) and provides practical activities for creating and displaying student records. Additionally, it highlights common file handling errors and includes classwork and assignment solutions related to file operations.

Uploaded by

chimoskyvibz.14
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

Monday 2nd – Friday 6th March,

2026.

Handling Computer Files


Using QBASIC Ctnd

SS2 Computer Science


File Creation, Reading, Appending & Operations
Lesson Objectives

• Create simple sequential files using QBASIC


• Write, read and append data in files
• Perform basic file operations
• Understand common file errors
What is a Computer File?

• A file is a collection of related data stored


permanently.
• Files prevent data loss after program ends.
• Example: student records, exam scores.
File Modes in QBASIC

• OUTPUT – Creates new file (deletes old


content).
• INPUT – Reads data from existing file.
• APPEND – Adds new data without deleting old
data.
Creating a Sequential File (OUTPUT
Mode)

OPEN "[Link]" FOR OUTPUT AS #1


PRINT #1, "John", 85
CLOSE #1

Explanation:
OUTPUT creates a new file.
PRINT # writes data.
CLOSE ends file operation.
Reading a File (INPUT Mode)

OPEN "[Link]" FOR INPUT AS #1


DO WHILE NOT EOF(1)
INPUT #1, N$, S
PRINT N$, S
LOOP
CLOSE #1

EOF prevents reading beyond file.


Appending Data (APPEND Mode)

OPEN "[Link]" FOR APPEND AS #1


PRINT #1, "Mary", 92
CLOSE #1

APPEND keeps old data and adds new record.


Practical Activity 1
Task: Create a file called [Link].
Store 3 students' names and scores.

Solution Program:
OPEN "[Link]" FOR OUTPUT AS #1
FOR I = 1 TO 3
INPUT "Enter Name: ", N$
INPUT "Enter Score: ", S
PRINT #1, N$, S
NEXT I
CLOSE #1
Explanation – Activity 1

File opened in OUTPUT mode.


Loop stores 3 records.
PRINT # writes each record.
CLOSE saves and exits file.
Practical Activity 2
Task: Display records stored in [Link].

Solution Program:
OPEN "[Link]" FOR INPUT AS #1
DO WHILE NOT EOF(1)
INPUT #1, N$, S
PRINT "Name: "; N$
PRINT "Score: "; S
LOOP
CLOSE #1
Explanation – Activity 2

INPUT mode reads file.


EOF prevents errors.
Records displayed exactly as stored.
Written Classwork

1. Define a sequential file.


2. State 3 file modes in QBASIC.
3. Differentiate between OUTPUT and APPEND.
Classwork Solutions

1. A sequential file stores data line by line in order


entered.
2. OUTPUT, INPUT, APPEND.
3. OUTPUT deletes old content; APPEND keeps old
data and adds new.
Assignment

• Write a QBASIC program to:


• Create file [Link]
• Store 2 staff names and salaries
• Append 1 more staff record
• Display all records
Assignment Solution – Part 1

OPEN "[Link]" FOR OUTPUT AS #1


FOR I = 1 TO 2
INPUT "Enter Name: ", N$
INPUT "Enter Salary: ", S
PRINT #1, N$, S
NEXT I
CLOSE #1
Assignment Solution – Part 2
OPEN "[Link]" FOR APPEND AS #1
INPUT "Enter New Staff Name: ", N$
INPUT "Enter Salary: ", S
PRINT #1, N$, S
CLOSE #1

OPEN "[Link]" FOR INPUT AS #1


DO WHILE NOT EOF(1)
INPUT #1, N$, S
PRINT N$, S
LOOP
CLOSE #1
Common Errors in File Handling

• File not found – File not created.


• Input past end of file – No EOF check.
• Permission error – File not closed.

You might also like