2210/22/O/N/21 question 1: worked solution (October/November 2021, paper 22)

Show as plain text

Cambridge O Level Computer Science 2210 · 8.2 Arrays Worked solution from the Programming Paper 2 Algorithms, Programming and Logic booklet, Part 2 of 3. Q44 2210/22/O/N/21 original Q1 Structured · 20 marks Worked solution (a)(i) Many answers are accepted. Example answers: Variable: PassengerID (or StartStage) [1] Use: stores the unique ID number of the passenger (or the start stage of the journey that is input) [1] (a)(ii) Describe each array with its name, data type, sample data and use. Example: Array name Data type Sample data Use JourneyStage1 string C1 to store the code for the home to start station PriceStage1 real 1.50 to store the price of the first stage of the journey Name of an array given [1] Data type of the array given [1] Sample data for the array given [1] Use of the array given [1] At least two complete arrays, each with all of these [1] (b) Any three of these: Use a validation check , for example a range, type, presence, length or format check [1] If the check fails, output an error message and ask for the code to be entered again [1] Use a loop (WHILE or REPEAT) to repeat the input until an acceptable code is entered [1] Also credited: an IF statement to test whether the check fails, and more than one appropriate check described. (c) Tasks 1 and 2 are done, so the cost is already stored. Apply the discount for the time, show the details and let the passenger correct them. IF CollectedTime[Index] > 10:00 THEN JourneyCost[Index] ← JourneyCost[Index] * 0.6 ENDIF OUTPUT "Your journey cost is: ", JourneyCost[Index] OUTPUT "Your journey details are: ", PassengerID[Index], JourneyTime[Index], JourneyCodes[Index], JourneyID[Index] OUTPUT "Are these details correct? (Y or N)" INPUT Correct WHILE Correct = "N" DO OUTPUT "Correct passenger ID" INPUT PassengerID[Index] OUTPUT "Correct journey time" INPUT JourneyTime[Index] OUTPUT "Correct journey codes" INPUT JourneyCodes[Index] OUTPUT "Your revised journey details are: ", PassengerID[Index], JourneyTime[Index], JourneyCodes[Index] OUTPUT "Are these details correct? (Y or N)" INPUT Correct ENDWHILE Any six of these points score one each: Conditional statement that checks the departure time against 10:00 [1] Calculates the 40% discount (multiplies the price by 0.6) [1] Calculates the discounted total price [1] Outputs the discounted total price [1] Outputs the booking details with suitable messages [1] Input with a prompt for the passenger to confirm the details [1] Also credited: an action after the confirmation input, the booking data entered again if it is wrong, and the journey details checked again. PRINT is accepted for OUTPUT. (d) Explain each change. Any four of these: Declare and use a counter to store the number of bookings for each passenger [1] Update (add 1 to) the counter each time that passenger makes a booking [1] Use an IF statement to check the number of bookings [1] … for the right condition, for example more than 10 (or equal to 10) [1] Applying the extra 10% discount to the total price of future journeys is also credited. KEY IDEA Count with a variable that goes up by 1, then use an IF on the count to decide when to change the price. TOTAL 20 marks Official mark scheme VIDEO ▶ Topic lesson A lesson on this topic · by Craig'n'Dave. Tap the picture to open it on YouTube.