Cambridge AS Level Computer Science 9618 · 9.2 Algorithms

Q37 · 9618/23/M/J/24 Q2

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

Q379618/23/M/J/24original Q2Structured · 7 marks
Question 2 from 9618/23/M/J/24

Worked solution

(a)

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.

(b)

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).

KEY IDEAReading a file into an array needs a loop that runs until the end of the file with an index that moves on each time.
TOTAL 7 marks

Official mark scheme

Mark scheme for 9618/23/M/J/24 question 2
VIDEO
▶ 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.