Worked solution from the Data Types and Structures Paper 2 Problem-solving and Programming booklet, Part 2 of 4.
Input the first value and store it. Then keep inputting while the array is not full and each value is bigger than the one before.
PROCEDURE Store()
DECLARE ThisNum, LastNum : REAL
DECLARE Index : INTEGER
INPUT ThisNum
LastNum ← ThisNum
Number[1] ← ThisNum
INPUT ThisNum
Index ← 2
WHILE Index < 21 AND ThisNum > LastNum
Number[Index] ← ThisNum
LastNum ← ThisNum
Index ← Index + 1
IF Index < 21 THEN
INPUT ThisNum
ENDIF
ENDWHILE
OUTPUT Index - 1, " values were stored in the array"
ENDPROCEDURELocal variables declared: Index as INTEGER, ThisNum and LastNum as REAL [1]
First value input and assigned to the first element [1]
Attempt at a conditional loop with both tests (array not full, value larger than previous) [1]
Completely correct conditional loop with both tests [1]
Inside the loop: value assigned to the current element when larger, and the next value input [1]
After the loop: output of the count of values stored with a message [1]
A count-controlled FOR loop with a BREAK (or similar exit) also scores.
Any two of these:
The number of values is not fixed, so it is not limited to the size of the array [1]
The data is stored permanently (non-volatile), so another program can use it without the values being typed in again [1]
Each real value must be converted to a string before it is written. [1]
▶ Whole paper
Video solution of the whole paper · by CSFeedbySirNisarAli. 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.