Question 1 Report
A coastal rescue team uses a program to calculate fuel for a boat trip. The program receives a distance in nautical miles and calls a subroutine that returns fuel needed at 2.4 litres per mile. The returned value is then displayed by the main program.
(a) When the distance is 15 miles, calculate the fuel returned. Show your working. [2]
(b) Explain why the subroutine should return a numeric value rather than a message such as Fuel calculated. [1]
(c) When the distance entered is 0, explain whether this is valid test data for the calculation. [1]
(d) Explain one validation rule for a distance entered by an operator. [1]
(a) Fuel is calculated at 2.4 litres per mile:
\[15 \times 2.4 = 36\]
The subroutine returns 36 litres. [2]
(b) It must return a numeric value because the main program needs a number to display or to use in further calculations. A message such as Fuel calculated cannot be used as the fuel amount. [1]
(c) Zero is valid boundary test data if a zero-distance trip is permitted. The calculation should then return 0 litres. [1]
(d) One suitable validation rule is that the distance must not be negative. Acceptable alternatives include requiring a numeric value or setting an agreed maximum distance. [1]
Everything you need to excel in your exams