2210/22/O/N/23 question 11: worked solution (October/November 2023, 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. Q52 2210/22/O/N/23 original Q11 Structured · 15 marks Worked solution Write a program that follows the requirements in order. Use the array names given and add a comment for each block. This is one correct answer: // set up the wood arrays WoodType[1] ← "Laminate" WoodType[2] ← "Pine" WoodType[3] ← "Oak" Price[1] ← 29.99 Price[2] ← 39.99 Price[3] ← 54.99 // index of the current customer in both arrays CurrentCustomer ← 1 // controls whether the program carries on for another customer Cont ← TRUE WHILE Cont = TRUE DO // input the customer name and store it OUTPUT "Enter the customer's name: " INPUT Customers[CurrentCustomer] // input and validate the room length OUTPUT "Enter the length of the room in metres: " INPUT RoomLength WHILE RoomLength < 1.5 OR RoomLength > 10.0 DO OUTPUT "Error: length must be between 1.5 and 10.0, try again: " INPUT RoomLength ENDWHILE // input and validate the room width OUTPUT "Enter the width of the room in metres: " INPUT RoomWidth WHILE RoomWidth < 1.5 OR RoomWidth > 10.0 DO OUTPUT "Error: width must be between 1.5 and 10.0, try again: " INPUT RoomWidth ENDWHILE // area of wood needed, rounded up to the next whole number RoomArea ← ROUND(RoomLength * RoomWidth, 0) IF RoomArea < RoomLength * RoomWidth THEN RoomArea ← RoomArea + 1 ENDIF // show the choices available OUTPUT "Wood choices: " FOR Count ← 1 TO 3 OUTPUT Count, " ", WoodType[Count], " $", Price[Count], " per square metre" NEXT Count // input and validate the choice of wood OUTPUT "Enter the number of the wood you want (1 to 3): " INPUT WoodChoice WHILE WoodChoice < 1 OR WoodChoice > 3 DO OUTPUT "Error: enter 1, 2 or 3: " INPUT WoodChoice ENDWHILE // price = area x price per square metre of the chosen wood WoodCost ← ROUND(RoomArea * Price[WoodChoice], 2) // store all the data in Quotations at the customer's index Quotations[CurrentCustomer, 1] ← ROUND(RoomLength, 1) Quotations[CurrentCustomer, 2] ← ROUND(RoomWidth, 1) Quotations[CurrentCustomer, 3] ← RoomArea Quotations[CurrentCustomer, 4] ← WoodChoice Quotations[CurrentCustomer, 5] ← WoodCost // output the quotation OUTPUT "Customer: ", Customers[CurrentCustomer] OUTPUT "Wood chosen: ", WoodType[WoodChoice] OUTPUT "Price of wood required: $", Quotations[CurrentCustomer, 5] // move to the next customer CurrentCustomer ← CurrentCustomer + 1 IF CurrentCustomer > 100 THEN CurrentCustomer ← 1 ENDIF ENDWHILE Wood arrays initialised with the three woods and prices [1] Customer name input with a prompt and stored in Customers[] [1] Room length and width input with prompts [1] Both measurements checked with a range check (1.5 to 10.0) in a loop with an error message and re-input until valid [2] Area worked out by length × width and rounded up to a whole number [2] Choice of wood input (with the list shown) [1] Price per square metre found from Price[] and multiplied by the area, rounded to 2 decimal places [2] All data stored in Quotations[] at the customer's index [2] Quotation output (name, wood choice, price) with suitable messages [1] Whole program in a loop so the next customer can be entered [1] Comments explain the code, with meaningful identifiers [1] Other correct approaches also score, for example REPEAT loops, other programming languages, or a different way to round up. KEY IDEA Plan the program in steps: input, validate with loops, calculate, store in the arrays, output, and repeat for the next customer. TOTAL 15 marks Official mark scheme VIDEO ▶ Whole paper Video solution of the whole paper · by Paper solver.. Tap the picture to open it on YouTube.