9618/21/M/J/23 question 2: worked solution (May/June 2023, paper 21)
Show as plain textHide plain text
Cambridge AS Level Computer Science 9618 · 9.2 Algorithms Worked solution from the Algorithm Design and Problem-solving Paper 2 Problem-solving and Programming booklet, Part 2 of 2. Q27 9618/21/M/J/23 original Q2 Structured · 7 marks Worked solution (a) Draw the boxes in this order, joined by arrows from START to END. Use a parallelogram for inputs and outputs, a rectangle for processes and a diamond for the decision. START → OUTPUT "Enter a character" and INPUT MyChar → OUTPUT "Enter a count" and INPUT MyCount → Set MyString to "" (empty string) → Diamond: Is MyCount > 0 ? YES → Set MyString to MyString & MyChar → Set MyCount to MyCount - 1 → arrow back to the diamond NO → OUTPUT MyString → END Both prompts drawn [1] Both inputs, using the names MyChar and MyCount [1] MyString set to empty before the loop and output after the loop [1] Loop that repeats MyCount times, with MyCount reduced by 1 each time [1] Joining MyChar onto MyString inside the loop (with &) is a fifth point that also scores, but the most you can score is 4, so any four of the five points score. (b) DECLARE StartDate : DATE StartDate ← SETDATE(15, 11, 2005) Declaration with type DATE [1] Use of the function SETDATE [1] Parameters in the order day, month, year: (15, 11, 2005) [1] KEY IDEA A flowchart loop is a decision diamond with an arrow back; remember the SETDATE(day, month, year) order. TOTAL 7 marks Official mark scheme VIDEO ▶ Starts at Q2 (10:45) Starts at Q2 (10:45) · by Pseudocode Pro. Tap the picture to open it on YouTube.