Worked solution from the Algorithm Design and Problem-solving Paper 2 Problem-solving and Programming booklet, Part 2 of 2.
Write the steps in words, not pseudocode. Any six of these:
Open the text file in append mode (and close it after the loop) [1]
Set a variable to 1 to use as the array index [1]
Use the variable as the index to get an element of the array, in a loop [1]
Test whether the element is blank (an empty string) [1]
If it is not blank, write it to the file on a new line [1]
Add 1 to the variable [1]
Repeat until all 65 elements have been checked. This step earns no extra mark: any 6 of these 7 points score.
Construct: Selection (an IF statement) [1]
Use: to test whether the array element is blank before writing it [1]
Another answer that scores: Sequence – the steps must be carried out in the correct order for the task to work.
▶ Topic lesson
A lesson on this topic · by Craig'n'Dave. 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.