2210/23/O/N/20 question 1: worked solution (October/November 2020, paper 23)
Show as plain textHide 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. Q6 2210/23/O/N/20 original Q1 Structured · 20 marks Worked solution (a) Many answers are accepted if they are meaningful and linked to Task 1. Example answers: Constant: MaxSalad [1] Value: 3 [1] Use: stores the most salad items a baguette can have [1] Variable: OrderNumber [1] Data type: integer [1] Use: stores the next order number available [1] (b)(i) Show the fillings, accept only a valid choice, then ask how many salads (0 to 3) and take each salad. REPEAT OUTPUT "Beef 1, Chicken 2, Cheese 3, Egg 4, Tuna 5, Turkey 6" OUTPUT "Please enter your choice of filling" INPUT Filling IF Filling < 1 OR Filling > 6 THEN OUTPUT "Error, please try again" ENDIF UNTIL Filling >= 1 AND Filling <= 6 REPEAT OUTPUT "How many salads do you want (0 to 3)?" INPUT NumSalad UNTIL NumSalad >= 0 AND NumSalad <= 3 OUTPUT "Lettuce 1, Tomato 2, Sweetcorn 3, Cucumber 4, Peppers 5" WHILE NumSalad > 0 DO OUTPUT "Please enter your choice of salad" INPUT SaladType IF SaladType >= 1 AND SaladType <= 5 THEN Salad[NumSalad] ← SaladType NumSalad ← NumSalad - 1 ELSE OUTPUT "Error" ENDIF ENDWHILE Any five of these points score one each: Display the fillings available [1] Prompt and entry of the filling choice [1] Only one correct filling accepted [1] Prompt and entry of the number of salads, accepting only 0 to 3 [1] Only correct salad choices accepted, for the number of salads asked for [1] Also credited: the salads displayed, and at least one error message for wrong data. (b)(ii) Any three of these. There is a way to input the filling choice [1] The input is checked to be a correct filling, for example with a CASE statement [1] If it is not, a suitable error message is output [1] A way to enter it again is also credited, for example REPEAT … UNTIL. (c) Any two of these. Store three sizes of baguette, for example add the third size to the array [1] Change the prompt so it shows the three sizes [1] Changing the selection statement (IF, REPEAT or WHILE) to accept a third size is also credited. (d) Any four of these. Check the total for each filling , for example with a FOR loop [1] Use two variables , one for the most popular and one for the least popular filling [1] Use an IF statement to pick the largest total as the most popular [1] Use an IF statement to pick the smallest total as the least popular [1] Also credited: use these totals with the number of baguettes sold to work out percentages, and display the results with suitable messages. KEY IDEA Validation loops repeat the input until it is in range, and each program step needs a clear reason. TOTAL 20 marks Official mark scheme VIDEO ▶ Topic lesson A lesson on this topic · by Mr Bulmer's Learning Zone. Tap the picture to open it on YouTube.