Data types, records, arrays and abstract data types – A Level Computer Science (9618)
112 questions · page 6 of 8 · Clear filters
Question text
3
Customers collect points every time they make a purchase at a store.
A program is used to manage the points system and the table lists some of the information stored
for one customer.
Information
Data type required
Name
String
Number of points collected
Integer
Date of birth
Date
(a) (i)
Identify a suitable structure for storing the information for one customer. Explain the
advantage of using this structure.
Structure …
Advantage …
…
…
…
…
…
[4]
(ii)
Describe a data structure that could be used to store the information for all customers.
…
… [2]
(b) Customers receive points depending on the amount they spend. The number of points
depends on the band that the amount falls into:
Band
Amount
Points
1
Less than $10
5 per whole dollar ($)
2
Between $10 and $100 inclusive
7 per whole dollar ($)
3
Over $100
10 per whole dollar ($)
For example, if the amount is $99.77, this amount is in band 2 and therefore the number of
points is 7 × 99, which is 693 points.
The algorithm to calculate the points from a given amount is expressed as follows:
•
work out the appropriate band
•
calculate and output the number of points.
Apply the process of stepwise refinement to increase the detail of the algorithm. Structure
your algorithm into a sequence of five steps that could be used to produce pseudocode.
Write the five steps.
1 …
…
…
2 …
…
…
3 …
…
…
4 …
Question text
6
A video-conferencing program supports up to six users. Speech from each user is sampled and
digitised (converted from analogue to digital). Digitised values are stored in array Sample.
The array Sample consists of 6 rows by 128 columns and is of type integer. Each row contains
128 digitised sound samples from one user.
The digitised sound samples from each user are to be processed to produce a single value which
will be stored in a 1D array Result of type integer. This process will be implemented by procedure
Mix().
A procedure Mix() will:
•
calculate the average of each of the 6 sound samples in a column
•
ignore sound sample values of 10 or less
•
store the average value in the corresponding position in Result
•
repeat for each column in array Sample
The diagram uses example values to illustrate the process:
2
3
...
126 127 128
1
20
20
20
30 30
2
1
20
20
30
50 30
3
2
20
20
40
40 40
4
3
Sample:
20
20
50
40 50 20
4
20
3
5
6
60
4
5
20
4
2
4
70 30
6
Result:
20
20
35
40
46
25
Write pseudocode for procedure Mix().
Assume Sample and Result are global.
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
Question text
7
A school has a computerised library system that allows students to borrow books for a fixed length
of time. The system uses text files to store details of students, books and loans.
A new module is to be written which will generate emails to each student who has an overdue
book.
(a) Decomposition will be used to break down the problem of designing the new module into
sub-problems.
Identify three program modules that could be used in the design and describe their use.
Module 1 …
Use …
…
…
…
Module 2 …
Use …
…
…
…
Module 3 …
Use …
…
…
…
[3]
(b) The program designer produces a structure chart for the new module. Part of the structure
chart is shown:
Module-A()
Module-B()
Module-C()
Module-D()
(i)
Explain the relationship between the four modules shown.
…
…
…
… [2]
(ii)
Two new modules are added: Module‑X() and Module‑Y().
•
Module‑X() has no parameters.
•
Module‑Y() will take a string and a real number as parameters and return a
Boolean value.
•
Module‑D() will call either Module‑X() or Module‑Y().
Draw only the part of the structure chart that represents the relationship between
Module‑X(), Module‑Y() and Module‑D().
[3]
Question text
1
A program calculates the postal cost based on the weight of the item and its destination.
Calculations occur at various points in the program and these result in the choice of several
possible postal costs. The programmer has built these postal costs into the program.
For example, the postal cost of $3.75 is used in the following lines of pseudocode:
IF Weight < 250 AND ValidAddress = TRUE THEN
3.75
// set postal cost for item to $3.75
ItemPostalCost
"Valid"
// item can be sent
ItemStatus
ENDIF
(a) (i)
Identify a more appropriate way of representing the postal costs.
… [1]
(ii)
Describe the advantages of your answer to part (a)(i) with reference to this program.
…
…
…
…
…
… [3]
(b) The lines of pseudocode contain features that make them easier to understand.
State three of these features.
1 …
2 …
3 …
[3]
(c) Give the appropriate data types for the following variables:
ValidAddress …
ItemPostalCost …
ItemStatus …
[3]
Question text
2
A program stores a user’s date of birth using a variable MyDOB of type DATE.
(a) Write a pseudocode statement, using a function from the insert, to assign the value
corresponding to 17/11/2007 to MyDOB.
… [1]
(b) MyDOB has been assigned a valid value representing the user’s date of birth.
Write a pseudocode statement to calculate the number of months from the month of the
user’s birth until the end of the year and to assign this to the variable NumMonths.
For example, if MyDOB contains a value representing 02/07/2008, the value 5 would be
assigned to NumMonths.
… [2]
(c) The program will output the day of the week corresponding to MyDOB.
For example, given the date 22/06/2023, the program will output "Thursday".
An algorithm is required. An array will be used to store the names of the days of the week.
Define the array and describe the algorithm in four steps.
Do not use pseudocode statements in your answer.
Array definition …
…
Step 1 …
…
…
Step 2 …
…
…
Step 3 …
…
…
Step 4 …
…
…
[6]
Question text
3
A program stores data in a text file. When data is read from the file, it is placed in a queue.
(a) The diagram below represents an Abstract Data Type (ADT) implementation of the queue.
Each data item is stored in a separate location in the data structure. During initial design, the
queue is limited to holding a maximum of 10 data items.
The operation of this queue may be summarised as follows:
•
The Front of Queue Pointer points to the next data item to be removed.
•
The End of Queue Pointer points to the last data item added.
•
The queue is circular so that locations can be reused.
0
1
2
3
4
5
Front of Queue Pointer
Red
6
Green
7
Blue
8
End of Queue Pointer
Pink
9
(i)
Describe how the data items Orange and Yellow are added to the queue shown in the
diagram.
…
…
…
…
…
…
…
… [4]
(ii)
The following diagram shows the state of the queue after several operations have been
performed. All queue locations have been used at least once.
0
D4
1
End of Queue Pointer
D3
2
D27
3
D8
4
D33
5
Front of Queue Pointer
D17
6
D2
7
D1
8
D45
9
D60
State the number of data items in the queue.
… [1]
(b) The design of the queue is completed and the number of locations is increased.
A function AddToQueue() has been written. It takes a string as a parameter and adds this to
the queue. The function will return TRUE if the string was added successfully.
A procedure FileToQueue() will add each line from the file to the queue. This procedure
will end when all lines have been added or when the queue is full.
Describe the algorithm for procedure FileToQueue().
Do not use pseudocode in your answer.
…
…
…
…
…
…
…
…
Question text
1
The following pseudocode represents part of the algorithm for a program.
Line numbers are for reference only.
10
DECLARE Sheet4 : ARRAY[1:2, 1:50] OF INTEGER
…
100
FOR PCount
0 TO 49
0
101
Sheet4[1, PCount]
47
102
Sheet4[2, PCount]
103
NEXT PCount
(a) The pseudocode contains references to an array.
Complete the table by writing the answer for each row.
Answer
The dimension of the array
The name of the variable used as an array index
The number of elements in the array
[3]
(b) The pseudocode contains two errors. One error is that variable PCount has not been
declared.
Identify the other error and state the line number where it occurs.
Error …
…
…
Line number …
[2]
(c) The pseudocode does not include a declaration for PCount.
State the data type that should be used in the declaration.
… [1]
(d) The pseudocode statements given in the following table are used in other parts of the
algorithm.
Complete the table by placing one or more ticks (✓) in each row.
The first row has already been completed.
Pseudocode statement
Input
Process
Output
INPUT MyChoice
✓
OUTPUT FirstName & LastName
WRITEFILE YourFile, TextLine
READFILE MyFile, TextLine
SQRT(NextNum)
Result
[4]
Question text
3
A program processes data using a stack. The data is copied to a text file before the program ends.
(a) The following diagram shows the current state of the stack.
The operation of this stack may be summarised as follows:
•
The TopOfStack pointer points to the last item added to the stack.
•
The BottomOfStack pointer points to the first item on the stack.
•
The stack grows upwards when items are added.
Stack
Pointer
Memory location
Value
506
505
WWW
TopOfStack
504
YYY
503
XXX
502
ZZZ
501
NNN
500
PPP
BottomOfStack
(i)
An error will be generated if an attempt is made to POP a value when the stack is empty.
State the maximum number of consecutive POP operations that could be performed on
the stack shown above before an error is generated.
… [1]
(ii)
The following operations are performed:
1.
POP and store value in variable Data1
2.
POP and store value in variable Data2
3.
PUSH value AAA
4.
PUSH value BBB
5.
POP and discard value
6.
POP and store value in variable Data2
Complete the diagram to show the state of the stack and the variables after the given
operations have been performed.
Stack
Pointer
Memory location
Value
506
505
504
503
Variable
Value
502
Data1
501
Data2
500
[4]
(b) The data is copied to a text file before the program ends.
(i)
State an advantage of writing the data from the stack to a text file before the program
ends.
…
… [1]
(ii)
A module SaveStack() will write the data from the stack to a text file.
Express an algorithm for SaveStack() as five steps that could be used to produce
pseudocode.
Write the five steps.
Step 1 …
…
Step 2 …
…
Step 3 …
…
Step 4 …
…
Step 5 …
…
[5]
Question text
8
A computer shop assembles desktop computers, using items bought from several suppliers. A text
file Stock.txt contains information about each item.
Information for each item is stored as a single line in the Stock.txt file in the format:
<ItemNum><SupplierCode><Description>
Item information is as follows:
Format
Comment
unique number for each item in the range “0001”
ItemNum
4 numeric characters
to “5999” inclusive
SupplierCode
3 alphabetic characters
code to identify the supplier of the item
Description
a string
a minimum of 12 characters
The file is organised in ascending order of ItemNum and does not contain all possible values in
the range.
The programmer has defined the first program module as follows:
Module
Description
ChangeSupp()
• called with two parameters Code1 and Code2 of type string that represent
valid supplier codes
• creates a new file NewStock.txt from the contents of the
file Stock.txt where any reference to Code1 is replaced by Code2
• returns a count of the number of items that have had their supplier code
changed
(a) Write pseudocode for module ChangeSupp().
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
Question text
1
(a) An algorithm includes a number of complex calculations. A programmer is writing a program
to implement the algorithm and decides to use library routines to provide part of the solution.
State three possible benefits of using library routines in the development of the program.
1 …
…
2 …
…
3 …
…
[3]
(b) The following pseudocode is part of a program that stores names and test marks for use in
other parts of the program.
DECLARE Name1, Name2, Name3 : STRING
DECLARE Mark1, Mark2, Mark3 : INTEGER
INPUT Name1
INPUT Mark1
INPUT Name2
INPUT Mark2
INPUT Name3
INPUT Mark3
(i)
The pseudocode needs to be changed to allow for data to be stored for up to 30 students.
Explain why it would be good practice to use arrays to store the data.
…
…
…
…
…
… [3]
(ii)
The following pseudocode statement includes array references:
OUTPUT "Student ", Name[Count], " scored ", Mark[Count]
State the purpose of the variable Count and give its data type.
Purpose …
…
Data type …
[2]
(c) The pseudocode statements in the following table may contain errors.
State the error in each case or write ‘NO ERROR’ if the statement contains no error.
Assume that any variables used are of the correct type for the given function.
Statement
Error
← "" THEN
IF EMPTY
← IS_NUM(-23.4)
Status
← STR_TO_NUM("37") + 5
X
← STR_TO_NUM("37" + "5")
Y
[4]
Question text
3
A 1D array Data of type integer contains 200 elements. Each element has a unique value.
An algorithm is required to search for the largest value and output it.
Describe the steps that the algorithm should perform.
Do not include pseudocode statements in your answer.
…
…
…
…
…
…
…
…
…
…
…
… [5]
Question text
4
(a) The following diagram shows an Abstract Data Type (ADT) representation of an ordered
linked list. The data item stored in each node is a single character. The data will be accessed
in alphabetical order.
The symbol Ø represents a null pointer.
Start pointer
'C'
'J'
'L'
Ø
(i)
Nodes with data 'A' and 'K' are added to the linked list. Nodes with data 'J' and 'L' are
deleted.
After the changes, the data items still need to be accessed in alphabetical order.
Complete the diagram to show the new state of the linked list.
Start pointer
'C'
'J'
'L'
[4]
(ii)
The original data could have been stored in a 1D array in which each element stores a
character.
For example:
'C'
'J'
'L'
Explain the advantages of making the changes described in part (a)(i) when the data is
stored in the linked list instead of an array.
…
…
…
… [2]
(iii)
Explain the disadvantages of making the changes described in part (a)(i) when the data
is stored in the linked list instead of an array.
…
…
…
… [2]
(b) A program will store data using a linked list like the one shown in part (a).
Explain how the linked list can be implemented.
…
…
…
…
…
…
…
… [4]
Question text
5
A program uses two 1D arrays of type integer. Array1 contains 600 elements and Array2
contains 200 elements.
Array1 contains sample values read from a sensor. The sensor always takes three consecutive
samples and all of these values are stored in Array1.
A procedure Summarise() will calculate the average of three consecutive values from Array1
and write the result to Array2. This will be repeated for all values in Array1.
The diagram below illustrates the process for the first six entries in Array1.
}
Array1
Array2
Comment
15
10
average of first three values
20
41
average of next three values
}
15
40
41
42
Write pseudocode for the procedure Summarise().
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
… [5]
Question text
2
(a) An algorithm will process data from a test taken by a group of students. The algorithm will
prompt and input the name and test mark for each of the 35 students.
The algorithm will add the names of all the students with a test mark of less than 20 to an
existing text file Support_List.txt, which already contains data from other group tests.
(i)
Describe the steps that the algorithm should perform.
Do not include pseudocode statements in your answer.
…
…
…
…
…
…
…
…
…
…
…
… [5]
(ii)
Explain why it may be better to store the names of the students in a file rather than in an
array.
…
…
… [1]
(iii)
Explain why WRITE mode cannot be used in the answer to part 2(a)(i).
…
…
… [1]
(b) Examine the following state-transition diagram.
Input-A Output-X
Input-B Output-W
Input-B
START
S2
S1
S3
Input-A
Input-A
Input-B
Input-A Output-W
S4
Complete the table to show the inputs, outputs and next states.
Input
Output
Next state
S1
Input-A
S2
Output-W
Output-W
[4]
Question text
3
A stack is used in a program to store string data which needs to be accessed in several modules.
(a) A stack is an example of an Abstract Data Type (ADT).
Identify one other example of an ADT and describe its main features.
Example …
Features …
…
…
…
…
…
[3]
(b) Explain how the stack can be implemented using an array.
…
…
…
…
…
…
…
…
…
…
…
…
…
…
… [5]
(c) A second stack is used in the program. The diagram below shows the initial state of this
stack. Value X is at the top of the stack and was the last item added.
Upper-case letters are used to represent different data values.
Stack operations are performed in three groups as follows:
Group 1:
PUSH D
PUSH E
Group 2:
POP
POP
POP
Group 3:
PUSH A
PUSH B
POP
PUSH C
Complete the diagram to show the state of the stack after each group of operat