Cambridge AS Level Computer Science 9618 · 9.2 Algorithms

Q24 · 9618/22/O/N/22 Q4

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

Q249618/22/O/N/22original Q4Structured · 7 marks
Question 4 from 9618/22/O/N/22

Worked solution

(a)

Follow the arrows: the decision "Is Index < 7" with the arrow looping back is a WHILE loop. The decision "Is Average > Last" is an IF inside it.

INPUT UserID
Average ← GetAverage(UserID)
Total ← 0
Index ← 4
WHILE Index < 7
    Last ← SameMonth[Index]
    IF Average > Last THEN
        Total ← Total + Average
    ELSE
        Total ← Total + Last
    ENDIF
    Index ← Index + 1
ENDWHILE
CALL Update(UserID, Total)

UserID input, and Average assigned from GetAverage(UserID) [1]

Total set to 0 and Index set to 4 [1]

Conditional loop that runs for Index from 4 to 6 [1]

Last assigned from SameMonth[Index] inside the loop [1]

IF … THEN … ELSE … ENDIF inside the loop [1]

Correct assignments to Total, Index incremented, and CALL Update(UserID, Total) after the loop [1]

A FOR Index ← 4 TO 6 … NEXT Index loop also scores, and a REPEAT … UNTIL Index = 7 loop also scores.

(b)

Write: pre-condition loop (also accepted: count-controlled loop). The test is made before the loop body. [1]

KEY IDEAA decision box with a line looping back is a loop; a decision box with two separate branches is an IF.
TOTAL 7 marks

Official mark scheme

Mark scheme for 9618/22/O/N/22 question 4
VIDEO
▶ Whole paper

Video solution of the whole paper · by Audere Prep. 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.