A ferry company writes a booking program to calculate the total charge for vehicles on an island route. Table 1 contains test data from the code editor. The...

Assessment: Computer Science 4CP0 | Paper 2 Mock 01 | Written Paper 2 Subject: Computer Science - 4CP0

Question 1 Report

A ferry company writes a booking program to calculate the total charge for vehicles on an island route. Table 1 contains test data from the code editor. The function vehicleCharge receives a vehicle type and a crossing number. Cars cost 1800 pence, vans cost 2600 pence and bicycles cost 500 pence. Crossing number 1 is a daytime crossing. All other valid crossing numbers add a 300 pence evening charge.

Vehicle type inputCrossing numberExpected charge in penceTest type
CAR11800Normal
VAN22900Normal
BICYCLE3800Normal
CAR0ErrorInvalid

The main program will call the function once for each booking and then display the returned number. The programmer must ensure that an unknown vehicle word is not treated as a correct booking.

(a) Identify the two parameters of vehicleCharge and state its return data type. [3]
(b) Write pseudocode for the selection that assigns the base charge for CAR, VAN and BICYCLE. [4]
(c) Complete a valid function call for a customer whose vehicle is stored in vehicle and whose crossing is stored in crossing. Store the result in total. [3]
(d) Give three test cases, different from Table 1, that would help test this function. Include the input data and the expected result for each. [3]

Answer Details

(a) The two parameters are vehicle type and crossing number. The return data type is INTEGER or number, because the function returns a charge in pence. [3]

(b) A valid selection is:

IF vehicleType = "CAR" THEN
  base <- 1800
ELSE IF vehicleType = "VAN" THEN
  base <- 2600
ELSE IF vehicleType = "BICYCLE" THEN
  base <- 500
ELSE
  DISPLAY "Error"
ENDIF

The final alternative is necessary so an unknown vehicle word is not treated as a valid booking. [4]

(c)

total <- vehicleCharge(vehicle, crossing)

The two stored values are passed in the same order as the function parameters, and the returned integer is stored in total. [3]

(d) Three useful additional tests are:

Vehicle inputCrossing inputExpected result
VAN12600
CAR22100
SCOOTER1Error

The first two check valid daytime and evening charging; the last checks that an unknown vehicle is rejected. [3]

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