Cambridge AS Level Computer Science 9618 · 10.2 Arrays

Q34 · 9618/23/O/N/24 Q4

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

Q349618/23/O/N/24original Q4Structured · 12 marks
Question 4 from 9618/23/O/N/24

Worked solution

(a)

There are five grade boundaries. Upper is the boundary plus 2. The mark is within range if it is at least Lower and at most Upper.

FOR Index ← 1 TO 5
    Lower ← GB[Index] - 2
    Upper ← GB[Index] + 2
    IF Mark >= Lower AND Mark <= Upper THEN
        OUTPUT "Check this paper"
    ENDIF
NEXT Index

5 [1]

GB[Index] + 2 (or Lower + 4) [1]

>= Lower [1]

<= Upper [1]

(b)(i)

Use the mark as an index.

Use Mark as the index of the Check array [1]

If that element is TRUE, the paper must be checked [1]

(b)(ii)

Set every element to FALSE first. Then for each boundary set the five elements from boundary - 2 to boundary + 2 to TRUE.

PROCEDURE GBInitialise()
    DECLARE GBIndex, GBMark, ThisIndex : INTEGER
    FOR ThisIndex ← 0 TO 75
        Check[ThisIndex] ← FALSE
    NEXT ThisIndex
    FOR GBIndex ← 1 TO 5
        GBMark ← GB[GBIndex]
        FOR ThisIndex ← GBMark - 2 TO GBMark + 2
            Check[ThisIndex] ← TRUE
        NEXT ThisIndex
    NEXT GBIndex
ENDPROCEDURE

Procedure heading and ENDPROCEDURE [1]

All elements of Check set to FALSE first [1]

Loop through the GB array [1]

Boundary mark taken from GB [1]

Loop over the five marks from boundary - 2 to boundary + 2 [1]

Each of those Check elements set to TRUE [1]

Another way that scores: loop 0 to 75 and test each index against all five boundaries, setting TRUE or FALSE.

KEY IDEAA lookup array of TRUE/FALSE flags indexed by mark replaces repeated range checks.
TOTAL 12 marks

Official mark scheme

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

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