2210/22/M/J/20 question 1: worked solution (May/June 2020, paper 22)

Show as plain text

Cambridge O Level Computer Science 2210 · 8.1 Programming concepts Worked solution from the Programming Paper 2 Algorithms, Programming and Logic booklet, Part 1 of 3. Q2 2210/22/M/J/20 original Q1 Structured · 20 marks Worked solution (a) Name two variables, give a data type and say what each one is used for. Variable 1: hourArrived , data type integer [1] Use: to work out the price from the number of hours parked [1] Variable 2: priceToPay , data type real [1] Use: stores the result of the price calculation [1] (b) The two checks must be different. Examples that score: Day: presence check [1] Justification: the day must be entered so the price can be worked out [1] Hour: range check [1] Justification: the hour must be between 8 and 23 [1] (c) Write how the program checked the 5th digit of the number. Any four of these. All 5 digits of the parking number are input [1] Each of the first 4 digits is multiplied by a weight based on its position, with the method for splitting up the digits described [1] The results are added together and divided by 11 [1] The remainder gives the correct 5th digit, which is checked against the 5th digit input; if they match the number is valid [1] (d) Ask for the payment, repeat until it is at least the price, then add it to the total. OUTPUT "Please enter payment" INPUT amount WHILE amount < priceToPay DO OUTPUT "Insufficient payment, please enter new payment" INPUT amount ENDWHILE totalPayment ← totalPayment + amount Input the amount paid [1] Check the amount is greater than or equal to the price to pay [1] If it is too small, ask for payment to be entered again until a valid amount is input [1] If it is enough, add the amount to the daily total [1] (e) Explain the evening charge. Any four of these. Add the number of hours chosen to the arrival hour [1] Check if the result is greater than 16 [1] If it is, work out the price up to 16 using the current price in force, then add the evening charge [1] If it is not, work out the price as usual [1] KEY IDEA Pick suitable variables and validation checks, and explain each step of the program's logic in order. TOTAL 20 marks Official mark scheme VIDEO ▶ Whole paper Video solution of the whole paper · by Zafar Ali Khan (ZAK). Tap the picture to open it on YouTube.