9618/22/O/N/22 question 6: worked solution (October/November 2022, paper 22)

Show as plain text

Cambridge AS Level Computer Science 9618 · 12.3 Program Testing and Maintenance Worked solution from the Software Development Paper 2 Problem-solving and Programming booklet, Part 3 of 3. Q41 9618/22/O/N/22 original Q6 Structured · 11 marks Worked solution (a) Multiply 1 × 2 × 3 ... step by step. After each multiplication, compare the running product with the parameter. If they match, the current number is the BaseNumber. FUNCTION FindBaseNumber(ThisValue : INTEGER) RETURNS INTEGER DECLARE Num, Try : INTEGER Try ← 1 FOR Num ← 1 TO ThisValue Try ← Try * Num IF Try = ThisValue THEN RETURN Num ENDIF NEXT Num RETURN -1 ENDFUNCTION Function heading and ending, with the parameter and return type [1] Local integer variables declared for Num and Try [1] A count-controlled loop from 1 to ThisValue [1] Try multiplied by Num inside the loop [1] Try compared with ThisValue inside the loop [1] Num returned straight away when they are equal [1] -1 returned after the loop if no match was found [1] A WHILE loop with a Found flag, stopping when Try is greater than ThisValue, also scores. (b) Choose four strings that each break a different rule: Input Reason for choice "Aardvark" Not a number, and not "End" "27.3" A number but not an integer "-3" (or "0") An integer, but not positive and non-zero "" An empty string One distinct invalid string with a matching reason in row 1 [1] Row 2 [1] Row 3 [1] Row 4 [1] Another valid choice is "end" in the wrong case. KEY IDEA Build up the product one number at a time and stop when it equals or passes the target. TOTAL 11 marks Official mark scheme VIDEO ▶ Whole paper Video solution of the whole paper · by Audere Prep. Tap the picture to open it on YouTube.