Cambridge AS Level Computer Science 9618 · 12.3 Program Testing and Maintenance

Q42 · 9618/23/O/N/22 Q6

Worked solution from the Software Development Paper 2 Problem-solving and Programming booklet, Part 3 of 3.

Q429618/23/O/N/22original Q6Structured · 11 marks
Question 6 from 9618/23/O/N/22

Worked solution

(a)

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 numberComponent weightMinMaxExpected return value
1300290315'A'
2320290315'R'
3317290315'C'
4288290315'C'
5286290315'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'.

(b)

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
ENDFUNCTION

Function 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]

KEY IDEATest each outcome and each boundary, and in the code check the limits with the right greater-than and less-than signs.
TOTAL 11 marks

Official mark scheme

Mark scheme for 9618/23/O/N/22 question 6
VIDEO
▶ 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.