Cambridge O Level Computer Science 2210 · 8.1 Programming concepts

Q13 · 2210/22/O/N/22 Q1

Worked solution from the Programming Paper 2 Algorithms, Programming and Logic booklet, Part 1 of 3.

Q132210/22/O/N/22original Q1Structured · 20 marks
Question 1 from 2210/22/O/N/22

Worked solution

(a)(i)

Many answers are accepted if they are meaningful. Example answers:

Constant: NumberDays [1]

Value: 14 [1]

(a)(ii)

Many answers are accepted if they are meaningful. Example answers:

Array: LicenceNumbers [1]

Use: stores the licence numbers of the cars to be parked [1]

(b)

Use a range check so the day is between 1 and 14, with a loop that asks again until it is valid.

INPUT Day
WHILE Day < 1 OR Day > 14 DO
    OUTPUT "You must enter a number between 1 and 14 inclusive"
    INPUT Day
ENDWHILE

Any two of these points score one each:

A (range) check for values between 1 and 14 [1]

An error message and the data entered again, with a WHILE or REPEAT loop until it is valid [1]

Also credited: a (type) check that an integer is entered, using an IF statement.

A suitable line of code or construct for the check, as shown [1]

(c)

Search the 20 spaces of the chosen day from space 1, and stop at the first free one.

OUTPUT "Enter the number of the day you need parking (1 to 14)"
INPUT Day
OUTPUT "Do you need an accessible space? (Y or N)"
INPUT Accessible
IF Accessible = "Y"
  THEN
    SpaceAllocated ← FALSE
    Space ← (Day - 1) * 20 + 1
    WHILE SpaceAllocated = FALSE AND Space <= Day * 20 DO
        IF LicenceNumbers[Space] = ""
          THEN
            OUTPUT "Enter your car licence number"
            INPUT LicenceNumbers[Space]
            SpaceAllocated ← TRUE
          ELSE
            Space ← Space + 1
        ENDIF
    ENDWHILE
    IF SpaceAllocated = TRUE
      THEN
        OUTPUT "You are allocated space ", Space - (Day - 1) * 20
      ELSE
        OUTPUT "No space available"
    ENDIF
ENDIF

Any six of these points score one each:

Day number and accessible parking inputs, both with suitable prompts [1]

Conditional statement to check if accessible parking is required [1]

Variable set to the first accessible space [1]

Checks whether the current array element is an available space [1]

A correct loop that checks all the array elements for the day [1]

Car licence number input and stored in the correct array position [1]

Also credited: the loop ends when a space is found or not, output for a space available or no space available, and output of the space allocated.

(d)

Explain each change. Any three of these:

Change the maximum constant to 560 (28 days) [1]

Change the message so the user is told to enter a day from 1 to 28 [1]

Alter the validation to allow an input of 1 to 28 [1]

Also credited: make the array that stores licence numbers and names bigger, and make sure all loops that retrieve or erase data use the new full range.

(e)

Explain each step. Any four of these:

Initialise counting variable(s) before any spaces are allocated [1]

… one for accessible spaces and one for general spaces [1]

Add 1 to the counter(s) when a space is allocated [1]

… for accessible spaces and for general spaces [1]

Also credited: keep both counters for the full two-week cycle, and output both totals so far with suitable messages.

KEY IDEAUse a constant for the sizes, validate input with a loop, and search an array for the first empty element.
TOTAL 20 marks

Official mark scheme

Mark scheme for 2210/22/O/N/22 question 1
VIDEO
▶ Topic lesson

A lesson on this topic · by Mr Bulmer's Learning Zone. 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.