Cambridge AS Level Computer Science 9618 · 10.2 Arrays

Q29 · 9618/23/M/J/24 Q4

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

Q299618/23/M/J/24original Q4Structured · 11 marks
Question 4 from 9618/23/M/J/24

Worked solution

(a)

Use two loops one after the other. Each one stops when a zero is entered.

PROCEDURE TwoParts()
    DECLARE NextNum, Average : REAL
    TotalA ← 0.0
    TotalB ← 0.0
    REPEAT
        INPUT NextNum
        TotalA ← TotalA + NextNum
    UNTIL NextNum = 0
    REPEAT
        INPUT NextNum
        TotalB ← TotalB + NextNum
    UNTIL NextNum = 0
    Average ← (TotalA + TotalB) / 2
    OUTPUT "The average is ", Average
ENDPROCEDURE

Procedure heading and ending [1]

Local variables declared (NextNum and Average) [1]

TotalA and TotalB set to 0 at the start [1]

First conditional loop that adds to TotalA until zero is entered [1]

Second conditional loop that adds to TotalB until zero is entered [1]

Average of the two totals worked out and output with a message [1]

(b)(i)

Write: a 1D array [1]

It holds 20 real values [1]

(b)(ii)

Write any three of these:

Many values are held under one identifier, so fewer variable names are needed [1]

The values are easier to process, search or access, for example with a loop and an index [1]

The program is easier to write, understand, maintain, test or debug [1]

KEY IDEAWhen the number of similar values grows, use an array so one loop and one name can handle them all.
TOTAL 11 marks

Official mark scheme

Mark scheme for 9618/23/M/J/24 question 4
VIDEO
▶ Starts at Q4 (27:54)

Starts at Q4 (27:54) · 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.