Lesson Plan

Lesson Plan
Grade: Date: 17/01/2026
Subject: Computer Science
Lesson Topic: Open, read, write and close files
Learning Objective/s:
  • Describe the four fundamental file operations (open, read, write, close).
  • Explain how different file modes affect creation, truncation, and appending of files.
  • Write pseudo‑code to read a text file sequentially and to write data to a new file.
  • Identify common file‑handling errors and apply appropriate error‑checking techniques.
  • Demonstrate why closing a file is essential for data integrity.
Materials Needed:
  • Projector or interactive whiteboard
  • Computer lab with IDE (e.g., Python or Java) installed
  • Sample text files (students.txt, scores.txt) on USB or printed
  • Worksheet with pseudo‑code exercises
  • Handout of the file‑mode table
  • File‑explorer access for checking created files
Introduction:
Imagine a game that needs to remember high scores after it’s closed. Students already understand variables and loops, so they can see how persistent storage extends program functionality. By the end of the lesson they will be able to open, read, write, and close files correctly and explain why each step matters.
Lesson Structure:
  1. Do‑now (5’) – Quick quiz on why data persistence is needed.
  2. Mini‑lecture (10’) – Review the four file operations and file modes; display the mode table.
  3. Guided demo (15’) – Open a file in the IDE, read lines sequentially, and display output.
  4. Pair programming (15’) – Write pseudo‑code to read a text file line‑by‑line.
  5. Whole‑class walkthrough (10’) – Write pseudo‑code to create a file and write three lines; discuss error handling.
  6. Worksheet activity (10’) – Identify errors in given snippets and choose the correct file mode.
  7. Exit ticket (5’) – One‑sentence summary of why closing a file is essential.
Conclusion:
We recap the four operations, the purpose of each file mode, and the necessity of closing files to flush data. Students submit their exit tickets and receive a homework task to create a small program that records a user’s name and score to a file. This reinforces the full file‑handling cycle.