Worked solution from the Software Development Paper 2 Problem-solving and Programming booklet, Part 3 of 3.
Test the edges of 0 to 60, a value outside it and one more normal value:
| Type of test data | Test data value | Expected outcome |
|---|---|---|
| normal | 36 | data item is accepted |
| boundary | 0 | data item is accepted |
| boundary | 60 | data item is accepted |
| abnormal | 61 | data item is rejected |
| normal | 15 | data item is accepted |
Row with 0 (accepted) [1]
Row with 60 (accepted) [1]
Row with 61 or more (abnormal, rejected) [1]
Row with another normal value, such as 15 (accepted) [1]
Use a bubble sort with a flag, and shrink the range after each pass. Swap both columns so the sensor ID stays with its value:
PROCEDURE Sort()
DECLARE Temp, J, Boundary : INTEGER
DECLARE NoSwaps : BOOLEAN
Boundary ← 1999
REPEAT
NoSwaps ← TRUE
FOR J ← 1 TO Boundary
IF Reading[J, 1] > Reading[J + 1, 1] THEN
Temp ← Reading[J, 1]
Reading[J, 1] ← Reading[J + 1, 1]
Reading[J + 1, 1] ← Temp
Temp ← Reading[J, 2]
Reading[J, 2] ← Reading[J + 1, 2]
Reading[J + 1, 2] ← Temp
NoSwaps ← FALSE
ENDIF
NEXT J
Boundary ← Boundary - 1
UNTIL NoSwaps = TRUE
ENDPROCEDUREProcedure heading and ending [1]
Conditional outer loop (REPEAT ... UNTIL) with a Boolean flag declared and set before each pass [1]
Inner FOR loop with the range 1 to 1999 (Boundary) [1]
Compare element J with element J+1 in column 1 [1]
Temp declared and the sensor values swapped [1]
The sensor ID values (column 2) swapped as well [1]
Flag set to show a swap, and the loop ends when no swap occurs [1]
Boundary reduced after each pass [1]
Other correct bubble sorts also score, for example a WHILE loop.
▶ Whole paper
Video solution of the whole paper · by Sir Sikandar Raza. 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.