Question 1 Report
Fig. 1 shows part of a food-delivery program. The main code receives a distance and calls a function to calculate the delivery charge. The returned charge is then supplied to a procedure that displays the final message. The delivery company uses this structure so that the calculation can be changed without rewriting the output commands.
(a) Explain why chargeFor must be a function. [2]
(b) When the function returns 8.50, state the value passed to showBill. [1]
(c) Explain one benefit of separating the calculation from the display procedure. [1]
The hospital appointment program checks a new patient's date of birth before making a booking. A function called validDate(day, month, year) returns either True or False. The main program should only call the booking procedure when the function returns True. A programmer has placed the booking commands inside the validation function, which makes the code difficult for staff to maintain. The system must be clear because it is reviewed during safety checks.
(a) Explain why the booking commands should be in a separate procedure. [2]
(b) When validDate returns False, state what the main program should not do. [1]
(c) Explain why returning a Boolean value is suitable for this validation function. [1]
Delivery-charge program
chargeFor must be a function because it calculates a delivery charge and returns that value to the main program for later use. [2]showBill is 8.50. [1]Appointment program
validDate returns False, the main program must not make or create the appointment booking. [1]True and False. [1]Everything you need to excel in your exams