Worked solution from the Data Types and Structures Paper 2 Problem-solving and Programming booklet, Part 2 of 4.
Go through the five boundaries. For each one, work out the range from 2 below to 2 above and check if the mark is inside it.
FUNCTION CheckMark(Mark : INTEGER) RETURNS BOOLEAN
DECLARE Index, Lower, Upper : INTEGER
FOR Index ← 1 TO 5
Lower ← GradeBoundary[Index] - 2
Upper ← GradeBoundary[Index] + 2
IF Mark >= Lower AND Mark <= Upper THEN
RETURN TRUE
ENDIF
NEXT Index
RETURN FALSE
ENDFUNCTIONLoop through all five elements of GradeBoundary [1]
Attempts to work out the range (Lower and Upper) inside the loop [1]
The range is completely correct (boundary - 2 to boundary + 2) [1]
Tests if the mark is in the range inside the loop [1]
Returns TRUE (or sets a variable) when a recheck is needed, inside the loop [1]
Returns a Boolean in both cases [1]
Another accepted way: a CASE OF statement with five ranges and OTHERWISE returning FALSE.
Loop through the candidates. For each mark that needs checking, write the ID to the file and add 1 to the count. Output the count after the loop.
PROCEDURE CheckAll(CNum : INTEGER)
DECLARE Index, Count, ThisMark : INTEGER
Count ← 0
OPENFILE "GRList.txt" FOR WRITE
FOR Index ← 1 TO CNum
ThisMark ← Result[Index, 1]
IF CheckMark(ThisMark) = TRUE THEN
WRITEFILE "GRList.txt", NUM_TO_STR(Result[Index, 2])
Count ← Count + 1
ENDIF
NEXT Index
CLOSEFILE "GRList.txt"
OUTPUT "There are ", Count, " papers to check"
ENDPROCEDUREProcedure heading, parameter and ending [1]
File opened in WRITE mode and closed afterwards [1]
Loop through all CNum candidates [1]
Gets the mark from column 1 of Result inside the loop [1]
Calls CheckMark() with the mark inside the loop [1]
Tests the result and, if TRUE, adds 1 to Count inside the loop [1]
Writes the ID to the file inside the loop, converted to a string [1]
Outputs a message with the count after the loop [1]
Write: the file must be opened in APPEND mode instead of WRITE mode [1]
▶ Whole paper
Video solution of the whole paper · 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.