Cambridge International AS & A Level: Computer Science 9608/41
Cambridge International AS & A Level: Computer Science 9608/41
Cambridge International AS & A Level: Computer Science 9608/41
* 1 5 8 7 7 1 7 4 0 3 *
2 hours
INSTRUCTIONS
● Answer all questions.
● Use a black or dark blue pen.
● Write your name, centre number and candidate number in the boxes at the top of the page.
● Write your answer to each question in the space provided.
● Do not use an erasable pen or correction fluid.
● Do not write on any bar codes.
● You may use an HB pencil for any diagrams, graphs or rough working.
● Calculators must not be used in this paper.
INFORMATION
● The total mark for this paper is 75.
● The number of marks for each question or part question is shown in brackets [ ].
● No marks will be awarded for using brand names of software packages or hardware.
DC (LO) 214519
© UCLES 2021 [Turn over
2
The user then enters the code for the item they would like the machine to dispense (give out). The
user must re-enter the code until it is valid.
If the code is valid but the user has not inserted enough money for the item chosen, the machine
waits for more coins to be inserted. The user then has to re-enter the code.
The user can press cancel at any time to return the money inserted into the machine.
(a) The state-transition diagram shows the different states of the vending machine.
..........................
Total the
money
Cancel inserted
Return ..............................
money
......................
Check
Cancel code
valid
Code re-entered
Valid code
Check .................
............. Sufficient money
total
inserted .................
.............
[5]
(b) The vending machine is part of a program that is written using object-oriented programming
(OOP). The vending machine makes use of two classes that are described in the following
tables.
foodItem
vendingMachine
(i) Write program code to declare the class vendingMachine. You are only required to
write program code for the attribute declarations and the constructor.
Program code
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
..................................................................................................................................... [4]
(ii) The method checkValid() takes the food item code as a parameter. It checks the
code against each element in items and returns:
Program code
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
..................................................................................................................................... [5]
(iii) Four objects of type foodItem are declared with the identifiers:
Program code
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
..................................................................................................................................... [2]
© UCLES 2021 9608/41/M/J/21 [Turn over
6
2 Peter uses a record structure, customer, to store data about customers. The data includes:
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
............................................................................................................................................. [3]
(b) The customer records are stored in a random file. The location of each record is calculated as
a hash value using:
(i) Calculate the hash value for each of the customer IDs in the following table.
(ii) Two or more records could have the same hash value that results in a collision.
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
..................................................................................................................................... [3]
You can assume that both the file and the record being accessed exist.
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
..................................................................................................................................... [5]
3 Alix manages a team of programmers who are creating a new computer game.
Alix has listed some of the tasks, along with their estimated time to complete and their immediate
predecessors in the following table:
Time to complete
Task Description Predecessors
(weeks)
A Design character – 1
Program character
B A 1
movement
C Design level 1 – 2
D Program level 1 C 2
E Design robot – 1
F Program robot movement E 1
G Integrate character in level 1 B, D 2
H Integrate robot in level 1 F, G 2
I Design level 2 C 2
J Program level 2 D, I 2
K Test level 1 H 3
Integrate character and
L J, K 2
robot into level 2
(a) Complete the Program Evaluation Review Technique (PERT) chart for the tasks in the table.
.........
4 7
.........
E
1
.........
2 5
.........
A K L
9 12 13
1 H 3 2
.........
C ......... 8 2
1 3 6 .........
2 .........
I ......... 11
2
10 .........
[5]
(b) Explain how the tasks in the table can be divided between the team to allow concurrency of
tasks.
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
............................................................................................................................................. [2]
(c) Explain the benefits of the team using program libraries in the development of the program.
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
............................................................................................................................................. [3]
(d) Identify two features in an editor that the developers can use to help them create their
programs.
Feature 1 ..................................................................................................................................
Feature 2 ..................................................................................................................................
[2]
4 Chon creates a binary tree structure to store options that the user can select from a menu (M) in
his program.
C R
A G L W
If option G is selected, the user must choose either option D or option H. If option L is selected,
the user must choose either option J or option P.
C R
A G L W
[2]
© UCLES 2021 9608/41/M/J/21
11
(b) Each node in the binary tree is stored using the following record structure:
TYPE node
leftPointer : INTEGER
data : STRING
rightPointer : INTEGER
ENDTYPE
The tree is stored as a 1D array, binaryTree. Null pointers are represented by –1.
(i) The table shows the contents of the three fields in each record stored in the 1D array
binaryTree.
Complete the table to show the contents of binaryTree from part (a).
0 M
freePointer 1 C
2 A
3 L
4 G
5 R
6 W
7 J
8 D
9 P
10 H
11
[4]
(ii) Write pseudocode to declare the array binaryTree to store up to 100 objects of type
node.
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
..................................................................................................................................... [2]
M
C R
A G L W
The pre-order traversal can be written as a recursive procedure:
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
ENDPROCEDURE
[6]
(a) The pseudocode function binarySearch()performs a binary search to find a given value in
the global array, dataArray. If the value is found, the function returns its index. If the value
is not found, the function returns –1.
flag -2
mid 0
THEN
RETURN …………………………………………
ELSE
THEN
………………………………………… …………………………………………
ELSE
THEN
………………………………………… …………………………………………
ELSE
RETURN …………………………………………
ENDIF
ENDIF
ENDIF
ENDWHILE
ENDFUNCTION
[4]
© UCLES 2021 9608/41/M/J/21
15
Program code
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
............................................................................................................................................. [5]
6 The table shows assembly language instructions for a processor that has one general purpose
register, the Accumulator (ACC), and an Index Register (IX).
Instruction
Label Op Operand Explanation
code
LDM #n Immediate addressing. Load the number n to ACC
Direct addressing. Load the contents of the location at
LDD <address>
the given address to ACC
Indexed addressing. Form the address from <address>
LDX <address> + the contents of the Index Register. Copy the contents
of this calculated address to ACC
LDR #n Immediate addressing. Load the number n to IX
STO <address> Store contents of ACC at the given address
ADD <address> Add the contents of the given address to ACC
INC <register> Add 1 to the contents of the register (ACC or IX)
Bitwise AND operation of the contents of ACC with the
AND <address>
contents of <address>
Bitwise XOR operation of the contents of ACC with the
XOR <address>
contents of <address>
Bitwise OR operation of the contents of ACC with the
OR <address>
contents of <address>
Output to screen the character whose ASCII value is
OUT
stored in ACC
Compare the contents of ACC with the contents of
CMP <address>
<address>
CMP #n Compare the contents of ACC with number n
Following a compare instruction, jump to <address> if
JPE <address>
the compare was True
Following a compare instruction, jump to <address> if
JPN <address>
the compare was False
JMP <address> Jump to the given address
END Return control to the operating system
<label>: <op Labels an instruction
<operand>
code>
<label>: <data> Gives a symbolic address <label> to the memory
location with contents <data>
An algorithm takes each letter of a stored 5-letter word and checks if the letter is upper case.
If the letter is not upper case, it converts the letter to upper case and then outputs it.
All ASCII upper case letters have 010 as the three most significant bits.
Complete the assembly language program for the algorithm described using the instruction set
provided on the previous page.
Instruction
Comment
Label Op code Operand
// increase count by 1
INC IX // increase IX by 1
word: B01001000
B01101111
B01110101
B01110011
B01100101
mask1: B00100000
mask2: B11011111
count: 0
[6]
The procedure initialises all array elements to −1 and the pointer to −1.
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
............................................................................................................................................. [3]
(b) The function pop() pops and returns the item from the top of the stack. If the stack is empty,
it returns −1.
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
............................................................................................................................................. [3]
BLANK PAGE
BLANK PAGE
Permission to reproduce items where third-party owned material protected by copyright is included has been sought and cleared where possible. Every
reasonable effort has been made by the publisher (UCLES) to trace copyright holders, but if any items requiring clearance have unwittingly been included, the
publisher will be pleased to make amends at the earliest possible opportunity.
To avoid the issue of disclosure of answer-related information to candidates, all copyright acknowledgements are reproduced online in the Cambridge
Assessment International Education Copyright Acknowledgements Booklet. This is produced for each series of examinations and is freely available to download
at www.cambridgeinternational.org after the live examination series.
Cambridge Assessment International Education is part of the Cambridge Assessment Group. Cambridge Assessment is the brand name of the University of
Cambridge Local Examinations Syndicate (UCLES), which itself is a department of the University of Cambridge.