Worked solution from the Programming Paper 2 Algorithms, Programming and Logic booklet, Part 1 of 3.
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]
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]
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.
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
ENDIFAny 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.
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.
▶ 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.