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

10 questions

0 / 0Answer a question to start your score.
New quizSaved 0

Quick quiz: 10 random questions from this topic. Answer them all, then open the Summary.

Advertisement
1
9618/22/O/N/25 · Question 3Oct/Nov 2025Paper 2210 marks
Loading question…
Question text

3
A text file OldFile.txt contains IDs, names and email addresses for members of a club. Three
information items are stored for each member and each item is stored on a separate line.
The example shows the information for the first two members in the first six lines of the file:
Line in file
Information item
Example data
"AB1234"
1
member 1 ID
"Freddie Jones"
2
member 1 name
"[email protected]"
3
member 1 email address
"BC2345"
4
member 2 ID
"Sue Smith"
5
member 2 name
"[email protected]"
6
member 2 email address
The member ID string is always two letters followed by four digits.
The file design is to be changed so that information for each user is stored as a single line of the
file, with the character '\' used as a separator between data items.
For example, the single line for member 1 will be:
"AB1234\Freddie Jones\[email protected]"
An algorithm will produce a new file NewFile.txt from the contents of OldFile.txt
Assume:
•
LineX, LineY and LineZ are of type STRING and are used to store the three items of
information for each member
•
NewString is a temporary variable of type STRING
•
OldFile.txt exists and contains valid data.
(a) The algorithm to create the new file is expressed in steps.
Complete the following numbered steps:
Step 1 :
open the file … in …
Step 2 :
open the file … in …
Step 3 :
read a line from … and store in …
Step 4 :
read a line from … and store in …
Step 5 :
read a line from … and store in …
Step 6 :
set NewString to …
Step 7 :
write NewString to …
Step 8 :
repeat from step … until …
Step 9 :
close both files.
[6]
ĬÕĊ®Ġ´íÈõÏĪÅĊàù¸Ā×
,
,
(b) The character '\' has been chosen as a separator.
Explain why this is a suitable character.
…
… [1]
(c) Two new information items are to be stored for each member. Both new items are encrypted;
they can each contain any character (including '\') and can be of any length up to a
maximum of 99 characters.
For example:
Information item
Example data
"AB1234"
member 1 ID
"Freddie Jones"
member 1 name
"[email protected]"
member 1 email address
"En/98&*(|?\/D7iP"
member 1 new information 1
"23\CoboL"
member 1 new information 2
Explain the additional file design changes needed so that:
•
all the information items for each member are stored on a single line of NewFile.txt
•
it is possible to extract each information item after the line is read.
Assume the '\' character is not used in any email address.
…
…
…
…
…

2
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]

3
9618/23/M/J/24 · Question 2May/June 2024Paper 237 marks
Loading question…
Question text

2
(a) A program uses a global 1D array of type string and a text file.
An algorithm that forms part of the program is expressed as follows:
•
copy the first line from the file into the first element of the array
•
copy the second line from the file into the second element of the array
•
continue until all lines in the file have been copied into the array.
Stepwise refinement is applied to the algorithm.
Outline five steps for this algorithm that could be used to produce pseudocode.
Assume there are more elements in the array than lines in the file.
Do not use pseudocode statements in your answer.
Step 1 …
…
Step 2 …
…
Step 3 …
…
Step 4 …
…
Step 5 …
…
[5]
(b) Sequence is one programming construct.
Identify one other programming construct that will be required when the algorithm from
part (a) is converted into pseudocode and explain its use.
Construct …
…
Use …
…
[2]

Advertisement
4
9618/23/M/J/26 · Question 8May/June 2026Paper 2319 marks
Loading question…
Question text

8
A warehouse stores stock in bins. A bin is a container which stores the stock items; each bin can
store many identical items. The warehouse is organised on three different levels – level 0 (ground
level), then level 1 and level 2. Each level has 120 bins, numbered 1 to 120.
A bin is identified by the level and a bin number. The data item stored for each bin is a Boolean
value; this indicates whether the bin is in use (contains stock items) or not in use (contains no
stock items).
(a) (i)
Complete the pseudocode to declare a 2D array Bins
DECLARE …
[2]
(ii)
A pseudocode module InactiveReport() will produce a report that will show:
•
a header for each level
•
the bin number for each bin that is not in use on that level
•
the total number of bins that are not in use on all levels.
The module is initially developed for only five bins on each level.
An example program output:
Level: ground floor
Shows:
Bin 1
Bin 3
• the header for each level
Level: 1
Bin 4
• a list of bin numbers for bins that are
not in use on that level
Level: 2
Bin 1
• the total number of bins not in use.
Bin 2
Bin 5
6 bins are not in use
© Cambridge University Press & Assessment 2026
,
,
Complete the pseudocode for the procedure InactiveReport()
Assume that the Bins array is a global variable and has already been populated
with data.
PROCEDURE InactiveReport()
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…

5
9618/42/O/N/23 · Question 1Oct/Nov 2023Paper 4227 marks
Loading question…
Question text

1
A program stores lower-case letters in two stacks.
One stack stores vowels (a, e, i, o, u) and one stack stores consonants (letters that are not
vowels).
Each stack is implemented as a 1D array.
(a) (i)
Write program code to declare two 1D global arrays: StackVowel and StackConsonant.
Each array needs to store up to 100 letters. The index of the first element in each array is 0.
If you are writing in Python, include declarations using comments.
Save your program as Question1_N23.
Copy and paste the program code into part 1(a)(i) in the evidence document.
[2]
(ii)
The global variable VowelTop is a pointer that stores the index of the next free space in
StackVowel.
The global variable ConsonantTop is a pointer that stores the index of the next free
space in StackConsonant.
VowelTop and ConsonantTop are both initialised to 0.
Write program code to declare and initialise the two variables.
If you are writing in Python, include declarations using comments.
Save your program.
Copy and paste the program code into part 1(a)(ii) in the evidence document.
[1]
(b) (i)
The procedure PushData() takes one letter as a parameter.
If the parameter is a vowel, it is pushed onto StackVowel and the relevant pointer
updated.
If the stack is full, a suitable message is output.
If the parameter is a consonant, it is pushed onto StackConsonant and the relevant
pointer updated.
If the stack is full, a suitable message is output.
You do not need to validate that the parameter is a letter.
Write program code for PushData().
Save your program.
Copy and paste the program code into part 1(b)(i) in the evidence document.
[6]
(ii)
The file StackData.txt stores 100 lower-case letters.
The procedure ReadData() reads each letter from the file and uses PushData() to
push each letter onto its appropriate stack.
Use appropriate exception handling if the file does not exist.
Write program code for ReadData().
Save your program.
Copy and paste the program code into part 1(b)(ii) in the evidence document.
[6]
(c) The function PopVowel() removes and returns the data at the top of StackVowel and
updates the relevant pointer(s).
The function PopConsonant() removes and returns the data from the top of StackConsonant
and updates the relevant pointer(s).
If either stack is empty, the string "No data" must be returned.
Write program code to declare PopVowel() and PopConsonant().
Save your program.
Copy and paste the program code into part 1(c) in the evidence document.
[5]
(d) The program first needs to call ReadData() and then:
1.
prompt the user to input their choice of vowel or consonant
2.
take, as input, the user’s choice
3.
depending on the user’s choice, call PopVowel() or PopConsonant() and store the
return value.
The three steps are repeated until 5 letters have been successfully returned and stored.
If either stack is empty at any stage, an appropriate message must be output.
Once 5 letters have been successfully returned and stored, they are output on one line, for
example:
abyti
(i)
Write program code for the main program.
Save your program.
Copy and paste the program code into part 1(d)(i) in the evidence document.
[6]
(ii)
Test your program with the following inputs:
vowel
consonant
consonant
vowel
vowel
Take a screenshot of the output.
Save your program.
Copy and paste the screenshot into part 1(d)(ii) in the evidence document.
[1]

6
9618/22/M/J/21 · Question 6May/June 2021Paper 228 marks
Loading question…
Question text

6
A procedure CountVowels() will:
•
be called with a string containing alphanumeric characters as its parameter
•
count and output the number of occurrences of each vowel (a, e, i, o, u) in the string
•
count and output the number of occurrences of the other alphabetic characters (as a single
total).
The string may contain both upper and lower case characters.
Each count value will be stored in a unique element of a global 1D array CharCount of type
INTEGER. The array will contain six elements.
Write pseudocode for the procedure CountVowels().
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…

7
9618/42/O/N/22 · Question 1Oct/Nov 2022Paper 4223 marks
Loading question…
Question text

1
A computer program is needed to store jobs in order of priority. Each job has a job number
(for example, 123) and a priority from 1 to 10, with 1 being the highest priority and 10 the lowest.
The program stores the jobs in a global 2D array.
The pseudocode declaration for the array is:
DECLARE Jobs : ARRAY[0:99, 0:1] OF INTEGER
For example:
•
Jobs[0, 0] stores the job number of the first job.
•
Jobs[0, 1] stores the priority of the first job.
The global variable, NumberOfJobs, stores the number of jobs currently in the array.
(a) Write program code to declare the global 2D array Jobs and the global variable
NumberOfJobs.
Save your program as Question1_N22.
Copy and paste the program code into part 1(a) in the evidence document.
[3]
(b) The procedure Initialise() stores –1 in each of the array elements and assigns 0 to
NumberOfJobs.
Write program code for the procedure Initialise().
Save your program.
Copy and paste the program code into part 1(b) in the evidence document.
[3]
(c) The procedure AddJob():
•
takes a job number and priority as parameters
•
stores the job in the next free array element
•
outputs ‘Added’ if the job was successfully stored in the array
•
outputs ‘Not added’ if the job was not successfully stored in the array.
Write program code for the procedure AddJob().
Save your program.
Copy and paste the program code into part 1(c) in the evidence document.
[5]
(d) The main program should call the procedure Initialise() and then use the AddJob()
procedure to store the following jobs in the order given:
Job number
Priority
12
10
526
9
33
8
12
9
78
1
Write program code for the main program and perform the tasks described.
Save your program.
Copy and paste the program code into part 1(d) in the evidence document.
[2]
(e) When a new job has been added, the array is sorted into ascending numerical order of priority
using an insertion sort.
Write program code for the procedure InsertionSort() to sort the data into ascending
numerical order of priority.
Save your program.
Copy and paste the program code into part 1(e) in the evidence document.
[5]
(f)
The procedure PrintArray() outputs each job number and priority on a line, for example:
123 priority 1
39 priority 3
120 priority 7
Write program code for the procedure PrintArray().
Save your program.
Copy and paste the program code into part 1(f) in the evidence document.
[3]
(g) The main program needs to sort the array and then output the contents of the array.
(i)
Amend the main program by writing program code to call procedures InsertionSort()
and PrintArray().
Save your program.
Copy and paste the program code into part 1(g)(i) in the evidence document.
[1]
(ii)
Test your program.
Take a screenshot of the output.
Copy and paste the screenshot into part 1(g)(ii) in the evidence document.
[1]

8
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
9
9618/22/O/N/24 · Question 3Oct/Nov 2024Paper 227 marks
Loading question…
Question text

3
A program uses a stack to hold up to 60 numeric values.
The stack is implemented using two integer variables and a 1D array.
The array is declared in pseudocode as shown:
DECLARE ThisStack : ARRAY[1:60] OF REAL
The stack operates as follows:
•
Global variable SP acts as a stack pointer that points to the next available stack location. The
value of SP represents an array index.
•
Global variable OnStack represents the number of values currently on the stack.
•
The stack grows upwards from array element index 1.
(a) (i)
Give the initial values that should be assigned to the two variables.
SP …
OnStack …
[1]
(ii)
Explain why it is not necessary to initialise the array elements before the stack is used.
…
…
…
… [2]
(b) A function to add a value to ThisStack is expressed in pseudocode as shown.
The function will return a value to indicate whether the operation was successful or not.
Complete the pseudocode by filling in the gaps.
FUNCTION Push(ThisValue : REAL) RETURNS BOOLEAN
DECLARE ReturnValue : BOOLEAN
IF … THEN
RETURN … // stack is already full
ENDIF
ThisValue
…
…
SP
OnStack + 1
OnStack
RETURN TRUE
ENDFUNCTION
[4]
ĬÑĊ¾Ġ´íÈõÏĪÅĊÞüµþ×

10
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