Computer Science (9-1) - 0984 CIE

File Handling

Overview

When a program stops, everything it was holding in memory vanishes. So how does a game remember your progress, or a program keep a high score between sessions? The answer is file handling: writing data out to a file that survives after the program ends, and reading it back when the program runs again.

In this lesson you will learn why programs store data in files, then learn the standard pseudocode for opening, reading from, writing to and closing a file. You will trace small routines that save and reload data so you can write file-handling code with confidence in the exam.

Objectives

  1. 1 Understand the purpose of storing data in a file to be used by a program
  2. 2 Open, close and use a file for reading and writing

Lesson Note

Data held in variables lives only in memory; close the program and it is gone. File handling is the storage and access of data in a file so it can be used again later. Without it a program could never remember anything between runs. Saved games, high-score tables, settings and records all rely on it, and 0478 expects you to read from and write to a text file using the standard pseudocode.

Available on the Green Bridge App

Download the Green Bridge CBT app on your phone or computer to access full lesson notes, practice questions, and more.

Full lesson notes with diagrams
AI-powered learning assistant
Study offline, anytime, anywhere
Available on Android, Windows, macOS, and Linux

Lesson Evaluation

Congratulations on completing the lesson on File Handling. Now that youve explored the key concepts and ideas, its time to put your knowledge to the test. This section offers a variety of practice questions designed to reinforce your understanding and help you gauge your grasp of the material.

You will encounter a mix of question types, including multiple-choice questions, short answer questions, and essay questions. Each question is thoughtfully crafted to assess different aspects of your knowledge and critical thinking skills.

Use this evaluation section as an opportunity to reinforce your understanding of the topic and to identify any areas where you may need additional study. Don't be discouraged by any challenges you encounter; instead, view them as opportunities for growth and improvement.

  1. Why does a program store data in a file rather than only in a variable? A. files run faster than variables B. data in a variable is lost when the program ends, but a file keeps it C. variables cannot hold numbers D. files do not need to be opened Answer: B
  2. Which pseudocode keyword opens a file ready to read from it? A. WRITEFILE B. CLOSEFILE C. OPENFILE name FOR READ D. EOF Answer: C
  3. What does opening a file FOR WRITE do to data already in the file? A. appends to the end B. leaves it unchanged C. overwrites it D. encrypts it Answer: C
  4. Which statement saves changes and frees a file after use? A. OPENFILE B. READFILE C. WRITEFILE D. CLOSEFILE Answer: D
  5. What does EOF(name) return when the end of the file is reached? A. the last line B. FALSE C. TRUE D. the filename Answer: C

Available on the Green Bridge App

Download the Green Bridge CBT app on your phone or computer to access full lesson notes, practice questions, and more.

Full lesson notes with diagrams
AI-powered learning assistant
Study offline, anytime, anywhere
Available on Android, Windows, macOS, and Linux

Available on the Green Bridge App

Download the Green Bridge CBT app on your phone or computer to access full lesson notes, practice questions, and more.

Full lesson notes with diagrams
AI-powered learning assistant
Study offline, anytime, anywhere
Available on Android, Windows, macOS, and Linux

Practice Mock Questions

Want to practice mock questions on File Handling? Download the Green Bridge CBT app to access mock questions and full practice assessments for this topic.

Download The App On Google Playstore

Everything you need to excel in JAMB, WAEC & NECO

Green Bridge CBT Mobile App
Personalized AI Learning Chat Assistant
Thousands of JAMB, WAEC & NECO Past Questions
Over 1200 Lesson Notes
Offline Support - Learn Anytime, Anywhere
Green Bridge Timetable
Literature Summaries & Potential Questions
Track Your Performance & Progress
In-depth Explanations for Comprehensive Learning