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

162 questions · page 4 of 11

0 / 0Answer a question to start your score.
Quick quiz (10)Saved 0
Advertisement
46
9618/22/M/J/25 · Question 4May/June 2025Paper 226 marks
Loading question…
Question text

4
An algorithm will:
•
input 100 integer values, one value at a time
•
store the first value input into the first location of the array Number
•
store the next input value in the next unused location of the array Number
•
output the contents of Number array in the opposite sequence to that in which the values
were input.
Complete the program flowchart to represent the algorithm.
Variable declarations are not required.
START
END
[6]
ĬÛĊ®Ġ´íÈõÏĪÅĊÝù¶þ×

47
9618/22/M/J/25 · Question 5May/June 2025Paper 2212 marks
Loading question…
Question text

5
An automated digital camera system is used to take a sequence of pictures of animals in a garden.
During the design of the system, a state‑transition diagram is produced.
The table details the states in the automated digital camera system along with the events which
cause the states to change.
The system starts in standby mode. The sequence of pictures is taken when in active mode.
Current state
Event
Next state
standby mode
turn on
detect mode
detect mode
turn off
standby mode
detect mode
movement detected
active mode
active mode
20 seconds elapsed
sequence complete
active mode
turn off
standby mode
sequence complete
time saved
detect mode
(a) Complete the state‑transition diagram for the automated digital camera system.
start
standby mode
[4]
ĬÛĊ®Ġ´íÈõÏĪÅĊßù¶Ā×
,
,
(b) At the end of each sequence of pictures, the time is saved as a string in the format
<HH><MM><SS> where:
•
HH represents the hours using two digits
•
MM represents the minutes using two digits
•
SS represents the seconds using two digits.
For example:
•
"081230" is stored to represent the time 8:12:30, in the morning
•
"152235" is stored to represent the time 15:22:35, in the afternoon.
Each string is stored on a new line in the text file TimeTaken.txt
An algorithm is required to process the content of the text file TimeTaken.txt once it has
been transferred to the computer.
For each hour when pictures are taken, output a suitable message showing the hour and the
total number of sequences of pictures taken within that hour.
Example outputs:
Hour : 15
Total : 32
Hour : 18
Total : 1
Write pseudocode for this algorithm.
Assume the text file TimeTaken.txt contains at least one line.
…
…
…
…
…
…
…
…
…
…
…
…
…
…
ĬÙĊ®Ġ´íÈõÏĪÅĊÞû¸þ×
,
,
…
…

48
9618/22/M/J/25 · Question 6May/June 2025Paper 229 marks
Loading question…
Question text

6
Two arrays Data and Pointer are accessed by the procedure Place()
Data and Pointer are both global arrays of type INTEGER
The contents of these two arrays are shown:
Data
Pointer
1018
7
1
1
1007
3
2
2
1010
1
3
3
1056
6
4
4
1092
-1
5
5
1062
5
6
6
1034
4
7
7
0
9
8
8
0
10
9
9
0
-1
10
10
Study the pseudocode:
PROCEDURE Place(Value : INTEGER, Start : INTEGER, Unused : INTEGER)
DECLARE New, Current, Last : INTEGER
CONSTANT NullPointer = -1
New
Unused
NullPointer
Last
Start
Current
WHILE Current <> NullPointer AND Data[Current] < Value
Current
Last
Pointer[Current]
Current
ENDWHILE
Pointer[Last]
Pointer[New]
New
Pointer[Last]
Value
Data[New]
ENDPROCEDURE
ĬÙĊ®Ġ´íÈõÏĪÅĊàû¸Ā×
,
,
(a) (i)
Complete the trace table below by dry running the procedure Place() when it is called
by the statement:
CALL Place(1043, 2, 8)
Value
Start
Unused
New
Last
Current
[4]
(ii)
Complete the diagram showing the contents of the global arrays Data and Pointer
after the procedure Place() has run to completion when called as shown in part (a)(i).
Data
Pointer
1018
1
1
1007
2
2
1010
3
3
1056
4
4
1092
5
5
1062
6
6
1034
7
7
8
8
9
9
10
10
[3]
(b) The operation carried out by procedure Place() together with the arrays form part of the
implementation of an Abstract Data Type (ADT).
Identify the ADT and state the operation carried out by procedure Place()
…
…
…
… [2]
ĬÛĊ®Ġ´íÈõÏĪÅĊàù¸Ā×

Advertisement
49
9618/22/M/J/25 · Question 7May/June 2025Paper 2218 marks
Loading question…
Question text

7
A program is being developed to implement a customer loyalty scheme for a coffee shop.
Each customer has a unique customer ID starting at 10001 with this value increasing by one each
time a new customer joins the loyalty scheme.
For example, the third customer who joins the loyalty scheme is given the customer ID 10003
The loyalty scheme is limited to 1000 customers.
A customer is awarded a loyalty point every time they buy a coffee.
The programmer has decided to use a global 2D array Loyalty of type INTEGER. The array
Loyalty is made up of 1000 rows and 2 columns. Each row relates to one customer; column 1
contains the unique customer ID and column 2 contains the number of customer loyalty points.
Rows in the array Loyalty that are not currently being used have the value of Column 1 set to
99999
The array is sorted in ascending order by customer ID.
The programmer has defined a program module:
Module
Description
•
called with parameter of type INTEGER representing a customer ID
•
searches the Loyalty array for this customer ID
•
the search will stop as soon as the customer ID is found
FindCustomer()
•
the search should efficiently deal with the situation when the
customer ID is not stored in the Loyalty array
•
if the customer ID is found, return an integer value representing the
loyalty points, otherwise return -1
ĬÕĊ®Ġ´íÈõÏĪÅĊßúµĂ×
,
,
(a) Write efficient pseudocode for module FindCustomer()
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…

50
9618/23/M/J/25 · Question 2May/June 2025Paper 2311 marks
Loading question…
Question text

2
A programmer uses a number of Abstract Data Types (ADT) in the programs that she is developing.
(a) A stack using memory locations 400 to 409 is used in one program.
The diagram represents the current state of the stack.
A variable TopOfStack pointer indicates the last value added to the stack.
Stack
Memory
Value
location
409
408
407
406
405
404
TopOfStack
403
'P'
402
'X'
401
'D'
400
'B'
(i)
Complete the answer column in the following table:
Answer
the memory location of the value that has been on the stack for
the longest time
the number of consecutive push operations that will result in the
TopOfStack variable containing 409
[2]
ĬÕĊ®Ġ´íÈõÏĪÅĊÞú·Ā×
,
,
(ii)
The diagram shows the current state of the stack.
Stack
Memory
Value
location
409
408
TopOfStack
407
'A'
406
'C'
405
'F'
404
'K'
403
'B'
402
'S'
401
'R'
400
'D'
The following sequence of operations are performed:
PUSH 'T'
POP
POP
PUSH 'Z'
PUSH 'X'
POP
PUSH 'Y'
Complete the following diagram to show the state of the stack after the operations have
been performed.
Stack
Memory
Value
location
409
408
407
406
405
404
403
402
401
400
[3]
Ĭ×Ċ®Ġ´íÈõÏĪÅĊÞü·Ā×
,
,
(b) In a different program, the programmer decides to implement a linked list using an array of
records.
(i)
The array is represented in the diagram.
A pointer value of –1 indicates the end of the linked list.
Complete the pointer field to produce a linked list that is in alphabetical order.
Index
Data
Pointer
0
"Neptune"
1
"Jupiter"
2
"Saturn"
3
"Earth"
4
"Mercury"
5
"Uranus"
[3]
(ii)
The variable StartPointer contains the index of the first item in the linked list.
State the value of the variable StartPointer
… [1]
(c) A third program is also being created to manage a queue.
Describe two features of a queue.
Feature one …
…
Feature two …
…
[2]
ĬÙĊ®Ġ´íÈõÏĪÅĊßü¶þ×

51
9618/23/M/J/25 · Question 4May/June 2025Paper 238 marks
Loading question…
Question text

4
A programmer is developing a new stock control program for a shop owner to produce sales
reports.
(a) A text file Sales.txt stores strings representing the number of items sold.
The file contains 52 lines, each representing the number of items sold in each week of the
year.
For example:
File line number
File data
1
"350"
2
"502"
3
"434"
49
"492"
50
"872"
51
"772"
52
"201"
The example shows that 502 items were sold in week 2.
The owner requires a module to output all week numbers where the number of items sold is
greater than 500.
Describe an algorithm that produces the required module.
Do not include pseudocode statements in your answer.
…
…
…
…
…
…
…
…
…
…
…
… [5]
ĬÙĊ®Ġ´íÈõÏĪÅĊÝü¶Ā×
,
,
(b) Once the program has been completed, it is tested using the walkthrough method.
Describe the walkthrough method and explain how it can be used to identify errors.
…
…
…
…
…
…
…
… [3]
ĬÛĊ®Ġ´íÈõÏĪÅĊÝú¶Ā×

52
9618/23/M/J/25 · Question 6May/June 2025Paper 239 marks
Loading question…
Question text

6
Study the structure chart:
Main
M
P
Sub_A
Sub_B
V
R
X
W
T
U
Sub_Part1A
Sub_Part2A
Sub_Part3A
Sub_Part1B
Sub_Part2B
Some of the parameter data types are:
•
R and V are of type INTEGER
•
T is of type REAL
•
U is of type STRING
•
W is of type BOOLEAN.
Some of the modules in the structure chart are functions, others are procedures.
(a) Explain one difference between functions and procedures.
…
… [1]
(b) Write the pseudocode to define the module headers:
Sub_Part1A
…
…
Sub_Part2A
…
…
Sub_Part3A
…
…
[5]
ĬÙĊ®Ġ´íÈõÏĪÅĊÞü¸Ā×
,
,
(c) The structure chart uses the two symbols shown.
Complete the table to explain what each symbol means and how the relevant modules in the
structure chart are affected.
Symbol
Explanation
…
…
…
…
…
…
[3]
ĬÛĊ®Ġ´íÈõÏĪÅĊÞú¸Ā×

53
9618/23/M/J/25 · Question 7May/June 2025Paper 2318 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
loyalty points
an integer value that depends on how often the customer visits the coffee shop
last visit date
the date the customer last visited the coffee shop
The programmer has defined a program module:
Module
Description
• called with two parameters:
1. loyalty points of type INTEGER
2. last visit date of type DATE
•
change the loyalty points:
 increase by four if the last visit date and the current date are in the
UpdateVisit()
same month
 otherwise increase by one
•
change the last visit date to the current date
•
the changed values must be available to the code that follows the call
to UpdateVisit()
(a) (i)
Write pseudocode for module UpdateVisit()
Assume the customer has made at least one previous visit.
…
…
…
…
…
…
…
…
…
…
…
…
…
[5]
ĬÕĊ®Ġ´íÈõÏĪÅĊÝùµĂ×
,
,
(ii)
The programmer decides to amend the UpdateVisit() module so that loyalty points
are further increased if the customer visits the coffee shop the same day of the week as
their last visit.
Write the pseudocode for this condition.
…
… [1]
Ĭ×Ċ®Ġ´íÈõÏĪÅĊÝûµĂ×
,
,
(b) A text file Loyalty.txt will be used to store the data items for the loyalty scheme.
The text file Loyalty.txt contains only one line of data for each customer.
Each data item is separated by a comma:
<CustomerID>,<LoyaltyPointsString>,<LastVisitDateString>
LastVisitDateString is always eight characters in length in the format: DDMMYYYY.
An example of how a line of data will be stored in the text file Loyalty.txt is:
"100123,132,05032025"
This example shows that the customer with an ID of 100123 had 132 loyalty points following
their last visit to the coffee shop on 05/03/2025.
If a customer visits the coffee sh

Advertisement
54
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]

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

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

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

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

Advertisement
59
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]

60
9618/21/O/N/24 · Question 1Oct/Nov 2024Paper 219 marks
Loading question…
Question text

1
A program will calculate the tax payable based on the cost of an item.
Calculations will occur at many places in the program and these involve the use of one of three tax
rates.
Tax rate values represent a percentage. For example, a tax rate value of 5.23 represents 5.23%.
In this case, the tax payable on an item costing $100 would be $5.23.
Tax rate values are used at several places within the program. One example is given in pseudocode
as follows:
←
HighRate
FALSE
CASE OF ItemCost
← 3.75
<= 50 : TaxRate
// tax rate of 3.75%
← 5.23
<= 200 : TaxRate
// tax rate of 5.23%
← 6.25
> 200 : TaxRate
// tax rate of 6.25%
← TRUE
HighRate
ENDCASE
←
* TaxRate // tax payable
TaxPayable
ItemCost
(a) The pseudocode contains a logical error.
Identify the error and suggest a correction.
Error …
…
Correction …
…
[2]
(b) During the design of the program, tax rate values have been used wherever they are needed
as shown in the pseudocode example above. Tax rates do not change while the program runs.
(i)
Identify a more appropriate way of representing the tax rate values in the final program.
… [1]
(ii)
Describe the benefits of your answer to part (b)(i) with reference to this program.
…
…
…
…
…
… [3]
ĬÕĊ®Ġ´íÈõÏĪÅĊÞü·þ×
,
,
(c) Give the appropriate data type for the variables in the following table, as used in the
pseudocode:
Variable name
Data type
HighRate
TaxPayable
[2]
(d) The final CASE condition (> 200) in the pseudocode example could be replaced with a
keyword.
Give the keyword.
… [1]
Ĭ×Ċ®Ġ´íÈõÏĪÅĊÞú·þ×

Advertisement