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 input | Crossing number | Expected charge in pence | Test type |
|---|---|---|---|
| CAR | 1 | 1800 | Normal |
| VAN | 2 | 2900 | Normal |
| BICYCLE | 3 | 800 | Normal |
| CAR | 0 | Error | Invalid |
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]
(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 input | Crossing input | Expected result |
|---|---|---|
| VAN | 1 | 2600 |
| CAR | 2 | 2100 |
| SCOOTER | 1 | Error |
The first two check valid daytime and evening charging; the last checks that an unknown vehicle is rejected. [3]
Everything you need to excel in your exams