ExamBank Scot · Higher Computing Science question bank · All Higher Computing Science questions

Higher Computing Science 2024 Question 10

9 marks · Testing and debugging

Complete the trace table for the first two iterations of the loop. The trace table should indicate the line number where a variable changes value and the new value of that variable. Line number counter index longestStreak 10 0 11 −1 12 0 13 0 15 12 13 18 20 State the line number of the code that should be removed to correct the algorithm. Name and describe a debugging technique that could be used during execution of the code. Explain why the scope of the variable counter is local. Describe how modular programming increases the efficiency and maintainability of the code. Efficiency Maintainability Lewis uses a smart watch to track the distance he walks each day for a week. His target is to walk 5 kilometres or more each day. The program will find the highest the number of consecutive days Lewis meets this target. For example, if the data was 5.2, 4.2, 4.0, 4.8, 5.8, 5.2, 6.4 The expected output should be 3. The following code has been developed to find the highest number of consecutive days Lewis has met his target but there is an error. … Line 09 FUNCTION consecutiveDays (ARRAY OF REAL values) RETURNS INTEGER Line 10 DECLARE counter INITIALLY 0 Line 11 DECLARE longestStreak INITIALLY − 1 Line 12 FOR index FROM 0 TO LENGTH(values) − 1 DO Line 13 SET counter TO 0 Line 14 IF values[index] >= 5.0 THEN Line 15 SET counter TO counter + 1 Line 16 ELSE Line 17 IF counter > longestStreak THEN Line 18 SET longestStreak TO counter Line 19 END IF Line 20 SET counter TO 0 Line 21 END IF Line 22 END FOR Line 23 IF counter > longestStreak THEN Line 24 SET longestStreak TO counter Line 25 END IF Line 26 RETURN longestStreak Line 27 END FUNCTION … Line 46 SET distances TO [5.2, 4.2, 4.0, 4.8, 5.8, 5.2, 6.4] Line 47 SET daysMet TO consecutiveDays(distances) …

Marking scheme

• Line 15 counter = 1 • Line 12 index = 1 AND Line 13 counter = 0 • Line 18 longestStreak = 0 AND Line 20 counter = 0 Do not penalise if candidate records all values at each line number Example answer: Line Number counter index longestStreak 10 0 11 -1 12 0 13 0 15 1 12 1 13 0 18 0 20 0 Line 13 • Breakpoint • Stops execution at a specified line/allowing variable values to be compared to expected values/allows variables to be inspected OR • Watchpoint • Stops execution when a variable changes or meets condition/allowing variable values to be compared to expected values/allows variable to be inspected Award 1 mark for correct description of dry run It is declared/only accessible or used inside the function (lines 9-27) Efficiency • The function can be called more than once/reused (with different parameters) • Local variables/parameters only held in memory while being executed Maintainability • If there is an error with that part of the program then the bug is easier to find/easier to identify errors in a section of code • Is increased because modules with local variables can be edited without affecting the other modules in the program • Any new modules or changes to existing modules can be edited/tested individually Award 1 mark for any one bullet about efficiency Award 1 mark for any one bullet about maintainability

Previous question: Higher Computing Science 2024 Question 9

Next question: Higher Computing Science 2024 Question 11