Cambridge O Level Computer Science 2210 · 8.1 Programming concepts

Q9 · 2210/21/M/J/21 Q1

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

Q92210/21/M/J/21original Q1Structured · 20 marks
Question 1 from 2210/21/M/J/21

Worked solution

(a)(i)

Many answers are accepted if they are meaningful and linked to Task 1. Example answers:

Constant: MaxCandidates [1]

Value: 4 [1]

Use: the maximum number of candidates for the election [1]

(a)(ii)

Many answers are accepted if they are meaningful and linked to Task 1. Example answers:

Variable: NumberCandidates [1]

Use: stores the number of candidates in the election [1]

Array: CandidateNames [1]

Use: stores the names of the candidates in the election [1]

(b)

Say what you change and how your program changes. Any four of these:

Change the value of the MaxCandidates constant (or variable) to 8 [1]

Change the input message to say the most candidates is 8 [1]

Change the loop limit so it runs up to 8 times [1]

Change the validation so it accepts up to 8 [1]

Also credited: make the arrays big enough for 8 names, and change the counters so votes can be counted for 8 candidates.

(c)

Input the voter number, search the list of voters who have voted, stop them if found, otherwise store the number.

OUTPUT "Please enter your unique voter number"
INPUT UniqueVoterNumber
FoundFlag ← False
AllNumbersChecked ← False
Counter ← 0
WHILE FoundFlag = False AND AllNumbersChecked = False DO
    IF StudentNumbers[Counter] = ""
      THEN
        AllNumbersChecked ← True
        StudentNumbers[Counter] ← UniqueVoterNumber
      ELSE
        IF UniqueVoterNumber = StudentNumbers[Counter]
          THEN
            FoundFlag ← True
            OUTPUT "Sorry, you have already voted"
          ELSE
            Counter ← Counter + 1
        ENDIF
    ENDIF
ENDWHILE
IF FoundFlag = False
  THEN
    OUTPUT "Please enter the code of your chosen candidate"
    INPUT Vote
ENDIF

Any five of these points score one each:

Input with a message to enter the unique voter number [1]

Attempt to check whether the voter has already voted [1]

If they have, a message warns them they cannot vote [1]

An attempt at stopping them from voting [1]

The voter number is stored in a suitable data structure [1]

Also credited: validation of the number (length, type or range check), and a check that the number is in the list of possible voters.

(d)

Explain how your program does each of these. Any four of these:

Finds the total number of votes cast for all candidates [1]

For each candidate (a loop), calculates the percentage of votes [1]

… excluding abstentions [1]

Displays each candidate's name, number of votes and percentage with suitable messages [1]

Displaying the number of votes cast and the number of abstentions with a message is also credited.

KEY IDEAStore voter numbers in an array, search it before accepting a vote, and use a loop to report each candidate.
TOTAL 20 marks

Official mark scheme

Mark scheme for 2210/21/M/J/21 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.