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 i...

Assessment: Computer Science 9210 | Paper 1 Mock 01 | Programming (on-screen) Subject: Computer Science - 9210

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.

main programdistance enteredchargeFor(distance)returns chargeshowBill(charge)© EAGLE BEACON GLOBAL

(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]

Answer Details

Delivery-charge program

  1. chargeFor must be a function because it calculates a delivery charge and returns that value to the main program for later use. [2]
  2. If the function returns 8.50, the value passed to showBill is 8.50. [1]
  3. Separating calculation from display means charge rules can be changed or tested without changing the output code; the calculation can also be reused. [1]

Appointment program

  1. Validation and booking have separate purposes. Keeping booking in a separate procedure makes each subroutine easier to test, understand and maintain. [2]
  2. If validDate returns False, the main program must not make or create the appointment booking. [1]
  3. A Boolean is suitable because validation has two outcomes, valid or invalid, which correspond directly to True and False. [1]

Download The App On Google Playstore

Everything you need to excel in your exams

Green Bridge CBT Mobile App
Personalized AI Learning Chat Assistant
200,000+ Exam Questions Across IGCSE, JAMB, WAEC & NECO
Over 3,900 Lesson Notes
Offline Support - Learn Anytime, Anywhere
Green Bridge Timetable
Literature Summaries & Potential Questions
Track Your Performance & Progress
In-depth Explanations for Comprehensive Learning