Worked solution from the Algorithm Design and Problem-solving Paper 2 Problem-solving and Programming booklet, Part 2 of 2.
Write five steps in words (no pseudocode):
Open the file for reading (and close it at the end) [1]
Set an index variable to 1 [1]
Repeat the next steps until the end of the file is reached [1]
Read a line from the file [1]
Store that line in the array at the index, and add 1 to the index [1]
There are six possible points; any five score.
Construct: a conditional loop (iteration) [1]
Use: to keep repeating until the end of the file is reached [1]
Alternative: a selection statement used to test the value returned by EOF() (also scores both marks if the use is given).
▶ Starts at Q2 (10:33)
Starts at Q2 (10:33) · by Pseudocode Pro. Tap the picture to open it on YouTube.
Solutions follow the official Cambridge mark schemes; marks are shown in grey. Videos are from other YouTube channels. Paper codes read component / series / year: M/J = May/June, O/N = October/November. Past-paper questions © UCLES, reproduced for classroom practice.