Model Answers: Medium
a)
[Total: 4 marks]
B; [1 mark]
[Total: 1 mark]
C; [1 mark]
[Total: 1 mark]
4a
a) One mark for each correct line.
DECLARE X : STRING
DECLARE Y : INTEGER
DECLARE Z : INTEGER
[Total: 3 marks]
4b
b) One mark for storing string in X.
One mark for calling the function length.
One mark for using the correct parameter X.
One mark for using the substring function.
One mark for correct parameters.
One mark for outputting length and substring return values.
For example:
X ← "Programming is fun"
OUTPUT Length(X)
Y ← 16
Z ← 3
OUTPUT SubString(X,Y,Z)
[Total: 6 marks]
i) Maximum 5 marks in total for question part
Maximum 3 marks for algorithm
Description (max 3)
– set variable called HighestScore to zero and variable called BestName to dummy value
– loop 30 times to check each student’s total score in turn
– check student’s score against HighestScore
– if student’s score > HighestScore then
– ..... replace value in HighestScore by student’s score and store student’s name in BestName
– output BestName and HighestScore outside the loop
Sample algorithm (max 3):
HighestScore 0
BestName “xxxx” (1 mark)
FOR Count 1 TO 30
IF StudentTotalScore[Count] >
HighestScore (1 mark)
THEN
HighestScore
StudentTotalScore[Count]
BestName StudentName[Count] (1 mark)
ENDIF
NEXT Count (1 mark)
PRINT BestName, HighestScore (1 mark)
If algorithm or program code only, then maximum 3 marks
ii) comment on which student(s)’ name will be output; [1 mark]
e.g. The first student with the highest score will be output
[Total: 6 marks]
6a
a) marking points:
the way to find and print the largest value a 1 mark
the way to find and print the largest value b 1 mark
the way to find and print the largest value c 1 mark
sample algorithm:
INPUT a, b, c
IF a > b AND a > c THEN PRINT a (1 mark)
ELSE IF b > c THEN PRINT b (1 mark)
ELSE PRINT c (1 mark)
[Total: 3 marks]
6b
b) marking points:
loop construct 1 mark
check if number is an integer 1 mark
counting the number of integers input 1 mark
output count value (outside the loop) 1 mark
sample algorithm:
FOR x ← 1 TO 1000 (1 mark)
INPUT Number
Difference ← INT(number) –
(1 mark)
Number
IF Difference = 0 THEN Total ←
Total + 1 (1 mark)
NEXT x
PRINT total (1 mark)
(NOTE: alternative to lines 3 and 4:
IF INT(Number) = Number THEN Total
(2 marks) )
← Total + 1
[Total: 4 marks]
7a
i) Many correct answers. They must be meaningful and related to Task 1. The names are
examples only.
One mark per mark point
Constant MaxCandidates
Value 4
Use The value of the maximum number of candidates for the election
ii) Many correct answers. They must be meaningful and related to Task 1. The names are
examples only.
One mark per mark point
Variable NumberCandidates
Use Storing the number of candidates in the election (for a tutor group)
Array CandidateNames
Use Storing the names of the candidates for the election
[Total: 7 marks]
7b
b) One mark per mark point (Max 4)
MP1 Change the value of the MaxCandidates constant/variable to 8
MP2 Change the input message to state the maximum number of candidates is 8 ...
MP3 ...how your program changed the input message
MP4 Change the loop limit to up to 8 ...
MP5 ...how your program changed the loop limit
MP6 Change the validation to allow input up to 8 ...
MP7 ...how your program changed its validation check
MP8 Change the array size(s) to ensure sufficient capacity to store up to 8 names ...
MP9 ...how your program changed the array sizes
MP10 Change the counters to ensure votes can be counted for up to 8 candidates ...
MP11 ...how your program changed its counters
[Total: 4 marks]
7c
c) Any five from:
MP1 Input with message to enter unique voter number
MP2 Validation of (unique) voter number entered e.g. length check/type check/range check
MP3 Attempt to check if voter number input is in list of possible voters
MP4 Attempt to check if they have already voted
MP5 If voter has already voted, message to warn them they can’t vote
MP6 Attempt at preventing them from voting
MP7 Store voter number in a suitable data structure
[Total: 5 marks]
Example answer
OUTPUT "Please enter your unique voter number"
INPUT UniqueVoterNumber
FoundFlag ← False
AllNumbersChecked ← False
Counter ← 0
WHILE FoundFlag = False AND AllNumbersChecked = False
IF StudentNumbers[Counter] = ""
THEN
AllNumbersChecked = True
StudentNumbers[Counter] ← UniqueVoterNumber
ELSE
IF UniqueVoterNumber = StudentNumbers[Counter]
THEN
FoundFlag = True
PRINT “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
7d
d) Explanation of how the program does the following:
Any four from:
MP1 Find out how many votes in total (for all candidates) were cast in the
election.
MP2 For each candidate
MP3 ... calculate the percentage of votes
MP4 ... excluding abstentions.
MP5 Display the name of each candidate, the number of votes and the
percentage of votes they received with appropriate messages.
MP6 Display the number of votes cast and the number of abstentions with
appropriate message.
[Total: 4 marks]
One mark per bullet point
37
Data type name Integer
Data type description (Any) whole number
Cambridge2021
Data type name String
Data type description A group of characters/text
47.86
Data type name Real
Data type description (Any real) number that could be a whole number or a fraction
[Total: 6 marks]
Any three correct statements (Max 3) e.g.
MP1 Add an input facility to allow teachers to enter the class size
MP2 Add a variable to store the input class size
MP3 Use the class size variable as the terminating condition for the loop
MP4 Make sure the arrays are sufficiently large to accommodate the largest possible class
size
[Total: 3 marks]