Programming · 4 question types
Past paper frequency (2018 to 2024)
This topic accounts for approximately 3% of your exam marks.
OPENFILE, READFILE, WRITEFILE, CLOSEFILE pseudocode operations appear occasionally.
Example — Write a pseudocode algorithm that prompts the user for a book's title and year of publication, then permanently saves the data by appending it to an existing text file called books.txt.
A full-mark answer:
INPUT Title
INPUT Year
OPENFILE "books.txt" FOR APPEND
WRITEFILE "books.txt", Title
WRITEFILE "books.txt", Year
CLOSEFILE "books.txt"
Mark-scheme split (typically):
| Step | Mark |
|---|---|
| Input both the title and the year from the user | 1 |
Open books.txt in an appropriate mode (APPEND keeps existing records) | 1 |
| Write the title and the year to the file | 1 |
| Close the file | 1 |
Important: APPEND is the right mode here because the question says "permanently stores ... to the existing text file". Using
WRITEinstead would destroy the existing records.