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

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. Q45 2210/21/M/J/22 original Q1 Structured · 20 marks Worked solution (a) Name the data structures and describe one of them fully. Example answer: an array named FirstName to store the first names of the members, such as James, and a variable to input whether or not they wish to volunteer. Uses an array [1] Uses a variable (or a constant) [1] Gives a name , for example FirstName [1] Gives sample data , for example James [1] Gives the use , for example to store the first names of the members [1] Describing a second array with its name, sample data and use is also credited, up to the 5 marks. (b) Explain how the total could be kept. Any three of these: Add a new variable (or array) to hold the total money collected, or the number of members who have paid [1] Initialise it to 0 at the start of the program [1] Use an IF statement to check whether the new member has paid the $75 fee, and if so add 75 to the running total [1] Adding 1 to a count of paid members, and multiplying by 75 to give the total paid, is also credited. (c) Describe the checks and say what each is for. Any three of these: A presence check to make sure something has been entered for "Do you want to work as a volunteer?" [1] A check that the input matches the expected answer, for example yes or no [1] If the input is not valid, an error message is output and a new input is requested [1] A type check that the data is the right type, for example an integer if 1 or 0 is required, is also credited. Only naming checks scores a maximum of two. (d) Ask for the name and message, show them, let the sponsor correct them, then store them and show the fee. ArrayIndex ← 0 Check ← "N" WHILE Check <> "Y" DO OUTPUT "Enter your name" INPUT Name OUTPUT "Enter the message you would like on your brass plaque" INPUT Message OUTPUT "Your name is ", Name, " and your message is ", Message OUTPUT "Is this correct? (Y or N)" INPUT Check IF Check <> "Y" THEN OUTPUT "The data entered is incorrect, please re-enter" ENDIF ENDWHILE PlankName[ArrayIndex] ← Name PlankMessage[ArrayIndex] ← Message ArrayIndex ← ArrayIndex + 1 OUTPUT "The fee for this service is $200" Any five of these points score one each: Name and message input, both with suitable prompts [1] The input is output for the sponsor to confirm [1] A method for the sponsor to confirm the details are correct [1] A method to enter the message again if there are errors [1] The name and message are stored in arrays [1] Also credited: the array index increased for the next sponsor, and the $200 fee shown or charged. (e) Explain each step. Any four of these: A menu is shown so the user can choose which list to see [1] The user inputs the number or code of their choice from the menu [1] The input is validated : if it does not match an option, an error message is shown and it is input again [1] If it matches, IF statements or a CASE statement compare the input with the options [1] Also credited: a loop outputs the matching first-name and last-name arrays, and an empty list is spotted and dealt with. KEY IDEA Show a menu, validate the choice, then use a CASE or IF to pick which stored list to output. 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.