Data types, records, arrays and abstract data types – A Level Computer Science (9618)
112 questions · page 3 of 8 · Clear filters
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()
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
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()
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
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.
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
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]
ĬÛĊ®Ġ´íÈõÏĪÅĊÝù¶þ×
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.
…
…
…
…
…
…
…
…
…
…
…
…
…
…
ĬÙĊ®Ġ´íÈõÏĪÅĊÞû¸þ×
,
,
…
…
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]
ĬÛĊ®Ġ´íÈõÏĪÅĊàù¸Ā×
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()
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
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]
ĬÙĊ®Ġ´íÈõÏĪÅĊßü¶þ×
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]
ĬÛĊ®Ġ´íÈõÏĪÅĊÝú¶Ā×
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]
ĬÛĊ®Ġ´íÈõÏĪÅĊÞú¸Ā×
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
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]
Ĭ×Ċ®Ġ´íÈõÏĪÅĊÞú·þ×
Question text
3
An algorithm will output the last three lines from a text file Result.txt
The lines need to be output in the same order as they appear in the file.
Assume:
•
Three variables LineX, LineY and LineZ will store the three lines. These are of type string
and all three variables have been initialised to an empty string.
•
The file exists and contains at least three lines.
(a) The algorithm to output the lines is expressed in eight steps.
Complete the steps.
1.
Open the file …
2.
Loop until …
3.
… and store in ThisLine
4.
Assign LineY to LineX
5.
Assign LineZ to LineY
6.
Assign ThisLine to LineZ
7.
After the loop, …
8.
Output LineX, LineY, LineZ
[4]
(b) Explain the purpose of steps 4, 5 and 6 in the algorithm from part (a).
…
…
… [1]
ĬÙĊ®Ġ´íÈõÏĪÅĊÝú¶þ×
,
,
(c) The requirement changes, and the algorithm will now output three lines from the file, starting
from a given line number.
The modified algorithm will be implemented as a function which will:
•
be called with an integer parameter representing the given line number
•
output three lines, starting at the given line
•
return TRUE if the 3 lines are output, or FALSE if it was not possible to output the 3 lines.
Describe the changes that need to be made to steps 2 to 8 of the algorithm given in part (a).
…
…
…
…
…
…
…
…
…
… [4]
ĬÛĊ®Ġ´íÈõÏĪÅĊÝü¶þ×
Question text
6
A factory produces food items. The items must be used within a certain number of days after their
production date. The number of days is known as the shelf life. It is different for each type of item
but is always a whole number in the range 1 to 21 (inclusive).
The latest date that an item can be used is called the ‘use-by’ date.
A program is needed to produce labels which show the ‘use-by’ date.
Part of the program is a function GetDate() which will:
•
take two parameters: a production date and a value representing the shelf life
•
return the corresponding ‘use-by’ date.
The program contains a global 1D array DaysInMonth of type integer which stores the number of
days in each month (index 1 is January):
Index
Value
31
1
28
2
Note: Leap years are not considered
31
3
30
4
30
11
31
12
(a) An algorithm uses the array DaysInMonth to calculate a ‘use-by’ date. An alternative design
would involve the use of multiple selection statements.
An array-based technique is often used when there is a large number of different values to
check and where no pattern exists.
One advantage of using an array-based technique is the speed of execution compared to the
use of multiple selection statements.
Give two other advantages of using an array for this type of operation rather than a solution
based on multiple selection statements.
1 …
…
2 …
…
[2]
ĬÙĊ®Ġ´íÈõÏĪÅĊàú¸Ā×
,
,
(b) Complete the pseudocode for the function GetDate().
Date functions from the insert should be used in your solution.
FUNCTION GetDate(ProductionDate : DATE, ShelfLife : INTEGER) RETURNS DATE
…
…
…
…
…
…
…
…
…
…
…
…
Question text
8
An exam paper has a maximum of 75 marks. One of five pass grades (A to E) is assigned,
depending on the mark obtained. The lowest mark for a given grade is known as the grade
boundary. For example, if the grade boundary for an A grade is 65 marks, then any candidate who
achieves a mark of 65 or above will be awarded an A. A grade of U is awarded for marks below the
E grade boundary.
The five grade boundaries are stored in a global 1D array GradeBoundary of type integer.
For example:
Element
Value
Comment
GradeBoundary[1]
65
The minimum mark for an A grade.
GradeBoundary[2]
57
The minimum mark for a B grade.
GradeBoundary[3]
43
The minimum mark for a C grade.
GradeBoundary[4]
35
The minimum mark for a D grade.
GradeBoundary[5]
27
The minimum mark for an E grade.
A global 2D array Result of type integer contains candidate marks for the exam. Each row
relates to one candidate. Column 1 contains the candidate mark and column 2 contains the unique
candidate ID.
For example, for the fourth and fifth candidates:
Element
Mark
Element
ID
Result[4, 1]
56
Result[4, 2]
1074832
Result[5, 1]
54
Result[5, 2]
2573839
There are more rows in the array than candidates who sit the exam. Any unused rows will be at
the end of the array.
Candidate papers that are given a mark within two marks of any grade boundary must be checked.
For example, given the values in the example grade boundaries above, any paper that was
awarded between 41 and 45 marks (inclusive) would need to be checked.
A program is being written to identify papers that need to be checked.
The programmer has defined the first program module as follows:
Module
Description
•
called with a parameter of type integer representing a
candidate mark
CheckMark()
•
returns TRUE if the mark is within 2 of any of the five grade
boundaries, otherwise returns FALSE
ĬÕĊ®Ġ´íÈõÏĪÅĊÝûµĄ×
,
,
(a) Write pseudocode for module CheckMark().
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…