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

Higher Computing Science 2017 Question 12 (CfE)

8 marks · Sub-programs, parameters and scope

Identify a formal parameter used in the code above and explain what is meant by a formal parameter. A car arrived at the car park at 10:00 and left at 13:00. When the function is called, arrived has the value 10.0 and left has the value 13.0. The function returns an incorrect cost of 2.75. Explain why this function did not return the expected value. Watchpoints are often used during testing. Describe how watchpoints are used to help programmers locate errors. The function makes use of a local variable. Describe two benefits of using local variables. A program is used to calculate parking charges for a public car park. The arrival and departure times are converted to and stored as real numbers, for example: 06:30 hours will be converted to and stored as 6.5. Welcome to Shore Car Park CHARGES all charges include VAT UP TO 1 HOUR £2·75 UP TO 2 HOURS £4·25 OVER 2 HOURS £6·25 The function below is used to calculate the cost of parking for each car. Line 1 FUNCTION calcCost(REAL departure, REAL arrival) RETURNS REAL Line 1 DECLARE hours_parked INITIALLY 0 Line 3 DECLARE parking_charge INITIALLY 0 Line 4 SET hours_parked TO departure – arrival Line 5 IF hours_parked <= 1 THEN Line 6 SET parking_charge TO 2.75 Line 7 ELSE Line 8 IF hours_parked <=2 THEN Line 9 SET parking_charge TO 4.25 Line 10 ELSE Line 11 SET parking_charge TO 6.25 Line 12 END IF Line 13 END IF Line 14 RETURN parking_charge Line 15 END FUNCTION This function is called using the line below: SET cost TO calcCost (arrived, left)

Marking scheme

• Arrival OR • departure Any one bullet from: • A formal parameter can be a copy of the actual parameter • A formal parameter can be a pointer/placeholder to the actual parameter • A formal parameter can control the flow of data eg. by reference or by value 1 mark for identifying parameter 1 mark for explanation of formal parameter • The values are switched/passed into the incorrect parameters • 10 – 13 results in -3 • hours_parked is less than 1 1 mark for any bullet – maximum 2 marks Watchpoints are used to stop execution when the value of a specific variable changes/pre- determined conditions are met (1 mark) This allows the programmer to compare the value with the expected value (1 mark) 2nd mark can only be awarded if clear indication that value is compared with an expected value/test table result etc. • More efficient as memory assigned to a local variable becomes available once function is terminated • Allows variables of the same name in different modules without affecting others • Aids modularity 1 mark for any bullet – maximum 2 marks

Previous question: Higher Computing Science 2017 Question 11 (CfE)

Next question: Higher Computing Science 2017 Question 13 (CfE)