Cambridge International AS & A Level: Computer Science 9608/42 May/June 2021
Cambridge International AS & A Level: Computer Science 9608/42 May/June 2021
Published
This mark scheme is published as an aid to teachers and candidates, to indicate the requirements of the
examination. It shows the basis on which Examiners were instructed to award marks. It does not indicate the
details of the discussions that took place at an Examiners’ meeting before marking began, which would have
considered the acceptability of alternative answers.
Mark schemes should be read in conjunction with the question paper and the Principal Examiner Report for
Teachers.
Cambridge International will not enter into discussions about these mark schemes.
Cambridge International is publishing the mark schemes for the May/June 2021 series for most Cambridge
IGCSE™, Cambridge International A and AS Level components and some Cambridge O Level components.
These general marking principles must be applied by all examiners when marking candidate answers. They should be applied alongside the
specific content of the mark scheme or generic level descriptors for a question. Each question paper and mark scheme will also comply with these
marking principles.
• the specific content of the mark scheme or the generic level descriptors for the question
• the specific skills defined in the mark scheme or in the generic level descriptors for the question
• the standard of response required by a candidate as exemplified by the standardisation scripts.
Marks awarded are always whole marks (not half marks, or other fractions).
• marks are awarded for correct/valid answers, as defined in the mark scheme. However, credit is given for valid answers which go beyond the
scope of the syllabus and mark scheme, referring to your Team Leader as appropriate
• marks are awarded when candidates clearly demonstrate what they know and can do
• marks are not deducted for errors
• marks are not deducted for omissions
• answers should only be judged on the quality of spelling, punctuation and grammar when these features are specifically assessed by the
question as indicated by the mark scheme. The meaning, however, should be unambiguous.
Rules must be applied consistently, e.g. in situations where candidates have not followed instructions or in the application of generic level
descriptors.
Marks should be awarded using the full range of marks defined in the mark scheme for the question (however; the use of the full mark range may
be limited according to the quality of the candidate responses seen).
Marks awarded are based solely on the requirements as defined in the mark scheme. Marks should not be awarded with grade thresholds or
grade descriptors in mind.
1(a) Horse 1
Horse
Donkey Kangaroo
Fish Jaguar
or
TYPE Booking
DECLARE BookingID : INTEGER
DECLARE CustomerID : INTEGER
DECLARE ItemID : INTEGER
DECLARE Quantity : INTEGER
ENDTYPE
Example code
VB.NET
Function Hash(BookingID)
Hash = BookingID Mod 100000 + 3
End Function
Python
def Hash(BookingID):
HashV = BookingID % 100000 + 3
return HashV
Pascal
Function Hash(BookingID:Integer):Integer
begin
Hash := BookingID MOD 100000 + 3
end;
5012345 12348
8212350 12353
Example pseudocode
FUNCTION StoreBooking(BookingRecord : Booking) RETURNS Boolean
RecordLocation ← Hash(BookingRecord.BookingID)
Filename ← "TheBookings.dat"
OPENFILE Filename FOR RANDOM
SEEK Filename, RecordLocation
GETRECORD Filename, RecordData
IF RecordData = NULL
THEN
PUTRECORD Filename, BookingRecord
CLOSE Filename
RETURN True
ELSE
CLOSE Filename
RETURN False
ENDIF
ENDFUNCTION
Example code
VB.NET
Class QuizClass
Private Questions(19) As QuestionClass
Private NumberOfQuestions As Integer
Python
class QuizClass():
#Private Questions[20] self.__QuestionClass
#Private self.__NumberOfQuestions Integer
def __init__(self):
self.__NumberOfQuestions = 0
3(a) Pascal
type QuizClass = class
private
NumberOfQuestions: Integer;
Questions : array[0..19] of QuestionClass;
public
Constructor init();
end;
Constructor QuizClass.init();
begin
NumberOfQuestions := 0;
end;
Example code
VB.NET
Public Function AddQuestion(QuestionObject)
If NumberOfQuestions < 20 Then
Questions(NumberOfQuestions) = QuestionObject
NumberOfQuestions = NumberOfQuestions + 1
return True
Else
return False
End If
End Function
Python
def AddQuestion(self, QuestionObject):
if self.__NumberOfQuestions < 20:
self.__Questions[self.__NumberOfQuestions] = QuestionObject
self.__NumberOfQuestions = self.__NumberOfQuestions + 1
return True
else:
return False
3(b) Pascal
Function AddQuestion(QuestionObject:QuestionClass):Boolean;
begin
if NumberOfQuestions < 20 then
Questions[NumberOfQuestions] := QuestionObject;
NumberOfQuestions := NumberOfQuestions + 1;
return True;
else
return False;
end;
Example code
Python
FirstQuiz = QuizClass()
Question1 = QuestionClass("What is 100/5?", "20", 1)
FirstQuiz.AddQuestion(Question1)
Pascal
FirstQuiz := QuizClass.Create();
Question1 := QuestionClass.Create("What is 100/5?", "20", 1);
FirstQuiz.AddQuestion(Question1);
3(d) Containment 1
© UCLES 2021 Page 12 of 20
9608/42 Cambridge International AS & A Level – Mark Scheme May/June 2021
PUBLISHED
Question Answer Marks
Interpreter:
• Writing the code // debugging // when testing for errors
Compiler:
• Program is complete // program needs distributing // program is bug-free // user acceptance stage // beta testing stage
// writing the program // when debugging
e.g.
• Pretty print // colour coding
• Colours key words in different colours
• So you can see where there are errors
• Auto-complete
• automatically adds closing statements
• Saves the user typing these terms
• Auto-indent
• Moves the code to the correct location
• So that it is easier to read
• So that the correct code is inside each construct
• Auto-correct
• Changes spelling mistakes
• To reduce syntax errors
• Collapse/expand modules
• Allows you to hide sections of code
• To make it easier to read the code you are focused on
0 1 2 3 4 5 6 7 8 9
50 89 500 23 2 23 100
HeadIndex: 4
TailIndex: 1
IF NumberInQueue > 9 // = 10
THEN
RETURN False
ELSE
MyNumbers[TailIndex] ← DataToInsert
TailIndex ← TailIndex + 1
IF TailIndex > 9
THEN
TailIndex ← 0
ENDIF
NumberInQueue ← NumberInQueue + 1
RETURN True
ENDIF
ENDFUNCTION
(Otherwise)
• Incrementing HeadIndex …
• …catching if it goes above 9 and setting to 0
• Decrement NumberInQueue
• returning first element
Example pseudocode
FUNCTION Dequeue() RETURNS INTEGER
DECLARE ItemToReturn : INTEGER
IF NumberInQueue = 0
THEN
ItemToReturn ← -1
ELSE
ItemToReturn ← MyNumbers(HeadIndex)
IF HeadIndex = 9
THEN
HeadIndex ← 0
ELSE
HeadIndex ← HeadIndex + 1
ENDIF
NumberInQueue ← NumberInQueue - 1
ENDIF
RETURN ItemToReturn
ENDFUNCTION
PROCEDURE InsertionSort()
DECLARE Count : INTEGER
DECLARE Counter : INTEGER
DECLARE Temp : INTEGER
Count ← 1
WHILE Count < 10
Temp = TheArray[Count]
Counter = Count - 1
Available username N Y N Y N Y N Y
Suitable password N N Y Y N N Y Y
Age > 16 N N N N Y Y Y Y
"Too young" Y Y Y Y N N N N
Available username – N –
Suitable password – – N
Age > 16 N Y Y
"Too young" Y N N
Game
over Meet
animal
Animal health >=
10
animal strength
>=10
Character animal strength
< 10
(Health)
= 0 // <=0 // <1
animal strength < 10
Compete Animal
runs
away
Instruction
Label Op code Operand
LDR #0
LOOP LDX character
LSL #1
OUT
INC IX
LDD count
INC ACC
STO count
CMP #3
JPN LOOP
END
count: 0
Character: B01000001
B10001110
B01000100