ExamBank Scot · Higher Computing Science question bank · All Higher Computing Science questions
16 marks · Standard algorithms
The temperature statistics feature displays the message: The lowest temperature was 8 Celsius at hour 1. Write, using pseudocode or a language with which you are familiar, an algorithm that can: • find the lowest temperature • display the message shown above • write the lowest temperature to an external file called “low.txt”. Name a function of the operating system and describe one task it will perform when creating the external file. The app makes use of a function to calculate the average. Line 1 FUNCTION calcAverage (ARRAY OF INTEGER list) RETURNS INTEGER Line 2 DECLARE total AS INTEGER INITIALLY 0 Line 3 DECLARE average AS INTEGER INITIALLY 0 Line 4 FOR index FROM 0 TO 23 DO Line 5 SET total TO total + list[index] Line 6 SET average TO total / (index +1) Line 7 END FOR Line 8 RETURN average Line 9 END FUNCTION At the end of the first iteration, the values for total and average are both 10. Complete the following trace table to show the values of the total and average variables at the end of the second and third iteration of the loop. End of Iteration Total Average 1 10 10 2 3 On the fourth iteration, a runtime error occurs. Error reporting states that line 6 is the cause. Explain why this line causes the problem and how to correct it. The calcAverage function only works for 24 integers. Describe how the function could be altered to calculate the average for any size of list. Describe two ways that intelligent heating systems such as HiDoe can be used to reduce the carbon footprint of homes. HiDoe manufactures intelligent heating control systems that allow users to monitor the temperature in different rooms in their house. An app can be downloaded to access information about energy use. Selecting Temperature Statistics on the app allows users to see the highest and lowest temperature of a room over the course of a 24 hour period. A sensor measures the temperature in a room at the start of each hour in a day. These temperatures are stored in an array called temps. index 0 1 2 3 ....... 22 23 temps 10 8 12 11 ....... 14 13
SET minpos TO 0 SET minimum TO temps(0) FOR index FROM 1 TO 23 DO IF temps (index) < minimum THEN SET minpos TO index SET minimum TO temps (index) END IF NEXT index SEND “ The... was” & minimum & “Celsius...” at hour” & index OPEN “low.txt” SEND minimum TO FILE Close “low.txt” SET minpos TO 0 FOR index FROM 1 TO 23 DO IF temps (index) < temps(minpos) THEN SET minpos TO index END IF NEXT index SEND “ The... was” & temps(minpos) & “Celsius...” at hour” & minpos OPEN “low.txt” SEND temps(minpos) TO FILE Close “low.txt” 1 mark for initialising minimum before loop AND assigning minimum within loop 1 mark for use of fixed loop (with end loop or indentation) 1 mark for IF statement with correct condition (with end if or indentation) 1 mark for assigning minpos 1 mark for output showing minimum and position 1 mark for open and close file 1 mark for send minimum to file OR 1 mark for initialising position 1 mark for use of fixed loop (with end loop or indentation) 1 Mark for IF statement with correct conditions (with end if or indentation) 1 mark for assigning minpos 1 mark output showing minimum and position 1 mark for open and close file 1 mark for send minimum to file Accept minimum > temps (index) Accept loop 0 to 23 • File management (1 mark): o identifies a free space on backing storage to place file (1 mark) OR o Updates/checks file directory (1 mark) • Memory management (1 mark): o locates data in main memory (1 mark) OR o allocates main memory for process (1 mark) • Input/Output (1 mark): o transfer from memory to backing storage (1 mark) • Resource allocation (1 mark): o managing processes and memory (1 mark) 1 mark for function 1 mark for description Accept error reporting, process management or accepting user commands with appropriate description. Iteration Total Average 2 18 9 3 30 10 1 mark for each correct line Calculation results in the wrong data type ie real for the variable average (1 mark) Make average a real variable (1 mark) Accept round functions • Change the number 23 to END OF LIST • Use a conditional loop that utilises END OF LIST/FILE as a condition • Use a function to determine the size of the array • Accept a parameter that is used to define the size of the array 1 mark for any bullet • Remote access to control heating when not at home • Use of geolocation can automatically turn heating off when no one is home • Takes account of external weather forecast and adjusts temperature accordingly • Real time temperature monitoring through mobile devices can reduce unnecessary gas/fuel use • Data can be analysed to determine how quickly a home heats and how slowly it loses heat meaning that the boiler can be used more efficiently • Multi room control systems prevent rooms being overheated when not in use 1 mark for any bullet – maximum 2 marks Answer must refer to the control/intelligence of the heating system.
Previous question: Higher Computing Science 2017 Question 9 (CfE)
Next question: Higher Computing Science 2017 Question 11 (CfE)