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

Higher Computing Science 2018 Question 15 (CfE)

18 marks · Constructs and reading code

Explain why line 4 of the function contains the limit (upper-1). Describe how the parameters are used when executing line 23. Your answer should identify the formal and actual parameters. State the scope of the min variable. Explain your answer. Testing reveals an error in the function. The function is first called during execution of line 23 of the main program. In order to identify this error, a watchpoint has been set to show the value of the min variable each time it is changed. Complete the table to show the values that would be shown when this watchpoint is triggered. Function Line min 2 6 6 Testers report that the program sometimes outputs the incorrect result. Identify the error in the function that causes incorrect output. State the type of error that has caused this issue. Explain why the incorrect code outputs the correct statement. Your answer should make reference to the original heat results shown on lines 21 and 22 of the code. If the fastest time in heat 1 and heat 2 is the same, the following output is always displayed: “The fastest runner ran in heat 2” Explain this output with reference to the conditional statement beginning at line 25. Explain how the code could be altered to include a third option which will state: “Both heats have the identical fastest time” Explain the role of the memory management function of the operating system when a user loads the SportsStats program. SportsStats is a program that processes the results of athletics competitions. The results of two different heats are compared to find which heat had the fastest time. Heat 1 Results Heat 2 Results 13.4 11.5 11.1 13.7 14.5 10.1 17.4 10.3 10.8 16.4 12.6 12.9 Show Results When a user presses the ‘Show Results’ button, the program should output the number of the heat that had the fastest runner, for example: “The fastest runner ran in heat 2” The program makes use of the following function: Line 1 FUNCTION fastest_time(ARRAY OF REAL list) RETURNS REAL Line 2 DECLARE min INITIALLY list[0] Line 3 DECLARE upper INITIALLY length(list[]) Line 4 FOR index FROM 1 to (upper-1) DO Line 5 IF min < list[index] THEN Line 6 SET min TO list[index] Line 7 END IF Line 8 END FOR Line 9 RETURN min Line 10 END FUNCTION The function is used in the following section of code: … Line 21 SET heat1 TO [13.4, 11.1, 14.5, 17.4, 10.8, 12.6] Line 22 SET heat2 TO [11.5, 13.7, 10.1, 10.3, 16.4, 12.9] Line 23 SET first_result TO fastest_time (heat1) Line 24 SET second_result TO fastest_time (heat2) Line 25 IF first_result < second_result THEN Line 26 SEND “The fastest runner ran in heat 1” TO DISPLAY Line 27 ELSE Line 28 SEND “The fastest runner ran in heat 2” TO DISPLAY Line 29 END IF …

Marking scheme

• The upper index of the array is one less than the length of the array. • Upper – 1 is the highest index position of the array. • (Exceeds array index) so runtime error would occur. 1 mark for any one bullet heat1 is the actual parameter. (1 mark) list is the formal parameter. (1 mark) 1 mark for any one bullet from • Formal parameter (list) contains the pointer/address of actual parameter (heat 1). • Any changes to the formal parameter (list) are automatically made to the actual parameter. Explanations based on passing by value are not acceptable. • Local OR lines 1/2 to lines 9/10. (1 mark) • It is only used within the function in which it is declared. (1 mark) A = 13.4 B = 14.5 C = 17.4 1 mark for each correct value A=13.4, B=13.4, C=14.5 Award 2 marks • Use of < (instead of >). • On line 5, list(index) and min should swap places. 1 mark for any one bullet Logic • The maximum time/16.4 in heat 2 is lower than the maximum time/17.4 in heat 1 (1 mark) • which coincides with the fastest time/10.1 being in heat 2. (1 mark) • (If the times are equal) the IF condition is false/not met/is not less than (1 mark) • therefore the else statement is executed. (1 mark) Concept of nested if or else if statement. • Tracks/checks available memory. • Allocates space/addresses in RAM for the function. • Protects other processes. 1 mark for each bullet. Maximum 2 marks

Previous question: Higher Computing Science 2018 Question 14 (CfE)

Next question: Higher Computing Science 2019 Question 1