8.1 Programming Concepts Model Answers
8.1 Programming Concepts Model Answers
a)
[Total: 4 marks]
B; [1 mark]
[Total: 1 mark]
C; [1 mark]
[Total: 1 mark]
4a
DECLARE X : STRING
DECLARE Y : INTEGER
DECLARE Z : INTEGER
[Total: 3 marks]
4b
For example:
X ← "Programming is fun"
OUTPUT Length(X)
Y ← 16
Z ← 3
OUTPUT SubString(X,Y,Z)
[Total: 6 marks]
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
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)
e.g. The first student with the highest score will be output
[Total: 6 marks]
6a
a) marking points:
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:
[Total: 4 marks]
7a
i) Many correct answers. They must be meaningful and related to Task 1. The names are
examples only.
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.
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
[Total: 4 marks]
7c
[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
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]
37
Cambridge2021
[Total: 6 marks]
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]