Cambridge AS Level Computer Science 9618 · 9.2 Algorithms

Q27 · 9618/21/M/J/23 Q2

Worked solution from the Algorithm Design and Problem-solving Paper 2 Problem-solving and Programming booklet, Part 2 of 2.

Q279618/21/M/J/23original Q2Structured · 7 marks
Question 2 from 9618/21/M/J/23

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 IDEAA flowchart loop is a decision diamond with an arrow back; remember the SETDATE(day, month, year) order.
TOTAL 7 marks

Official mark scheme

Mark scheme for 9618/21/M/J/23 question 2
VIDEO
▶ Starts at Q2 (10:45)

Starts at Q2 (10:45) · by Pseudocode Pro. Tap the picture to open it on YouTube.

Solutions follow the official Cambridge mark schemes; marks are shown in grey. Videos are from other YouTube channels. Paper codes read component / series / year: M/J = May/June, O/N = October/November. Past-paper questions © UCLES, reproduced for classroom practice.