Worked solution from the Software Development Paper 2 Problem-solving and Programming booklet, Part 3 of 3.
The lines are output in the wrong order, not as they appear in the file. [1]
Description:
The last line of the file is not always stored in Buffer[3]. [1]
So the FOR loop that outputs Buffer[1] to Buffer[3] gives the lines in the wrong sequence. [1]
Explanation (any two of these):
Use a shuffle: copy Buffer[2] to Buffer[1] and Buffer[3] to Buffer[2] [1]
Then read the next line from the file and store it in Buffer[3] [1]
Another way: remember the index of the last line stored, and output starting after it, wrapping round using MOD 3. Or read the file once to count the lines, close and reopen it, discard lines up to the count minus 3, then read and output the last three.
The correct output happens when the number of lines in the file is a multiple of three. [1]
Use MOD to wrap the counter from 3 back to 1:
LineNum ← (LineNum MOD 3) + 1
An assignment to LineNum that uses MOD [1]
The statement is completely correct [1]
((LineNum + 3) MOD 3) + 1 is also accepted.
▶ Whole paper
Video solution of the whole paper · by Digify ID. 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.