2210/21/M/J/20 question 1: worked solution (May/June 2020, paper 21)
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. Q1 2210/21/M/J/20 original Q1 Structured · 20 marks Worked solution (a)(i) Name an array that holds product details for the mobile devices, and say what it stores. Give two arrays. Array 1: ItemCode [1] Purpose: stores the item code of every device and SIM card for sale [1] Array 2: Description (or Price ) [1] Purpose: stores the description (or price) of each item, in the same position as its item code [1] (a)(ii) Name a variable that is used while the program runs, and say what it holds. Give two variables. Variable 1: PurchaseItem [1] Purpose: stores the item code the customer types in [1] Variable 2: TotalPrice [1] Purpose: stores the running total price of the purchase [1] (b) Item codes contain letters, not only digits, and a real number can only hold a numeric value that is used in calculations. Write: the code is made up of letters (not just numbers) and is never used in calculations, so it cannot be a real [1] Write: the best data type is string [1] (c) Ask for the device, check the code exists in the array, decide if it is a phone or tablet, and only ask about a SIM card for a phone. OUTPUT "Which phone or tablet would you like? Input the Item Code" DeviceFlag ← False WHILE DeviceFlag = False DO INPUT DeviceCode Count ← 0 WHILE Count < 10 DO IF DeviceCode = ItemCode[Count] THEN IF Count < 6 THEN DeviceType ← "Phone" ELSE DeviceType ← "Tablet" ENDIF DeviceFlag ← True Count ← 10 ENDIF Count ← Count + 1 ENDWHILE IF DeviceFlag = False THEN OUTPUT "Your code does not exist, please try again" ENDIF ENDWHILE IF DeviceType = "Phone" THEN OUTPUT "Would you like a SIM card? (Answer Y or N)" INPUT SimRequired ENDIF Input with a message to choose the mobile device [1] Check that the item code entered is valid (an attempt at validation) [1] The validation is accurate: the code is looked up and an error message is shown if it is not found [1] Work out whether the device is a phone or a tablet [1] Ask about a SIM card, and only when the device is a phone [1] Other correct ways score, for example a FOR loop or a different array layout. (d) Explain each step the program takes. Any five of these. Finds whether more than one device has been bought, for example by counting the devices chosen [1] Applies the device discount when the conditions are met, using an IF statement [1] Works out the discount and the new price, for example price × discount rate, then price − discount [1] Outputs the new total with a message [1] Outputs the amount the customer has saved with a message [1] Any other correct explanation of the messages shown also scores. KEY IDEA Use arrays for the product data, variables for values that change, and a validation loop that repeats until the item code is found. 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.