Past paper – A Level Computer Science (9618)
Cambridge International AS & A Level · 9618
Computer Science · Paper 42
May/June 2026 · 9618/42/M/J/26
Answer on paper, open each mark scheme and give yourself marks, then open the Summary.
Question text
A program stores nine lower‑case strings in a 1D array TheData. The following strings are
1
stored in the order shown:
laptop
tablet
printer
computer
processor
monitor
memory
cable
touchscreen
(a) Write program code to declare the array TheData in the main program. Store the given
strings in the array.
Save your program as Question1_J26.
Copy and paste the program code into 1(a) in the evidence document.
[2]
The procedure FindLongestShortest():
(b) (i)
•
takes an array of strings as a parameter
•
finds and outputs the longest string in the array of strings
•
finds and outputs the shortest string in the array of strings.
All outputs must have appropriate messages. Do not use in‑built functions to find the
longest and shortest string in the array. You may use an in‑built length function to find
the length of a string.
You can assume that there will only be one string that has the shortest length.
You can assume that there will only be one string that has the longest length.
Write program code for FindLongestShortest()
Save your program.
Copy and paste the program code into 1(b)(i) in the evidence document.
[5]
© Cambridge University Press & Assessment 2026
Write program code to extend the main program to call FindLongestShortest()
(ii)
with TheData
Save your program.
Copy and paste the program code into 1(b)(ii) in the evidence document.
[1]
(iii)
Test your program
Take a screenshot of the output(s).
Save your program.
Copy and paste the screenshot into 1(b)(iii) in the evidence document.
[1]
The function InsertionSort():
(c) (i)
•
takes an array of strings as a parameter
•
sorts the strings in the array into ascending alphabetical order using an insertion sort
•
returns the sorted array.
The function must work for an array of any length. Do not use an in‑built function to sort
the array.
Write program code for InsertionSort()
Save your program.
Copy and paste the program code into 1(c)(i) in the evidence document.
[5]
(ii)
Write program code to extend the main program to perform the following in the
order shown:
•
output the string "Before sorting"
•
output the contents of the array TheData
•
call InsertionSort() with TheData as a parameter
•
output the string "After sorting"
•
output the contents of the returned sorted array.
Save your program.
Copy and paste the program code into 1(c)(ii) in the evidence document.
[3]
(iii)
Test your program
Take a screenshot of the output(s).
Save your program.
Copy and paste the screenshot into 1(c)(iii) in the evidence document.
[1]
© Cambridge University Press & Assessment 2026
Question text
2
A program stores data about avatars in a program using Object‑Oriented Programming (OOP).
An avatar is a character that a user can control in a game.
The class Avatar stores the data about avatars.
Avatar
TheName : String
stores the name of the avatar
Glasses : Boolean
stores TRUE if the avatar wears glasses
stores FALSE if the avatar does not wear glasses
Hair : String
stores the colour of the avatar's hair
Age : Integer
stores the age of the avatar
Constructor()
initialises all attributes to its parameter values
GetName()
returns the name of the avatar
GetAge()
returns the age of the avatar
MeetCriteria()
takes the glasses choice and hair choice as parameters
and returns whether the avatar matches the choices
Write program code to declare the class Avatar and its constructor. All attributes must
(a) (i)
be private.
Do not declare the other methods.
Use your programming language appropriate constructor.
If you are writing in Python, include attribute declarations using comments.
Save your program as Question2_J26.
Copy and paste the program code into 2(a)(i) in the evidence document.
[4]
The get methods GetName() and GetAge() each return the relevant attribute.
(ii)
Write program code for GetName() and GetAge()
Save your program.
Copy and paste the program code into 2(a)(ii) in the evidence document.
[3]
© Cambridge University Press & Assessment 2026
The method MeetCritera() takes two parameters:
(iii)
•
a Boolean value to identify whether the avatar wears glasses
•
a string value to identify the hair colour.
The method checks whether this avatar’s attributes match both of the parameters.
Boolean TRUE is returned when both of the attributes match the parameters, otherwise
Boolean FALSE is returned.
Write program code for MeetCriteria()
Save your program.
Copy and paste the program code into 2(a)(iii) in the evidence document.
[2]
The text file AvatarFile.txt stores data for 30 avatars. Each avatar is on a new line
(b) (i)
in the file. The data is stored in the order: name, glasses, hair colour, age. Each value is
separated by a space.
For example, the first line in the file is:
Kit True blonde 21
The name of the avatar is Kit, the avatar wears glasses, the avatar has blonde hair, the
avatar is 21 years old.
The procedure LoadAvatars() reads the data from the text file into the program. The
function creates a new object for each avatar in the file and stores the avatar objects in
a global array with the identifier AvailableAvatars
The procedure uses exception handling when opening and reading from the file.
Write program code for LoadAvatars()
Save your program.
Copy and paste the program code into 2(b)(i) in the evidence document.
[7]
Write program code for the main program to call LoadAvatars()
(ii)
Save your program.
Copy and paste the program code into 2(b)(ii) in the evidence document.
[1]
© Cambridge University Press & Assessment 2026
The procedure EnterChoices() prompts the user to enter whether they want an
(c) (i)
avatar that wears glasses and the hair colour they want.
The procedure takes these two values as input until they are valid:
•
wearing glasses can only be yes or no
•
the hair colour can be black, blonde, brown, pink, red or green.
The procedure calls the method MeetCriteria() for each avatar in
AvailableAvatars and stores the avatars that match the criteria in a global array.
Write program code for EnterChoices()
Save your program.
Copy and paste the program code into 2(c)(i) in the evidence document.
[6]
(ii)
Write program code to extend the main program to:
•
call EnterChoices()
•
output the quantity of avatars that match the criteria
•
output the name and age of each avatar that matches the criteria.
All outputs must include an appropriate message.
Save your program.
Copy and paste the program code into 2(c)(ii) in the evidence document.
[5]
© Cambridge University Press & Assessment 2026
(d) (i)
Test your program with the following data as input:
Question text
A 2D array is used to store the linked list, LinkedList. The linked list stores a maximum of
3
eight data items. Each data item is an integer.
The array elements not currently used in the linked list are stored as the empty list.
LinkedList has two pointers:
•
StartLinkedList stores a pointer to the first node in the linked list
•
StartEmptyList stores a pointer to the first node in the empty list.
A data value of -1 indicates there is no data in the node.
A pointer of -1 indicates it is the end of the linked list, or the end of the empty list.
The linked list and pointers all have global scope.
The linked list already has the following data stored:
array index
data
pointer
0
9512
5
1
5541
3
2
1999
0
3
6651
–1
4
–1
6
5
5612
1
6
–1
–1
7
–1
4
StartLinkedList currently stores 2
StartEmptyList currently stores 7
(a) Write program code to declare and initialise the linked list and the pointers.
Save your program as Question3_J26.
Copy and paste the program code into 3(a) in the evidence document.
[5]
© Cambridge University Press & Assessment 2026
The procedure PrintListItems() outputs the data in each node of the linked list.
(b) (i)
The procedure starts with the first node in the linked list and follows the pointers until it
has reached the end of the linked list.
Write program code for PrintListItems()
Save your program.
Copy and paste the program code into 3(b)(i) in the evidence document.
[4]
The procedure PrintEmptyList() outputs the index of each node in the empty list.
(ii)
The procedure starts with the first node in the empty list and follows the pointers until it
has output the index of each node in the empty list.
Write program code for PrintEmptyList()
Save your program.
Copy and paste the program code into 3(b)(ii) in the evidence document.
[3]
(iii)
Write program code to extend the main program to:
•
output "Linked list" and then call PrintListItems()
•
output "Empty list" and then call PrintEmptyList()
Save your program.
Copy and paste the program code into 3(b)(iii) in the evidence document.
[2]
(iv)
Test your program.
Take a screenshot of the output(s).
Save your program.
Copy and paste the screenshot into 3(b)(iv) in the evidence document.
[2]
© Cambridge University Press & Assessment 2026
(c) New nodes are inserted at the end of the linked list.
The procedure AddItem() takes an integer parameter, inserts the parameter in the space
identified by StartEmptyList and updates the appropriate pointer(s).
If there is no space in the linked list, the procedure outputs "List is full"
Write program code for AddItem()
(i)
Save your program.
Copy and paste the program code into 3(c)(i) in the evidence document.
[8]
(ii)
Write program code to extend the main program to:
•
use AddItem() to insert a new node into the linked list with the data 8451
•
output the new contents of the linked list using PrintListItems() with a
suitable heading
•
output the new contents of the empty list using PrintEmptyList() with a
suitable heading.
Save your program.
Copy and paste the program code into 3(c)(ii) in the evidence document.
[2]
(iii)
Test your program.
Take a screenshot of the output(s).
Save your program.
Copy and paste the screenshot into 3(c)(iii) in the evidence document.
[1]
© Cambridge University Press & Assessment 2026
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 (Cambridge University Press & Assessment) 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 our Copyright
Acknowledgements Booklet. This is produced for each series of examinations and is freely