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

162 questions · page 3 of 11

0 / 0Answer a question to start your score.
Quick quiz (10)Saved 0
Advertisement
31
9618/23/O/N/25 · Question 5Oct/Nov 2025Paper 2328 marks
Loading question…
Question text

5
A global 1D array Num of integers contains four elements. A program assigns values to these
elements as shown:
1
Num[1]
2
Num[2]
5
Num[3]
3
Num[4]
A procedure Process() manipulates the values in the array.
The procedure is written in pseudocode:
PROCEDURE Process(Start : INTEGER)
DECLARE CaseVar, Index, Count : INTEGER
Start
Index
0
Count
WHILE Count <= 20
CaseVar Num[Index]
CASE OF CaseVar
1 : Num[Index] Num[Index] + Index //clause one
Index Index + 1
Count Count + 1
2 : Num[Index] Num[Index] + Index //clause two
Index Index + 2
Count Count + 2
3 : Num[Index] Num[Index] * 2
//clause three
Index Index + 3
Count Count - 1
4 : Count Count + 4
//clause four
OTHERWISE : Count 20
ENDCASE
(Index MOD 4) + 1
Index
ENDWHILE
ENDPROCEDURE
ĬÑĊ¾Ġ´íÈõÏĪÅĊàù¸þ×
,
,
(a) Complete the trace table by dry running the procedure when it is called in the statement:
CALL Process(1)
Index
CaseVar
Count
Num[1]
Num[2]
Num[3]
Num[4]
[5]
ĬÓĊ¾Ġ´íÈõÏĪÅĊàû¸þ×
,
,
(b) As a reminder, the CASE structure in the pseudocode is:
CASE OF CaseVar
1 : Num[Index] Num[Index] + Index //clause one
Index Index + 1
Count Count + 1
2 : Num[Index] Num[Index] + Index //clause two
Index Index + 2
Count Count + 2
3 : Num[Index] Num[Index] * 2
//clause three
Index Index + 3
Count Count - 1
4 : Count Count + 4
//clause four
OTHERWISE : Count 20
ENDCASE
The CASE structure could be optimised by combining two existing clauses.
(i)
Identify the CaseVar values for these two existing clauses.
… [1]
(ii)
Write pseudocode for a single clause to replace the two clauses identified in (b) (i).
…
…
… [2]
ĬÑĊ¾Ġ´íÈõÏĪÅĊÞù¸Ā×

32
9618/23/O/N/25 · Question 6Oct/Nov 2025Paper 239 marks
Loading question…
Question text

6
Students are learning about a simple check digit method for data validation. In this method, a
single check digit is appended to the end of an original number to give a new number.
The students are studying a method which:
•
calculates the sum of all the digits in the original number
•
uses integer division to calculate the remainder when the sum is divided by 10
•
uses the remainder as the check digit
•
appends the check digit to the original number, creating the new number.
For example:
original number
4162
sum of all digits
4 + 1 + 6 + 2 = 13
remainder when the sum is divided by 10 using integer division
3
new number
41623
The original number is always at least three digits in length.
When the new number is input, the check digit is used to validate the new number.
(a) A function Generate() is written to take an original number as a parameter and to return the
check digit.
Outline a test plan that could be used to fully test function Generate()
Assume that the parameter is valid.
…
…
…
… [2]
ĬÍĊ¾Ġ´íÈõÏĪÅĊÝüµĂ×
,
,
(b) A function CheckNumber() will take an integer value and return the Boolean value TRUE if
the check digit is correct, otherwise return FALSE
Write pseudocode for the function CheckNumber()
Assume that the parameter is valid.
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…

33
9618/23/O/N/25 · Question 8Oct/Nov 2025Paper 2320 marks
Loading question…
Question text

8
A program is being developed to manage student book loans from a college library.
The programmer has defined a record type to define each loan.
The data items are:
Data item
Data type
Comment
the unique ID of the student who has borrowed
the book
StudentID
STRING
The first three characters of a StudentID
represent a tutor ID. Each student has one tutor.
BookID
STRING
the unique ID of the book being borrowed
OnLoan
BOOLEAN
TRUE if the book has not been returned
The programmer has defined a global array Loan to store 8000 loan records.
There are more elements in the array than books in the library. Unused elements have the
StudentID set to an empty string. These may occur anywhere in the array.
The programmer has defined a program module:
Module
Description
•
called with two parameters of type STRING representing a
StudentID and a BookID
•
outputs a message saying whether a given loan has been
LoanStatus()
returned or not
•
outputs a warning message if a record of the given loan is
not found
ĬÍĊ¾Ġ´íÈõÏĪÅĊÞü·Ă×
,
,
(a) Write efficient pseudocode for the module LoanStatus()
Assume that each combination of StudentID and BookID can occur only once.
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…

Advertisement
34
9618/41/O/N/25 · Question 1Oct/Nov 2025Paper 4120 marks
Loading question…
Question text

1
A program stores integers in a stack. The stack is represented as a 1D array of 30 elements with
the identifier Stack
The global pointer TopOfStack stores the index of the last element inserted into the stack.
TopOfStack is initialised to –1
(a) Write program code to declare Stack, initialise each element in the array with a null value
and declare and initialise TopOfStack
Save your program as Question1_N25.
Copy and paste the program code into part 1(a) in the evidence document.
[2]
(b) The function Push() takes an integer parameter. If the stack is full, the function returns
FALSE. If the stack is not full, the parameter is inserted into the stack, the pointer is updated
and the function returns TRUE
Write the 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 integer in the stack and updates the pointer as
appropriate. If there is no data in the stack, the function returns the value –999
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 main program generates 40 random integers between 0 and 1000 (inclusive) and attempts
to insert each one into the stack using the appropriate function. If the return value from the
function call indicates the stack is full, no more integers are generated and "Stack full" is
output.
Write program code for the main program.
Save your program.
Copy and paste the program code into part 1(d) in the evidence document.
[4]
(e) The procedure FindValues():
•
pops each integer from the stack until the stack is empty
•
finds and outputs the largest number that was in the stack in an appropriate message
•
finds and outputs the smallest number that was in the stack in an appropriate message.
Write program code for FindValues()
Save your program.
Copy and paste the program code into part 1(e) in the evidence document.
[4]
Extend the main program to call FindValues()
(f)
(i)
Save your program.
Copy and paste the program code into part 1(f)(i) in the evidence document.
[1]
(ii)
Test your program.
Take a screenshot of the output(s).
Save your program.
Copy and paste the screenshot(s) into part 1(f)(ii) in the evidence document.
[1]

35
9618/41/O/N/25 · Question 3Oct/Nov 2025Paper 4125 marks
Loading question…
Question text

A program stores records in the 2D array HashTable. Each record is stored at a specific index of
3
the array that is calculated using a hashing algorithm with the record’s key field.
The array has 100 × 10 elements. The hashing algorithm uses the key to generate an index
between 0 and 99 (inclusive). If two key fields generate the same index, there is a collision. Any
records that have a collision are stored in the next space in the same index.
For example: In this table two record keys generated the same hash value of 1. Four record keys
generated the same hash value of 3.
Index
0
1
2
3
4
5
…
9
0
record
1
record
record
2
3
record
record
record
record
4
…
99
The program uses Object-Oriented Programming (OOP).
(a) The class Record stores data about the records:
Record
Key : Integer
stores the integer key field for the data
Data : String
stores the string data
initialises Key and Data to its parameter values
Constructor()
The attributes Key and Data are public.
Write program code to declare the class Record and its constructor.
Use your programming language appropriate constructor.
Save your program as Question3_N25.
Copy and paste the program code into part 3(a) in the evidence document.
[2]
(b) The procedure InitialiseHashTable() initialises each element in the array to an empty
or null record.
Write program code to declare the global 2D array HashTable and the procedure
InitialiseHashTable()
Save your program.
Copy and paste the program code into part 3(b) in the evidence document.
[2]
(c) The function Hash():
•
takes an integer key field as a parameter
•
calculates and returns the hash value of the key field.
The hash value is the result from the formula: key MOD 100
Write program code for Hash()
Save your program.
Copy and paste the program code into part 3(c) in the evidence document.
[2]
(d) The procedure InsertData():
•
takes an object of type Record as a parameter
•
calculates the hash value for the parameter using the appropriate function
•
stores the parameter in the correct position in HashTable
You can assume there will be no more than 10 objects that generate the same hash value.
Write program code for InsertData()
Save your program.
Copy and paste the program code into part 3(d) in the evidence document.
[4]
(e) The file "HashTableData.txt" stores 200 key values and string data items in the format:
key,string
For example, the first row in the text file is:
528,permission
The key is 528 and the string data is "permission"
The procedure ReadData():
•
opens the text file and reads each line
•
splits each line into the key and data
•
calls InsertData() with an object containing each key and matching data.
Write program code for ReadData()
Save your program.
Copy and paste the program code into part 3(e) in the evidence document.
[5]
The function GetRecord():
(f)
•
takes an integer key field as a parameter
•
calculates the hash value for the key field using the appropriate function
•
searches the hash table for the record with the matching key field
•
returns the data for the record if the record is found
•
returns "Not found" if the record is not found.
Write program code for GetRecord()
Save your program.
Copy and paste the program code into part 3(f) in the evidence document.
[5]
(g) The main program:
•
calls InitialiseHashTable() and ReadData()
•
takes five integer key fields as input from the user
•
calls GetRecord() with each input and outputs the return value.
(i)
Write program code for the main program.
Save your program.
Copy and paste the program code into part 3(g)(i) in the evidence document.
[3]
(ii)
Test your program with the following five inputs in the order given:
528
1128
1828
1062
39
Take a screenshot of the output(s).
Save your program.
Copy and paste the screenshot(s) into part 3(g)(ii) in the evidence document.
[2]
Permission to reproduce items where third-party owned material protected by copyright is included has been sought and

36
9618/42/O/N/25 · Question 2Oct/Nov 2025Paper 4226 marks
Loading question…
Question text

2
A program stores 20 unique random integers between 0 and 100 (inclusive) in a 1D array that is
local to the main program.
(a) Write program code to declare the array local to the main program and store 20 unique
random numbers between 0 and 100 (inclusive) in the array.
Save your program as Question2_N25.
Copy and paste the program code into part 2(a) in the evidence document.
[3]
(b) The procedure PrintArray() takes an integer array as a parameter. The procedure outputs
the array contents on a single line with a space between each integer.
Write the program code for PrintArray()
Save your program.
Copy and paste the program code into part 2(b) in the evidence document.
[3]
(c) The function BubbleSort():
•
takes an integer array as a parameter
•
sorts the data into ascending order using a bubble sort
•
returns the sorted array.
The function needs to work for an array of any length.
Do not use an inbuilt sorting method.
Write program code for BubbleSort()
Save your program.
Copy and paste the program code into part 2(c) in the evidence document.
[5]
(d) (i)
The main program:
•
outputs the contents of the array using PrintArray()
•
sorts the array using BubbleSort()
•
outputs "Sorted"
•
outputs the contents of the sorted array using PrintArray()
Write program code for the main program.
Save your program.
Copy and paste the program code into part 2(d)(i) in the evidence document.
[3]
(ii)
Test your program.
Take a screenshot of the output(s).
Save your program.
Copy and paste the screenshot(s) into part 2(d)(ii) in the evidence document.
[1]
(e) The recursive function RecursiveBinarySearch() takes four parameters:
•
an integer array
•
the lower bound of the array
•
the upper bound of the array
•
the value to find in the array.
The recursive function performs a binary search to find the index of the value in the array.
The function returns the index of the value if it is found. The function returns –1 if the value is
not found.
Write program code for RecursiveBinarySearch()
Save your program.
Copy and paste the program code into part 2(e) in the evidence document.
[6]
(f)
(i)
The main program:
•
prompts the user to enter an integer
•
takes the integer as input
•
calls RecursiveBinarySearch() with the sorted array, appropriate lower bound,
appropriate upper bound and the user’s input as parameters
•
outputs "Not found" if the input is not within the array
•
outputs "Found at position" and the index if the input is within the array.
Write program code to amend the main program.
Save your program.
Copy and paste the program code into part 2(f)(i) in the evidence document.
[3]
(ii)
Test your program three times with each of the inputs described:
Test 1: the smallest number in the array
Test 2: the largest number in the array
Test 3: a number not in the array
Take a screenshot of each output.
Save your program.
Copy and paste the screenshot(s) into part 2(f)(ii) in the evidence document.
[2]

37
9618/42/O/N/25 · Question 3Oct/Nov 2025Paper 4221 marks
Loading question…
Question text

3
A program stores integers in ascending order in an ordered binary tree. The tree is implemented
as a 2D array.
Each node is stored with three values:
•
a pointer to the left node
•
the data
•
a pointer to the right node.
All null values are stored as –1
The binary tree can store up to 50 nodes.
Nodes cannot be deleted from the binary tree.
(a) The binary tree is stored as a global array with the identifier TreeArray. The left pointer, the
data and the right pointer of each node are initialised to –1
The global variable RootPointer stores the index of the root node in the tree, initialised to
–1
The global variable FreeNode stores the index of the next free node in the array, initialised
to 0
Write program code to declare and initialise TreeArray, RootPointer and FreeNode
Save your program as Question3_N25.
Copy and paste the program code into part 3(a) in the evidence document.
[3]
(b) The procedure AddNode():
•
takes an integer to store in the binary tree as a parameter
•
stores the parameter in the next free node in the array
•
finds the position to store the data in the tree by following the appropriate pointers
•
updates the pointer of the new node’s parent node.
The procedure outputs "The tree is full" if the parameter cannot be stored because
the tree is full.
Write program code for AddNode()
Save your program.
Copy and paste the program code into part 3(b) in the evidence document.
[7]
(c) The text file TreeData.txt stores 50 integers. Each integer is on a new line in the file.
The main program reads each integer from the file and stores each integer in the binary tree
in the order they are read.
Write program code for the main program.
Save your program.
Copy and paste the program code into part 3(c) in the evidence document.
[4]
(d) The procedure WriteAllToFile() stores the content of TreeArray in a new text file with
the filename Tree.txt. The file Tree.txt is not provided.
Each node in TreeArray is stored on one line with a comma separating each value.
For example, the current contents of TreeArray are:
Index
0
1
2
0
–1
20
1
1
–1
30
–1
…
49
-1
-1
-1
After writing TreeArray to the text file, Tree.txt will contain:
–1,20,1
–1,30,–1
…
-1,-1,-1
Write program code for WriteAllToFile()
Include exception handling when writing to the file.
Save your program.
Copy and paste the program code into part 3(d) in the evidence document.
[5]
Amend the main program to call WriteAllToFile()
(e) (i)
Save your program.
Copy and paste the program code into part 3(e)(i) in the evidence document.
[1]
(ii)
Test your program.
Take a screenshot that shows all of the content stored in the file Tree.txt
In this screenshot you need to make sure the filename is visible.
Save your program.
Copy and paste the screenshot(s) into part 3(e)(ii) in the evidence document.
[1]
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 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 Cambridge Assessment. Cambridge Assessment is the brand name of the University of Cambridge

38
9618/43/O/N/25 · Question 2Oct/Nov 2025Paper 4324 marks
Loading question…
Question text

2
A program reads string data from a text file into a linear queue and then compresses the data.
The queue is created using the global 1D array Queue. The queue can store up to 100 elements.
Each element is initialised to the empty string ""
The queue has two pointers that are global to the program:
•
QueueHead that points to the index of the first element in the queue, initialised to –1
•
QueueTail that points to the index of the last element in the queue, initialised to –1
The global variable NumberItems stores the number of elements stored in the queue, initialised
to 0
(a) Write program code to declare and initialise Queue, QueueHead, QueueTail and
NumberItems
Save your program as Question2_N25.
Copy and paste the program code into part 2(a) in the evidence document.
[2]
(b) The function Enqueue() takes a string as a parameter. The function checks if the queue is
full, and returns Boolean FALSE if the queue is full.
If the queue is not full, the parameter is inserted into the next position in Queue. The function
updates the appropriate pointer(s), updates NumberItems and then returns Boolean TRUE
Write program code for Enqueue()
Save your program.
Copy and paste the program code into part 2(b) in the evidence document.
[5]
(c) The function Dequeue() returns the string "False" if the queue is empty.
If the queue is not empty, the function returns the next element in the queue. The function
updates the appropriate pointer(s) and updates NumberItems
Write program code for Dequeue()
Save your program.
Copy and paste the program code into part 2(c) in the evidence document.
[3]
(d) The text file BinaryData.txt stores individual binary digits, '1' and '0'. Each digit is on
a new line. For example, the first line in the text file stores '1', the second line stores '1'
The procedure ReadData() reads in each line from the text file BinaryData.txt and
inserts it into the queue using the appropriate method.
The procedure needs to work for a text file with any number of lines up to a maximum of 100.
Write program code for ReadData()
Save your program.
Copy and paste the program code into part 2(d) in the evidence document.
[5]
(e) The string data in the text file is compressed.
The compression algorithm counts the number of times each binary digit appears
consecutively, then stores the binary digit followed by the number of times it appears. The
algorithm stores the compressed data in a single string.
For example, if the text file contains the data:
1
1
0
0
0
1
1
1
The compression algorithm will create the string "120313" because there are two '1' digits,
followed by three '0' digits, followed by three '1' digits.
The procedure Compress() uses Dequeue() to remove each element from the queue in
turn. The procedure then compresses the data following the compression algorithm described.
The new compressed string is stored in the global variable NewString
You can assume that one binary digit will never appear more than nine times consecutively in
the sequence.
You can assume that there will always be at least one item in the queue.
Write program code for Compress()
Save your program.
Copy and paste the program code into part 2(e) in the evidence document.
[6]
(f)
(i)
Write program code for the main program to:
•
call ReadData()
•
call Compress()
•
output the content of the compressed string.
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(s) into part 2(f)(ii) in the evidence document.
[1]

Advertisement
39
9618/43/O/N/25 · Question 3Oct/Nov 2025Paper 4320 marks
Loading question…
Question text

3
A program is written to perform different individual processes using arrays.
(a) A 1D array stores 10 integers.
A recursive function RecursiveCount() takes three parameters:
(i)
•
ArrayCopy, an array of integers
•
NumberElements, the number of elements in the array of integers
•
DataToFind, an integer data to find in the array.
The function counts and returns the number of times DataToFind is in ArrayCopy
The recursive algorithm:
•
returns 0 if there are no elements in ArrayCopy
•
compares the first element in ArrayCopy with DataToFind
◦
if the element matches, the function returns 1 added to the return value from a
recursive call (passing the array without the first element)
◦
if the element does not match, the function returns the return value from a
recursive call (passing the array without the first element).
Write program code for RecursiveCount()
Save your program as Question3_N25.
Copy and paste the program code into part 3(a)(i) in the evidence document.
[6]
(ii)
The main program stores the following data in a 1D array of integers in the order given:
0
5
1
2
5
9
9
6
5
0
The main program calls RecursiveCount() with the parameters:
•
0 as the data to find
•
10 as the number of elements
•
the array of 10 integers.
The return value is output.
Write program code for the main program.
Save your program.
Copy and paste the program code into part 3(a)(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(s) into part 3(a)(iii) in the evidence document.
[1]
(b) The program stores the following string. The string has four statements that are each
terminated by a semi-colon ';'
"x=0;y=1;x=x+y;y++;"
Write program code to amend the main program to store the string "x=0;y=1;x=x+y;y++;"
(i)
in a local variable.
Save your program.
Copy and paste the program code into part 3(b)(i) in the evidence document.
[1]
The function SplitData() splits a string parameter into four individual lines of code.
(ii)
The function creates an array of the strings where each line is stored in a new array
element without the semi-colon.
The function returns the array of strings.
Do not use an inbuilt function to split the string.
Write program code for SplitData()
Save your program.
Copy and paste the program code into part 3(b)(ii) in the evidence document.
[6]
The main program needs to call SplitData() with the string from part 3(b)(i). The
(iii)
main program then needs to output each element from the returned array on a new line.
Write program code to amend the main program.
Save your program.
Copy and paste the program code into part 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(s) into part 3(b)(iv) in the evidence document.
[1]
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 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 Cambridge Assessment. Cambridge Assessment is the brand name of the University of Cambridge

40
9618/21/M/J/25 · Question 3May/June 2025Paper 218 marks
Loading question…
Question text

3
A student has been asked to create a simple guessing game program. This program will generate
a random integer value between 1 and 100. It will then repeatedly prompt the user to input an
integer value until they input the randomly generated value.
The student has written a structured English description:
step 1 – randomly generate an integer value between 1 and 100 inclusive
step 2 – prompt the user to input an integer value
step 3 – output an appropriate message if the value input was too high; then repeat from step 2
step 4 – output an appropriate message if the value input was too low; then repeat from step 2
step 5 – output an appropriate message if the value input was the same value that was randomly
generated; then end the program.
Write a pseudocode algorithm from this structured English description.
Assume no input validation is needed.
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
… [8]
ĬÛĊ®Ġ´íÈõÏĪÅĊÝúµþ×

41
9618/21/M/J/25 · Question 4May/June 2025Paper 2128 marks
Loading question…
Question text

4
Study the algorithm:
DECLARE Chars : ARRAY[1:4] OF CHAR
DECLARE I, J : INTEGER
DECLARE Key : CHAR
2
I
'D'
Chars[1]
'T'
Chars[2]
'H'
Chars[3]
'R'
Chars[4]
WHILE I <= 4
//Outer loop
Chars[I]
Key
I – 1
J
WHILE J >= 0 AND Chars[J] > Key
//Inner loop
Chars[J]
Chars[J + 1]
J – 1
J
ENDWHILE
Key
Chars[J + 1]
I + 1
I
ENDWHILE
(a) The outer loop structure used in the algorithm is not the most appropriate one to use.
State the type of loop structure that would be the most appropriate to use and justify why it is
the most appropriate.
Loop structure …
Justification …
…
[2]
ĬÙĊ®Ġ´íÈõÏĪÅĊßüµĀ×
,
,
(b) Complete the trace table by dry running the algorithm.
The first row has been completed.
Chars
I
Key
J
Chars[J]
[1]
[2]
[3]
[4]
2
'D'
'T'
'H'
'R'
[6]
ĬÛĊ®Ġ´íÈõÏĪÅĊßúµĀ×

42
9618/21/M/J/25 · Question 5May/June 2025Paper 217 marks
Loading question…
Question text

5
Stacks and queues are both abstract data types.
A stack uses a top-of-stack pointer to indicate the location of the last item added to the stack.
A queue uses two pointers:
•
a front pointer to indicate the location of the next item to be removed from the queue
•
a rear pointer to indicate the location of the next item to be added to the queue.
A queue can be used to reverse the items stored on a stack.
For example, if a stack contains six items:
Initial state of the stack:
top-of-stack pointer
item 6
item 5
item 4
item 3
item 2
item 1
Final state of the stack when the items have been reversed:
top-of-stack pointer
item 1
item 2
item 3
item 4
item 5
item 6
Describe how the queue could be used to reverse the items that are currently stored on the stack.
Your description must include how the pointers are used in both the stack and queue.
Assume:
•
The stack initially contains an unknown number of items.
•
The queue can store all the items currently stored on the stack.
•
The queue is initially empty.
ĬÙĊ®Ġ´íÈõÏĪÅĊÞü·þ×
,
,
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…

43
9618/21/M/J/25 · Question 6May/June 2025Paper 2112 marks
Loading question…
Question text

6
A program monitors the speed of vehicles as they move around a large building site.
Each vehicle contains a sensor which reads an integer value that represents the speed of the
vehicle. The value is expected to be in the range 0 to 60 inclusive.
The sensors cannot read values less than 0.
A program module has been written to validate the values read by the sensors.
(a) A test plan is needed to fully test the module.
Complete the table. The first line has been completed for you.
Assume the sensors generate only integer values.
Type of test data
Test data value
Expected outcome
normal
36
data item is accepted
[4]
(b) Each sensor used in the system has a unique sensor ID number in the range 1 to 50.
The program that is used to monitor the speed of each vehicle reads each sensor value
every second and stores this value along with the sensor’s unique ID into a global 2D array
Reading
The global array Reading has been declared as follows:
DECLARE Reading : ARRAY[1:2000, 1:2] OF INTEGER
The array contains 4000 elements organised as 2000 rows and 2 columns.
Column 1 contains the sensor value, and column 2 contains the sensor ID.
When 2000 sensor readings have been taken, the array is full and the system stops taking
any more sensor readings until the array has been processed.
A procedure Sort() is needed to sort the array into ascending order of sensor value using
an efficient bubble sort algorithm.
ĬÙĊ®Ġ´íÈõÏĪÅĊàü·Ā×
,
,
Write efficient pseudocode for the procedure Sort()
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…

Advertisement
44
9618/21/M/J/25 · Question 7May/June 2025Paper 2118 marks
Loading question…
Question text

7
A program is being developed to implement a customer loyalty scheme for a coffee shop.
The programmer has decided that the following data items need to be stored for each customer:
Data item
Description
customer ID
a unique six-digit string
an integer value that is increased by one for every cup of coffee the
points
customer orders
When a customer visits the shop and orders coffee, the scheme operates as follows:
•
The total number of points is increased by the number of coffees ordered.
•
If just one cup of coffee is ordered and the number of points goes above 10, then:
◦
the cup of coffee they have just ordered is given to them free of charge
◦
the number of points is reduced by 11.
•
If the order is for multiple coffees and the number of points goes above 10, then:
◦
they get one coffee free of charge for every 11 points
◦
the number of points is reduced by 11 for each free coffee.
For example, the:
•
customer currently has 9 points
•
customer orders 16 cups of coffee
•
total number of points now becomes 25
•
customer gets 2 free coffees and now has 3 points left.
The programmer has defined a program module that is called every time a customer places an
order:
Module
Description
•
called with two integer parameters:
◦
the number of coffees ordered
◦
CustomerOrder()
the current number of points
•
output a suitable message giving the number of free coffees
•
return a value for the new points total.
ĬÕĊ®Ġ´íÈõÏĪÅĊßù¶Ă×
,
,
(a) Write pseudocode for module CustomerOrder()
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…

45
9618/22/M/J/25 · Question 3May/June 2025Paper 228 marks
Loading question…
Question text

3
An algorithm is designed to generate and output two unique random integers. Each integer value
is between –10 and 10 inclusive.
If both integers output are negative, a third random integer between 30 and 35 inclusive will be
generated and output.
Write pseudocode for this algorithm.
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…

Advertisement