Cambridge AS Level Computer Science 9618 · 11.2 Constructs

Q49 · 9618/23/O/N/23 Q4

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

Q499618/23/O/N/23original Q4Structured · 7 marks
Question 4 from 9618/23/O/N/23

Worked solution

(a)

Keep a base value. Each time, add a random amount from 0 up to just below the step size, so the new number is always bigger than the old one. Then raise the base by the step:

PROCEDURE RandList()
    DECLARE Count, BaseNum, ThisNum : INTEGER
    CONSTANT StepVal = 10
    BaseNum ← 0
    FOR Count ← 1 TO 25
        ThisNum ← BaseNum + INT(RAND(StepVal))
        OUTPUT ThisNum
        BaseNum ← BaseNum + StepVal
    NEXT Count
ENDPROCEDURE

Procedure heading and ending [1]

Loop counter Count declared as a local INTEGER [1]

Loop that runs 25 times (one number each time) [1]

Random number made with INT and RAND inside the loop [1]

Number made greater than the previous one, and the 'previous' value updated (here BaseNum increases by StepVal) [1]

Random number output inside the loop [1]

(b)

The condition says: the next value is equal to or smaller than the current value. Write the same test as one comparison:

IF Result[x + 1] <= Result[x] THEN [1]

Result[x] >= Result[x + 1] also scores.

KEY IDEAMake each number bigger than the last by adding a random part to a base that grows every time.
TOTAL 7 marks

Official mark scheme

Mark scheme for 9618/23/O/N/23 question 4
VIDEO
▶ Starts at Q4 (55:26)

Starts at Q4 (55:26) · by Zafar Ali Khan (ZAK). 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.