ExamBank Scot · Higher Computing Science question bank · All Higher Computing Science questions
3 marks · Testing and debugging
A breakpoint is set at Line 26 and the program is tested using the following four player numbers as input: no1 no2 no3 no4 5 10 15 22 Complete the trace table to show the values stored when the breakpoint is activated on the first two iterations of the loop. Breakpoint Variable Value 1st iteration index 0 winningNos[index] numMatches 2nd iteration index 1 winningNos[index] numMatches Explain, with reference to the code, why the number of matches always results in 4. A number matching game stores four winning numbers and compares them to a player’s input of four numbers. 250 points are awarded for each number matched. For example, two matched numbers would be awarded 500 points. The code below contains an error, as the player is always awarded 1000 points. … Line 10 DECLARE winningNos INITIALLY [10, 14, 21, 33] Line 11 DECLARE numMatches INITIALLY 0 Line 12 DECLARE points INITIALLY 0 Line 13 RECEIVE no1 FROM KEYBOARD Line 14 RECEIVE no2 FROM KEYBOARD Line 15 RECEIVE no3 FROM KEYBOARD Line 16 RECEIVE no4 FROM KEYBOARD Line 17 FOR index FROM 0 TO 3 DO Line 18 IF no1 = winningNos[index] THEN Line 19 SET numMatches TO numMatches + 1 Line 20 ELSE IF no2 = winningNos[index] THEN Line 21 SET numMatches TO numMatches + 1 Line 22 ELSE IF no3 = winningNos[index] THEN Line 23 SET numMatches TO numMatches + 1 Line 24 ELSE Line 25 SET numMatches TO numMatches + 1 Line 26 END IF Line 27 END FOR Line 28 SET points TO 250 * numMatches Line 29 SEND "You matched "& numMatches & " numbers and have won " & points TO DISPLAY …
Award 1 mark for each bullet. • winningNos[index[ 10 winningNos[index] 14 • numMatches 1 numMatches 2 Breakpoint Variable Value 1st Iteration index 0 winningNos[index] 10 numMatches 1 2nd Iteration index 1 winningNos[index] 14 numMatches 2 If there are no matches to any of the IF conditions the ELSE statement (Line 24/25) is executed.