Cambridge O Level Computer Science 2210 · 7.9 Writing and amending algorithms

Q112 · 2210/22/M/J/25 Q7

Worked solution from the Algorithm design and problem-solving Paper 2 Algorithms, Programming and Logic booklet, Part 8 of 8.

Q1122210/22/M/J/25original Q7Structured · 10 marks
Question 7 from 2210/22/M/J/25

Worked solution

(a)

Fill in each empty box using what the question says. The algorithm inputs a value, rejects it if it is out of range (and inputs again), otherwise adds it to the total and counts it. It stops when 50 values are accepted.

Top parallelogram: INPUT Value [1]

First decision (Yes goes back to the input, No continues left): IS Value <= -20 OR Value >= 50 ? [1]

Left process box (No branch): Total ← Total + Value [1]

Second process box: Count ← Count + 1 [1]

Second decision (Yes continues down, No goes back to the input): IS Count = 50 ? [1]

The two output parallelograms: OUTPUT Total and then OUTPUT Total / 50 [1]

(b)

To keep every value, use an array and a second loop:

Change INPUT Value so that each accepted value is saved into an array, for example Numbers[Count] ← Value [1]

... using the counter as the index [1]

After the first loop (outside it), add a second loop that repeats 50 times [1]

Inside the second loop add an OUTPUT that outputs the array content at the counter position, for example OUTPUT Numbers[Count] [1]

KEY IDEATotalling and counting go inside the loop, the averaging goes after it, and an array lets you keep every value to output later.
TOTAL 10 marks

Official mark scheme

Mark scheme for 2210/22/M/J/25 question 7
VIDEO
▶ Topic lesson

A lesson on this topic · by Mr Bulmer's Learning Zone. 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.