Cambridge AS Level Computer Science 9618 · 10.2 Arrays

Q40 · 9618/22/O/N/25 Q4

Worked solution from the Data Types and Structures Paper 2 Problem-solving and Programming booklet, Part 2 of 4.

Q409618/22/O/N/25original Q4Structured · 13 marks
Question 4 from 9618/22/O/N/25

Worked solution

(a)

The highest score is 5 × 3 + 4 × 5 = 35, so the array needs indexes 0 to 35.

DECLARE CheckTotal : ARRAY[0:35] OF BOOLEAN
DECLARE Index : INTEGER
FOR Index ← 0 TO 35
    CheckTotal[Index] ← FALSE
NEXT Index

CheckTotal array declared [1]

Loop counter declared [1]

Loop with correct syntax and 36 passes (0 to 35) [1]

Each array element assigned FALSE [1]

(b)

Easy questions score 0, 3, 6 ... 15 (step 3). Hard questions score 0, 5, ... 20 (step 5). The total is the two added.

DECLARE EasyQ, HardQ : INTEGER
FOR EasyQ ← 0 TO 15 STEP 3
    FOR HardQ ← 0 TO 20 STEP 5
        CheckTotal[HardQ + EasyQ] ← TRUE
    NEXT HardQ
NEXT EasyQ

EasyQ starts at 0 [1]

EasyQ STEP 3 [1]

HardQ loop ends at 20 [1]

HardQ STEP 5 [1]

Index is HardQ + EasyQ (or EasyQ + HardQ) [1]

(c)

Write the steps in words:

Step 1: check that the score is between 0 and 35 [1]

Step 2: if it is not, return FALSE [1]

Step 3: use the score as the index into CheckTotal [1]

Step 4: return the value stored at that index (TRUE or FALSE) [1]

KEY IDEAUse nested loops to build every possible total once, then check a score with a direct array lookup.
TOTAL 13 marks

Official mark scheme

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

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