Data types, records, arrays and abstract data types – A Level Computer Science (9618)

28 questions · page 1 of 2 · Clear filters

0 / 0Answer a question to start your score.
Quick quiz (10)Saved 0
Advertisement
1
9618/41/M/J/26 · Question 1May/June 2026Paper 4126 marks
Loading question…
Question text

1
A program stores integer data in a linear queue.
The queue is created as a global 1D array with space for 10 elements.
The queue has a global head pointer, initialised to –1, that points to the first element in
the queue.
The queue has a global tail pointer, initialised to –1, that points to the last element in the queue.
(a) The main program initialises the 10 elements of the queue to –1 and initialises the
two pointers.
Write program code to declare the global variables and initialise the queue and its pointers.
Save your program as Question1_J26.
Copy and paste the program code into 1(a) in the evidence document.
[3]
(b) The function Enqueue() performs these tasks:
•
takes an integer parameter
•
checks if the queue is full
•
returns Boolean FALSE, if the queue is full
•
stores the parameter in the queue, updates the appropriate pointer(s) and returns
Boolean TRUE, if the queue is not full.
Write program code for Enqueue()
Save your program.
Copy and paste the program code into 1(b) in the evidence document.
[7]
© Cambridge University Press & Assessment 2026
(c) (i)
Write program code to extend the main program to:
•
take 11 integers as input from the user
•
use the appropriate function to insert each integer into the queue
•
output a message if at any point the queue is full
•
output the final content of the queue array. Do not dequeue the data.
You do not need to validate the data input.
Save your program.
Copy and paste the program code into 1(c)(i) in the evidence document.
[5]
(ii)
Test your program.
Enter the following data as input in the order given:
1
2
3
4
5
6
7
8
9
10
11
Take a screenshot of the output(s).
Save your program.
Copy and paste the screenshot into 1(c)(ii) in the evidence document.
[1]
© Cambridge University Press & Assessment 2026
(d) The function Dequeue():
•
returns –1 if the queue is empty
•
updates the pointer(s) and returns the next item from the queue if the queue is
not empty.
Write program code for Dequeue()
Save your program.
Copy and paste the program code into 1(d) in the evidence document.
[6]
(e) (i)
Write program code to amend the main program to:
•
take 6 integers as input from the user and store them in the queue using the
appropriate function
•
use the appropriate function to remove 4 elements from the queue
•
output each removed element from the queue.
Save your program.
Copy and paste the program code into 1(e)(i) in the evidence document.
[3]
(ii)
Test your program.
Enter the following data as input in the order given:
100
10
5
6
18
68
Take a screenshot of the output(s).
Save your program.
Copy and paste the screenshot into 1(e)(ii) in the evidence document.
[1]
© Cambridge University Press & Assessment 2026

2
9618/41/M/J/26 · Question 2May/June 2026Paper 4128 marks
Loading question…
Question text

2
A program stores data about toys that are made from bricks. The toys are stored in a record
structure with four fields:
•
ToyName: the string name of the toy
•
NumberBricks: the integer number of bricks in the toy
•
Difficulty: the string difficulty level of the toy (easy, medium or expert)
•
Category: the string category of the toy (for example town, display, play).
(a) Write program code to declare a record structure with the identifier ToyRecord and the
four fields.
Save your program as Question2_J26.
Copy and paste the program code into 2(a) in the evidence document.
[2]
(b) The text file Toys.txt stores data about 16 toys. Each toy is on a new line in the file. The
data is stored in the order: toy name, number of bricks, difficulty, category. Each value is
separated by a comma.
For example, the first line in the file is:
Fire Station,3981,Expert,Town
The name of the toy is Fire Station. The toy has 3981 bricks. The difficulty level is Expert.
The category is Town.
The function ReadData():
(i)
•
takes an array of type ToyRecord as a parameter
•
opens the file Toys.txt and reads in the data
•
creates a new record of type ToyRecord for each toy read from the file
•
stores each record in the parameter array
•
returns the populated array.
The function uses exception handling when opening and reading from the file.
Write program code for ReadData()
Save your program.
Copy and paste the program code into 2(b)(i) in the evidence document.
[8]
© Cambridge University Press & Assessment 2026
The procedure OutputToys() takes an array of type ToyRecord as a parameter and
(ii)
outputs the data for each toy in the array.
Write program code for OutputToys()
Save your program.
Copy and paste the program code into 2(b)(ii) in the evidence document.
[3]
(iii)
Write program code for the main program to:
•
declare an array of type ToyRecord with space for 16 elements
•
call the function ReadData() with the empty array and store the returned array
•
call OutputToys() with the returned array.
Save your program.
Copy and paste the program code into 2(b)(iii) in the evidence document.
[3]
(iv)
Test your program.
Take a screenshot of the output(s).
Save your program.
Copy and paste the screenshot into 2(b)(iv) in the evidence document.
[1]
(c) The program needs to allow a user to enter the difficulty level of a toy and then write all toys
that match that difficulty level to an external text file.
The function SearchToys():
(i)
•
takes an array of type ToyRecord as a parameter
•
prompts the user to enter the difficulty level
•
takes the difficulty level as input until it is valid
•
creates a new array containing the ToyRecord objects that match the difficulty
level input
•
returns the populated array.
Write program code for SearchToys()
Save your program.
Copy and paste the program code into 2(c)(i) in the evidence document.
[5]
© Cambridge University Press & Assessment 2026
The procedure WriteToys():
(ii)
•
takes an array of type ToyRecord as a parameter
•
creates and opens the file SelectedToys.txt to write
•
writes each record from ToyRecord to SelectedToys.txt with each field
separated by a comma and each record on a new line. For example:
<ToyName>,<NumberBricks>,<Difficulty>,<Category>
Write program code for WriteToys()
Save your program.
Copy and paste the program code into 2(c)(ii) in the evidence document.
[3]
(iii)
Write program code to extend the main program to:
•
call SearchToys() with the populated array and store the return array
•
call WriteToys() with the returned array.
Save your program.
Copy and paste the program code into 2(c)(iii) in the evidence document.
[2]
(iv)
Test your program. Enter the appropriate input for a medium difficulty level
when prompted.
Take one screenshot of the text file the program produces with the contents and
filename clearly visible.
Save your program.
Copy and paste the screenshot into 2(c)(iv) in the evidence document.
[1]
© Cambridge University

3
9618/42/M/J/26 · Question 1May/June 2026Paper 4218 marks
Loading question…
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

Advertisement
4
9618/42/M/J/26 · Question 3May/June 2026Paper 4227 marks
Loading question…
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

5
9618/43/M/J/26 · Question 1May/June 2026Paper 4321 marks
Loading question…
Question text

A program stores 15 strings in the 1D array DataArray
1
(a) Write program code to declare the global 1D array DataArray with space for 15
string elements.
Save your program as Question1_J26.
Copy and paste the program code into 1(a) in the evidence document.
[1]
(b) The procedure CreateArray() takes 15 strings as input from the user. Each input is
converted to lower case and stored in DataArray in the order input.
Write program code for CreateArray()
Save your program.
Copy and paste the program code into 1(b) in the evidence document.
[4]
(c) The procedure OutputArray() outputs the data in each element in DataArray on one
line with a space between each element.
Write program code for OutputArray()
Save your program.
Copy and paste the program code into 1(c) in the evidence document.
[2]
© Cambridge University Press & Assessment 2026
Write program code for the main program to call CreateArray() and
(d) (i)
then OutputArray()
Save your program.
Copy and paste the program code into 1(d)(i) in the evidence document.
[1]
(ii)
Test your program. Enter the following data for the inputs in the order given:
1
One
2
TWO
three
??
house
99987
popping
green
eleven
12
Twenty
THIRTY
16
Take a screenshot of the output(s).
Save your program.
Copy and paste the screenshot into 1(d)(ii) in the evidence document.
[1]
© Cambridge University Press & Assessment 2026
(e) The procedure FindWords() takes a string as input from the user and converts it to
lower case. The procedure counts and outputs the number of times the input is stored
in DataArray
Write program code for FindWords(). Do not use an in‑built function to count the number
of times the input is stored in DataArray
Save your program.
Copy and paste the program code into 1(e) in the evidence document.
[5]
The procedure SortLength() uses a bubble sort to order the elements in DataArray
(f)
(i)
into ascending order by the length of each string.
The bubble sort needs to be efficient and stop iterating as soon as it identifies that
DataArray is in the correct order.
Write program code for SortLength(). Do not use an in‑built function to sort the array
or check if the array is in the correct order.
Save your program.
Copy and paste the program code into 1(f)(i) in the evidence document.
[5]
Write program code to extend the main program by calling FindWords() then
(ii)
SortLength() then OutputArray()
Save your program.
Copy and paste the program code into 1(f)(ii) in the evidence document.
[1]
© Cambridge University Press & Assessment 2026
(iii)
Test your program. Enter the following data to be stored in the array in the order given:
one
One
1
three
three
One
house
99987
popping
green
eleven
One
Twenty
THIRTY
One
Enter "one" as the string to find in the array.
Take a screenshot of the output(s).
Save your program.
Copy and paste the screenshot into 1(f)(iii) in the evidence document.
[1]
© Cambridge University Press & Assessment 2026

6
9618/43/M/J/26 · Question 3May/June 2026Paper 4325 marks
Loading question…
Question text

3
A binary tree is designed to store up to 100 positive integers. The binary tree stores data in
ascending numerical order.
The data in the binary tree is created as a global 2D array with the identifier BinaryTree
Each node has three values:
•
a pointer to the array index with the left node
•
the integer data
•
a pointer to the array index with the right node.
A null pointer is represented by the integer –1. All nodes are initialised with the null data –1
The table has example data for a binary tree:
index
left pointer
data
right pointer
0
1
20
2
1
4
10
–1
2
3
26
–1
3
–1
22
–1
4
–1
8
–1
The binary tree has two global pointers:
•
TreeRootPointer, initialised to –1, stores the index of the root node of the binary tree
•
FirstFreeNodePointer, initialised to 0, stores the index of the first node that does not
store any data.
Data cannot be removed or replaced from the tree. FirstFreeNodePointer is incremented
each time a node is added to the binary tree.
(a) The main program initialises all 100 nodes, TreeRootPointer
and FirstFreeNodePointer
Write program code for the main program.
Save your program as Question3_J26.
Copy and paste the program code into 3(a) in the evidence document.
[3]
© Cambridge University Press & Assessment 2026
(b) The procedure AddNode():
•
takes an integer parameter to be stored as the data in a new node
•
stores the data in the first element and updates the root pointer when the tree is empty
•
outputs "The tree is full" if the tree is full
•
stores the data in the next free node if the tree is not full, then:
◦
checks if the data is less than or greater than the root node
◦
follows the left or right pointer(s) repeatedly until it reaches the appropriate
leaf node
◦
updates the appropriate parent node pointer to the new node.
Write program code for AddNode()
Save your program.
Copy and paste the program code into 3(b) in the evidence document.
[7]
(c) The procedure OutputArray() outputs the content of the first 10 elements in the binary
tree. Each node is output on one line in the format:
<left pointer> <data> <right pointer>
For example:
1
20
4
Write program code for OutputArray()
Save your program.
Copy and paste the program code into 3(c) in the evidence document.
[2]
© Cambridge University Press & Assessment 2026
(d) (i)
Write program code to extend the main program to:
•
take 10 integers as input
•
store each input in the binary tree in the order they are entered using the
appropriate procedure
•
output the content of the binary tree using OutputArray()
Save your program.
Copy and paste the program code into 3(d)(i) in the evidence document.
[3]
(ii)
Test your program. Enter the following numbers in the order shown:
50
26
120
236
2
16
67
49
165
15
Take a screenshot of the output(s).
Save your program.
Copy and paste the screenshot into 3(d)(ii) in the evidence document.
[1]
© Cambridge University Press & Assessment 2026
(e) An in‑order tree traversal outputs the contents of the binary tree in ascending numerical
order by:
•
visiting the left node
•
output the data
•
visiting the right node.
For example, an in‑order traversal on the following binary tree will output: 5 12 18 20 26
20
12
26
5
18
The recursive procedure InOrder():
(i)
•
takes the root pointer as a parameter
•
makes a recursive call with the left pointer as the parameter if the left pointer is
not null
•
outputs the data at the parameter
•
makes a recursive call with the right pointer as the parameter if the right pointer is
not null.
Write program code for InOrder()
Save your program.
Copy and paste the program code into 3(e)(i) in the evidence document.
[7]
Write program code to extend the main program to call InOrder()
(ii)
Save your program.
Copy and paste the program code into 3(e)(ii) in the evidence document.
[1]
© Cambridge University Press & Assessment 2026
(iii)
Test your program. Enter the following numbers in the order given:
50
26
120
236
2
16

7
9618/41/M/J/25 · Question 1May/June 2025Paper 4120 marks
Loading question…
Question text

1
A program stores positive integers in a circular queue.
The queue is stored as a global 1D array of 20 integers with the identifier Queue. Each index is
initialised with the data –1
The global variable HeadPointer, initialised to –1, points to the first element in the queue.
The global variable TailPointer, initialised to –1, points to the last element in the queue.
The global variable NumberItems, initialised to 0, stores the number of items in the queue.
(a) Write program code to declare and initialise Queue, HeadPointer, TailPointer and
NumberItems
Save your program as Question1_J25.
Copy and paste the program code into part 1(a) in the evidence document.
[2]
(b) The function Enqueue():
•
takes an integer as a parameter
•
checks if the queue is full
•
returns FALSE if the queue is full
•
stores the parameter in the next position in the queue and returns TRUE if the queue is
not full
•
updates the appropriate pointers and NumberItems
Write program code for Enqueue()
Save your program.
Copy and paste the program code into part 1(b) in the evidence document.
[6]
(c) The main program:
•
attempts to store each of the integers 1 to 25 (inclusive) in the queue in ascending
numerical order using Enqueue()
•
outputs the integer that was passed to Enqueue() and "Successful" if it was stored
in the queue, or "Unsuccessful" if it was not stored in the queue.
For example:
if the integer 5 is passed to Enqueue() and is stored in the queue, the output will

be: "5 Successful"
if the integer 23 is passed to Enqueue() and is not stored in the queue, the output

will be: "23 Unsuccessful"
Write program code for the main program.
Save your program.
Copy and paste the program code into part 1(c) in the evidence document.
[3]
(d) The function Dequeue() returns –1 if the queue is empty. If the queue is not empty, the
function returns the next item in the queue, updates the appropriate pointers and updates
NumberItems
Write program code for Dequeue()
Save your program.
Copy and paste the program code into part 1(d) in the evidence document.
[6]
Write program code to extend the main program to call Dequeue() twice and output the
(e) (i)
return value each time.
Save your program.
Copy and paste the program code into part 1(e)(i) in the evidence document.
[2]
(ii)
Test your program.
Take a screenshot of the output(s).
Save your program.
Copy and paste the screenshot into part 1(e)(ii) in the evidence document.
[1]

8
9618/41/M/J/25 · Question 2May/June 2025Paper 4125 marks
Loading question…
Question text

2
A program reads data from a text file, splits the data depending on its content and stores the
separated data into different files.
The text file TheData.txt contains 72 lines of data. Each line of data has an integer number and
a string colour that are separated by a comma. For example, the first line in the file is:
10,red
The integer is 10 and the string is "red"
The file contains six different colours: red, green, blue, orange, yellow, pink.
(a) The function ReadData():
•
prompts the user to enter a filename and reads this filename from the user
•
opens the file and reads each line of data into a 1D array
•
returns the populated 1D array.
The function needs to work for a file that contains an unknown number of lines.
Write program code for ReadData()
Save your program as Question2_J25.
Copy and paste the program code into part 2(a) in the evidence document.
[7]
(b) The procedure SplitData() takes a 1D string array as a parameter with the identifier
DataArray
The procedure declares six 1D arrays: one array for each colour that appears in the file (red,
green, blue, orange, yellow, pink).
The procedure accesses each string in DataArray. The data in each string is split into the
integer and the colour. The integer is stored in the array that matches the colour.
For example, the first string in DataArray has the integer 10 and the colour red, so the
integer 10 is stored in the array for the colour red.
Write program code for SplitData()
Save your program.
Copy and paste the program code into part 2(b) in the evidence document.
[6]
(c) The procedure StoreData():
•
takes two parameters: a 1D array DataToStore and a filename
•
opens the text file with the filename that is passed as a parameter
•
appends each item of data from DataToStore to a new line in the text file
•
uses exception handling when opening and writing data to the text file.
Write program code for StoreData()
Save your program.
Copy and paste the program code into part 2(c) in the evidence document.
[5]
(d) Each of the six colours has a blank text file where the numbers will be stored. The names of
these six text files are:
•
Blue.txt
•
Green.txt
•
Orange.txt
•
Pink.txt
•
Red.txt
•
Yellow.txt
The procedure SplitData() needs amending to call StoreData() six times, with each of
the six colour arrays and the name of the text file that corresponds to that colour.
For example, StoreData() will be called with the red array and the file name "Red.txt"
Write program code to amend SplitData()
Save your program.
Copy and paste the program code into part 2(d) in the evidence document.
[2]
(e) The main program calls ReadData() and then SplitData()
(i)
Write program code for the main program.
Save your program.
Copy and paste the program code into part 2(e)(i) in the evidence document.
[3]
Test your program. Input the text "TheData.txt" when prompted.
(ii)
Take a screenshot of the output(s) and a screenshot showing the content of the file that
stores the red numbers.
Save your program.
Copy and paste the screenshot(s) into part 2(e)(ii) in the evidence document.
[2]

Advertisement
9
9618/42/M/J/25 · Question 1May/June 2025Paper 4227 marks
Loading question…
Question text

A program reads data from a text file and stores it in a stack. The stack Stack is stored as a 1D
1
array of up to 20 elements. The pointer TopOfStack stores the index of the last element stored in
the stack.
(a) Stack is a global array of strings with all elements initialised to "-1"
TopOfStack is a global variable initialised to –1
Write program code to declare and initialise Stack and TopOfStack
Save your program as Question1_J25.
Copy and paste the program code into part 1(a) in the evidence document.
[2]
(b) The function Push() takes a string parameter and attempts to store it on the stack.
The function returns –1 if the stack is full.
The function returns 1 if the parameter is successfully pushed onto the stack.
Write program code for Push()
Save your program.
Copy and paste the program code into part 1(b) in the evidence document.
[4]
(c) The function Pop() returns the next item from the stack.
The function returns "–1" if the stack is empty.
Write program code for Pop()
Save your program.
Copy and paste the program code into part 1(c) in the evidence document.
[4]
(d) The text file StackData.txt stores numbers and mathematical operators. Each number
and operator are on a new line in the text file.
The mathematical operators used in this program are:
mathematical
meaning
operator
+
addition
–
subtraction
/
division
*
multiplication
^
power of
The procedure ReadData():
•
takes a string filename as a parameter
•
opens the file and reads in each line of data
•
uses the Push() function to insert each line of data onto the stack
•
outputs "Stack full" if any data cannot be stored on the stack because the stack is
full
•
uses exception handling when opening and reading from the text file.
The procedure needs to work for a file that contains an unknown number of lines.
Write program code for ReadData()
Save your program.
Copy and paste the program code into part 1(d) in the evidence document.
[6]
(e) The values stored in the stack are used to perform mathematical operations.
A total is initialised to the first value in the stack. The first value in the stack will always be a
number.
The next value will be a mathematical operator and the next value will be the number to apply
to the calculation. This is repeated until there are no values left in the stack. There will always
be a number following a mathematical operator.
For example, the contents of a stack are:
TopOfStack
10
+
3
–
2
The total is initialised to the first value in the stack: 10
total = 10
The next two values are: + 3
total = 10 + 3 = 13
The next two values are: – 2
total = 13 – 2 = 11
The final total is 11 and this is returned.
Write program code for the function Calculate() to:
•
take each value from the stack
•
calculate and return the final total.
Save your program.
Copy and paste the program code into part 1(e) in the evidence document.
[7]
(f)
(i)
Write program code to extend the main program to:
•
take a filename as input from the user
•
call ReadData() with the input filename
•
call Calculate()
•
output the final total.
Save your program.
Copy and paste the program code into part 1(f)(i) in the evidence document.
[2]
(ii)
Test your program twice with the file names:
StackData.txt
SecondStack.txt
Take a screenshot of the output(s).
Save your program.
Copy and paste the screenshot into part 1(f)(ii) in the evidence document.
[2]

10
9618/42/M/J/25 · Question 2May/June 2025Paper 4222 marks
Loading question…
Question text

A program stores data in a 1D array of records, HashTable. The array has space for 200 records.
2
Each data item is stored in a specific index of the array that is calculated using an algorithm. The
index is calculated from the key field using the formula: Key MOD 200
If two key fields generate the same index, there is a collision. Any records that have a collision
are stored in a second array, Spare. This array has space for 100 records. When a collision is
detected, the record is stored in the next free space in Spare.
(a) The pseudocode record format is:
TYPE NewRecord
DECLARE Key : INTEGER
DECLARE Item1 : INTEGER
DECLARE Item2 : INTEGER
ENDTYPE
Write program code to declare the record type NewRecord
If your chosen programming language does not support record formats, a class can be used
instead.
Save your program as Question2_J25.
Copy and paste the program code into part 2(a) in the evidence document.
[2]
Write program code to declare the global arrays HashTable and Spare
(b) (i)
Save your program.
Copy and paste the program code into part 2(b)(i) in the evidence document.
[1]
An empty record has the integer –1 stored in each field.
(ii)
The procedure Initialise() stores an empty record in each element in HashTable
and Spare
Write program code for Initialise()
Save your program.
Copy and paste the program code into part 2(b)(ii) in the evidence document.
[2]
(c) The hash value is calculated from the key field using the formula: Key MOD 200
The function CalculateHash() takes a key field as a parameter and calculates and returns
the hash value for the key field.
Write program code for CalculateHash()
Save your program.
Copy and paste the program code into part 2(c) in the evidence document.
[2]
(d) The procedure InsertIntoHash():
•
takes a record of type NewRecord as a parameter
•
uses CalculateHash() to calculate the hash value for the key field in the record
•
checks if the hash value index in HashTable currently stores an empty record
○ if the index stores an empty record, store the parameter in this index
○ if the index does not store an empty record, store the parameter in Spare
You can assume there will always be enough space in Spare to store any collisions.
Write program code for InsertIntoHash()
Save your program.
Copy and paste the program code into part 2(d) in the evidence document.
[6]
(e) The text file HashData.txt stores up to 200 rows of data to be stored into the hash table.
Each row contains three integer numbers separated by commas.
The first number is the key field, the second number is item 1 and the third number is item 2.
For example:
The first row in the text file contains: 646, 12, 568
The key field is 646, item 1 is 12 and item 2 is 568
The procedure CreateHashTable():
•
opens the file HashData.txt
•
creates a record for each row of data in the file
•
calls InsertIntoHash() with each record.
Write program code for CreateHashTable()
Save your program.
Copy and paste the program code into part 2(e) in the evidence document.
[5]
The procedure PrintSpare() outputs the key field of each element in the array Spare
(f)
(i)
that does not contain an empty record.
Write program code for PrintSpare()
Save your program.
Copy and paste the program code into part 2(f)(i) in the evidence document.
[2]
(ii)
The main program should call the procedure to initialise the arrays, call the procedure
to create the hash table and then call the procedure to output the contents of the array
Spare
Write program code for the main program.
Save your program.
Copy and paste the program code into part 2(f)(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 part 2(f)(iii) in the evidence document.
[1]

11
9618/43/M/J/25 · Question 1May/June 2025Paper 4326 marks
Loading question…
Question text

A program reads data from a text file and stores it in a queue. The linear queue Queue is stored as
1
a 1D array of up to 50 elements. The queue has the following pointers:
•
HeadPointer – this stores the index of the first element in the queue, initialised to –1
•
TailPointer – this stores the index of the last element in the queue, initialised to –1
(a) Queue is a global array of 50 integers with all elements initialised to –1 in the main program.
The two pointers are declared as global variables and initialised to –1
Write program code to declare and initialise Queue, HeadPointer and TailPointer
Save your program as Question1_J25.
Copy and paste the program code into part 1(a) in the evidence document.
[3]
(b) The function Enqueue():
•
takes an integer parameter to store in the next position in the queue
•
returns FALSE if the queue is full and the parameter cannot be stored in the queue
•
returns TRUE if the parameter is stored in the queue
•
updates the pointers where appropriate.
Write program code for Enqueue()
Save your program.
Copy and paste the program code into part 1(b) in the evidence document.
[6]
(c) The function Dequeue():
•
returns the next item in the queue, if the queue is not empty
•
returns –1 if the queue is empty
•
updates the pointers where appropriate.
Write program code for Dequeue()
Save your program.
Copy and paste the program code into part 1(c) in the evidence document.
[5]
(d) The text file QueueData.txt stores positive integers. Each integer is on a new line in the
file.
The procedure CreateQueue():
•
opens the file QueueData.txt
•
reads in each line from the text file and uses Enqueue() to insert each line into the
queue
•
outputs "Queue full" if any item cannot be inserted into the queue
•
uses exception handling when opening and reading from the text file.
The procedure needs to work for a file that contains an unknown number of lines.
Write program code for CreateQueue()
Save your program.
Copy and paste the program code into part 1(d) in the evidence document.
[6]
The main program needs extending to call CreateQueue(). The main program then
(e) (i)
adds together all of the integers stored in the queue, using Dequeue() to access each
integer. The total is then output.
Write program code to extend the main program.
Save your program.
Copy and paste the program code into part 1(e)(i) in the evidence document.
[5]
(ii)
Test your program.
Take a screenshot of the output(s).
Save your program.
Copy and paste the screenshot into part 1(e)(ii) in the evidence document.
[1]

12
9618/43/M/J/25 · Question 2May/June 2025Paper 4320 marks
Loading question…
Question text

A program sorts the data in the 1D array DataArray and searches DataArray for specific
2
values.
DataArray stores 14 integer values and is declared local to the main program.
(a) Write program code to create DataArray and initialise it with the following data values in the
order they are written:
0
3
4
56
67
44
43
32
31
345
45
6
54
1
Save your program as Question2_J25.
Copy and paste the program code into part 2(a) in the evidence document.
[1]
(b) The function InsertionSort() takes an array of integers as a parameter. The function
sorts the data in the array into ascending numerical order using an insertion sort. The function
returns the sorted array.
Write program code for InsertionSort()
You must not use any inbuilt sorting functions for your programming language.
Save your program.
Copy and paste the program code into part 2(b) in the evidence document.
[5]
(c) The procedure OutputArray() takes an array of integers as a parameter. The procedure
outputs each element in the array from the first element to the last element. The output is on
one line with a space between each number.
An example output is:
"0 3 4 56 67 44 43 32 31 345 45 6 54 1"
Write program code for OutputArray()
Save your program.
Copy and paste the program code into part 2(c) in the evidence document.
[2]
(d) (i)
The main program needs extending to:
•
output the content of the unsorted array using OutputArray()
•
sort the array using InsertionSort()
•
output the content of the sorted array using OutputArray()
Write program code to extend the main program.
Save your program.
Copy and paste the program code into part 2(d)(i) in the evidence document.
[2]
(ii)
Test your program.
Take a screenshot of the output(s).
Save your program.
Copy and paste the screenshot into part 2(d)(ii) in the evidence document.
[1]
(e) The function Search() performs a binary search to find ItemToFind in DataArray
The function takes two parameters:
•
DataArray, an array of integers
•
ItemToFind, an integer to find in DataArray
The function returns:
•
the index of ItemToFind if it is in DataArray
•
–1 if ItemToFind is not in DataArray
Write program code for Search()
You must not use any inbuilt searching functions for your programming language.
Save your program.
Copy and paste the program code into part 2(e) in the evidence document.
[6]
The main program needs extending to call Search() with the sorted array four times:
(f)
(i)
•
the first time to find the index of the integer 0
•
the second time to find the index of the integer 345
•
the third time to find the index of the integer 67
•
the fourth time to find the index of the integer 2
If the integer is found in the array, output an appropriate message that includes the index.
If the integer is not found, output that it was not found.
Write program code to extend the main program.
Save your program.
Copy and paste the program code into part 2(f)(i) in the evidence document.
[2]
(ii)
Test your program.
Take a screenshot of the output(s).
Save your program.
Copy and paste the screenshot into part 2(f)(ii) in the evidence document.
[1]

13
9618/41/M/J/24 · Question 1May/June 2024Paper 4127 marks
Loading question…
Question text

1
A program needs to take integer numbers as input, sort the numbers and then search for a specific
number.
(a) The integer numbers will be stored in the global 1D array, DataStored, with space for up to
20 integers.
The global variable NumberItems stores the quantity of items the array contains.
Write program code to declare DataStored and NumberItems.
Save your program as Question1_J24.
Copy and paste the program code into part 1(a) in the evidence document.
[1]
(b) The procedure Initialise():
•
prompts the user to input the quantity of numbers the user would like to enter
•
reads the input and validates it is between 1 and 20 (inclusive)
•
prompts the user to input each number and stores each number in DataStored.
Write program code for Initialise().
Save your program.
Copy and paste the program code into part 1(b) in the evidence document.
[5]
(c) The main program stores 0 in NumberItems, calls Initialise() and then outputs the
contents of DataStored.
(i)
Write program code for the main program.
Save your program.
Copy and paste the program code into part 1(c)(i) in the evidence document.
[2]
(ii)
Test your program by inputting the following data in the order given:
30
5
3
9
4
1
2
Take a screenshot of the output(s).
Save your program.
Copy and paste the screenshot into part 1(c)(ii) in the evidence document.
[2]
(d) The procedure BubbleSort() uses a bubble sort to sort the data in DataStored into
ascending numerical order.
Write program code for BubbleSort().
(i)
Save your program.
Copy and paste the program code into part 1(d)(i) in the evidence document.
[4]
Write program code to amend the main program to call BubbleSort() and then output
(ii)
the contents of DataStored.
Save your program.
Copy and paste the program code into part 1(d)(ii) in the evidence document.
[1]
(iii)
Test your program by inputting the following data in the order given:
5
3
9
4
1
2
Take a screenshot of the output(s).
Save your program.
Copy and paste the screenshot into part 1(d)(iii) in the evidence document.
[1]
(e) The function BinarySearch():
•
takes the integer parameter DataToFind to search for in the array
•
performs an iterative binary search on the array DataStored
•
returns the index where DataToFind is found in DataStored. If DataToFind is not
found, the function returns −1.
Write program code for the iterative function BinarySearch().
(i)
Save your program.
Copy and paste the program code into part 1(e)(i) in the evidence document.
[6]
(ii)
Write program code to amend the main program to:
•
take a number as input from the user
•
call BinarySearch() with the number input
•
output the value returned from the function call as its parameter.
Save your program.
Copy and paste the program code into part 1(e)(ii) in the evidence document.
[3]
(iii)
Test your program twice with the following inputs:
Test 1: 5
1
6
2
8
10
2
Test 2: 5
1
6
2
8
10
7
Take a screenshot of the output(s).
Save your program.
Copy and paste the screenshot into part 1(e)(iii) in the evidence document.
[2]

Advertisement
14
9618/41/M/J/24 · Question 3May/June 2024Paper 4117 marks
Loading question…
Question text

3
A program reads data from the user and stores the data that is valid in a linear queue.
The queue is stored as a global 1D array, QueueData, of string values. The array needs space for
20 elements.
The global variable QueueHead stores the index of the first element in the queue.
The global variable QueueTail stores the index of the last element in the queue.
(a) The main program initialises all the elements in QueueData to a suitable null value,
QueueHead to −1 and QueueTail to −1.
Write program code for the main program.
Save your program as Question3_J24.
Copy and paste the program code into part 3(a) in the evidence document.
[1]
(b) The function Enqueue() takes the data to insert into the queue as a parameter.
If the queue is not full, it inserts the parameter in the queue, updates the appropriate pointer(s)
and returns TRUE. If the queue is full, it returns FALSE.
Write program code for Enqueue().
Save your program.
Copy and paste the program code into part 3(b) in the evidence document.
[4]
(c) The function Dequeue() returns "false" if the queue is empty. If the queue is not empty, it
returns the next item in the queue and updates the appropriate pointer(s).
Write program code for Dequeue().
Save your program.
Copy and paste the program code into part 3(c) in the evidence document.
[3]
(d) The string values to be stored in the queue are 7 characters long. The first 6 characters are
digits and the 7th character is a check digit. The check digit is calculated from the first 6 digits
using this algorithm:
•
multiply the digits in position 0, position 2 and position 4 by 1
•
multiply the digits in position 1, position 3 and position 5 by 3
•
calculate the sum of the products (add together the results from all of the multiplications)
•
divide the sum of the products by 10 and round the result down to the nearest integer to
get the check digit
•
if the check digit equals 10 then it is replaced with 'X'.
Example:
Data is 954123
Character position
0
1
2
3
4
5
Digit
9
5
4
1
2
3
Multiplier
1
3
1
3
1
3
Product
9
15
4
3
2
9
Sum of products = 9 + 15 + 4 + 3 + 2 + 9 = 42
Divide sum of products by 10: 42 / 10 = 4 (rounded down)
The check digit = 4. This is inserted into character position 6.
The data including the check digit is: 9541234
A 7‑character string is valid if the 7th character matches the check digit for that data. For
example, the data 9541235 is invalid because the 7th character (5) does not match the check
digit for 954123.
The subroutine StoreItems() takes ten 7‑character strings as input from the user and
(i)
uses the check digit to validate each input.
Each valid input has the check digit removed and is stored in the queue using
Enqueue().
An appropriate message is output if the item is inserted. An appropriate message is
output if the queue is already full.
Invalid inputs are not stored in the queue.
The subroutine counts and outputs the number of invalid items that were entered.
StoreItems() can be a procedure or a function as appropriate.
Write program code for StoreItems().
Save your program.
Copy and paste the program code into part 3(d)(i) in the evidence document.
[6]
(ii)
Write program code to amend the main program to:
•
call StoreItems()
•
call Dequeue()
•
output a suitable message if the queue was empty
•
output the returned value if the queue was not empty.
Save your program.
Copy and paste the program code into part 3(d)(ii) in the evidence document.
[1]
(iii)
Test the program with the following inputs in the order given:
999999X
1251484
5500212
0033585
9845788
6666666
3258746
8111022
7568557
0012353
Take a screenshot of the output(s).
Save your program.
Copy and paste the screenshot into part 3(d)(iii) in the evidence document.
[2]
Permission to reproduce items where third‑party owned material protected by copyright is included has been sought and cleared where possible. Every
publisher will be pleased to make amends at the earliest poss

15
9618/42/M/J/24 · Question 1May/June 2024Paper 4222 marks
Loading question…
Question text

1
A program outputs a main word. The program asks the user to enter the different words of 3 or
more letters that can be made from the letters in the main word. These are called the answers.
There are 3 files: Easy.txt, Medium.txt and Hard.txt. Each file has the main word on the
first line. For example, the main word in Easy.txt is house.
The answers are stored in the file. Each answer is on a new line after the main word. For example,
Easy.txt has 14 answers that can be made from the letters in house.
The words read from the text file are stored in the global array WordArray. The number of words
that can be made from the letters in the main word is stored in the global variable NumberWords.
(a) The procedure ReadWords():
•
takes a file name as a parameter
•
opens the file and reads in the data
•
stores the main word in the first element in WordArray
•
stores each answer in a new element in WordArray
•
counts and stores the number of answers.
Write program code for the procedure ReadWords().
Save your program as Question1_J24.
Copy and paste the program code into part 1(a) in the evidence document.
[6]
(b) The main program asks the user to enter "easy", "medium" or "hard" and calls
ReadWords()with the filename that matches the user’s input. For example, if the user enters
"easy", the parameter is "Easy.txt".
Write program code for the main program.
Save your program.
Copy and paste the program code into part 1(b) in the evidence document.
[4]
The procedure Play():
(c) (i)
•
outputs the main word from the array and the number of answers
•
allows the user to enter words until they enter the word ‘no’ to indicate they want to
stop
•
outputs whether each word the user enters is an answer or not an answer
•
counts the number of answers the user gets correct
•
replaces each answer that the user gets correct with a null value in the array.
Write program code for the procedure Play().
Save your program.
Copy and paste the program code into part 1(c)(i) in the evidence document.
[6]
Amend the procedure Play()so that when the user enters the command to stop, the
(ii)
procedure:
•
outputs the percentage of answers the user entered from the array
•
outputs all the answers that the user did not enter.
Write program code to amend Play().
Save your program.
Copy and paste the program code into part 1(c)(ii) in the evidence document.
[3]
The procedure ReadWords()calls Play()after the data in the file has been read.
(d) (i)
Write program code to amend ReadWords().
Save your program.
Copy and paste the program code into part 1(d)(i) in the evidence document.
[1]
(ii)
Test your program by inputting these words in the order shown:
easy
she
out
no
Take a screenshot of the output(s).
Save your program.
Copy and paste the screenshot into part 1(d)(ii) in the evidence document.
[1]
(iii)
Test your program by inputting these words in the order shown:
hard
fine
fined
idea
no
Take a screenshot of the output(s).
Save your program.
Copy and paste the screenshot into part 1(d)(iii) in the evidence document.
[1]

Advertisement