Worked solution from the Software Development Paper 2 Problem-solving and Programming booklet, Part 3 of 3.
Test every outcome and the boundaries. Reject is 3 g or more beyond a limit, Recheck is within 2 g of a limit, Accept is anything further inside. Using Min = 290 and Max = 315:
| Test number | Component weight | Min | Max | Expected return value |
|---|---|---|---|---|
| 1 | 300 | 290 | 315 | 'A' |
| 2 | 320 | 290 | 315 | 'R' |
| 3 | 317 | 290 | 315 | 'C' |
| 4 | 288 | 290 | 315 | 'C' |
| 5 | 286 | 290 | 315 | 'R' |
Row 1 correct [1]
Row 2 correct [1]
Row 3 correct [1]
Row 4 correct [1]
Row 5 correct [1]
Any weights in the same ranges also score, for example any value above 317 for 'R' and below 288 for 'R'.
Start with the Recheck result, then change it to Reject or Accept when those tests pass:
FUNCTION Status(Actual, Min, Max : INTEGER) RETURNS CHAR
DECLARE Result : CHAR
Result ← 'C'
IF Actual > Max + 2 OR Actual < Min - 2 THEN
Result ← 'R'
ENDIF
IF Actual < Max - 2 AND Actual > Min + 2 THEN
Result ← 'A'
ENDIF
RETURN Result
ENDFUNCTIONFunction heading and ending, with the parameters [1]
A local variable declared for the result [1]
Check for Reject [1]
Check for Accept [1]
Check for Recheck (or just use it as the default result) [1]
Result returned after a reasonable attempt [1]
▶ Starts at Q6 (11:58)
Starts at Q6 (11:58) · by Zafar Ali Khan (ZAK). 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.