Cambridge AS Level Computer Science 9618 · 9.2 Algorithms

Q46 · 9618/23/O/N/25 Q2

Worked solution from the Algorithm Design and Problem-solving Paper 2 Problem-solving and Programming booklet, Part 2 of 2.

Q469618/23/O/N/25original Q2Structured · 8 marks
Question 2 from 9618/23/O/N/25

Worked solution

(a)

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.

(b)

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.

KEY IDEAStepwise refinement breaks the task into small ordered steps: open, loop, test, write, move on.
TOTAL 8 marks

Official mark scheme

Mark scheme for 9618/23/O/N/25 question 2
VIDEO
▶ 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.