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

112 questions · page 4 of 8 · Clear filters

0 / 0Answer a question to start your score.
Quick quiz (10)Saved 0
Advertisement
46
9618/22/O/N/24 · Question 1Oct/Nov 2024Paper 229 marks
Loading question…
Question text

1
A program has been developed and released for general use. After a few months of use an error is
detected where under certain circumstances it outputs an unexpected value.
(a) The error in the program needs to be corrected.
Identify the stage of the program development life cycle that this correction is made in.
… [1]
(b) The program contains a function Lookup(). After investigation, it is found that this is the
function that sometimes returns an incorrect value.
An Integrated Development Environment (IDE) is used to help locate the error.
The IDE features of watch window, single stepping and breakpoint will be used.
Explain these features including the order that they will be used in to locate the error in
Lookup().
…
…
…
…
…
… [3]
(c) To solve the error a programmer decides to create a new module.
The design of the new module has been completed and the module is being coded.
Identify two features of an IDE that will help during the coding of this new module.
1 …
2 …
[2]
(d) The new module referred to in part (c) introduces three new variables.
Complete the following table by giving the appropriate data type for each.
Variable name
Used to store
Data type
Name
A customer name.
Index
An array index.
The result of the division of any two
Result
non-zero numbers.
[3]
ĬÍĊ¾Ġ´íÈõÏĪÅĊÝú¸þ×

47
9618/22/O/N/24 · Question 2Oct/Nov 2024Paper 229 marks
Loading question…
Question text

2
A program is being developed to process bank card information.
When a card number is displayed, all the characters except the last four are replaced with the
asterisk character '*'.
Card numbers are stored as strings. The strings are between 10 and 20 characters in length.
The function Conceal() will take a string representing a card number and return a modified
string.
Example strings:
Original string
Modified string
"1234567890"
"******7890"
"1234567897652"
"*********7652"
"1234567890123456" "************3456"
(a) The function Conceal() will:
•
take a numeric string as a parameter representing the card number
•
return a string in which the asterisk character replaces all except the last four characters
of the card number parameter.
Write pseudocode for the function Conceal().
…
…
…
…
…
…
…
…
…
…
…
…
…
…
… [6]
ĬÍĊ¾Ġ´íÈõÏĪÅĊßú¸Ā×
,
,
(b) The requirements have been changed. Conceal() will now be written as a procedure which
will process 100 card numbers each time it is called.
The card numbers will be stored in a 2D array CardNumber. The original string will be stored
in column one and the modified string in column two.
(i)
Write pseudocode to declare the array.
…
… [2]
(ii)
The new procedure Conceal() will write the modified string to the corresponding
element in column two.
The array CardNumber is passed as a parameter to the new procedure Conceal().
Identify how this parameter should be specified in the new procedure header.
…

48
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]
ĬÑĊ¾Ġ´íÈõÏĪÅĊÞüµþ×

Advertisement
49
9618/22/O/N/24 · Question 6Oct/Nov 2024Paper 229 marks
Loading question…
Question text

6
A shop sells sandwiches and snacks. The owner chooses a ‘daily special’ sandwich which is
displayed on a board outside the shop. Each ‘daily special’ has two different fillings and is made
with one type of bread.
The owner wants a program to randomly choose the ‘daily special’ sandwich.
The program designer decides to store the possible sandwich fillings in a 1D array of type string.
The array is declared in pseudocode as follows:
DECLARE Filling : ARRAY [1:35] OF STRING
Each element contains the name of one filling.
An example of the first five elements is as follows:
Index
Element value
"Cheese"
1
"Onion"
2
"Salmon"
3
"Anchovies"
4
"Peanut Butter"
5
A second 1D array stores the possible bread used:
DECLARE Bread : ARRAY [1:10] OF STRING
Each element contains the name of one type of bread.
An example of the first three elements is as follows:
Index
Element value
"White"
1
"Brown"
2
"Pitta"
3
Both arrays may contain unused elements. The value of these will be an empty string and they
may occur anywhere in each array.
A procedure Special() will output a message giving the ‘daily special’ sandwich made from two
randomly selected different fillings and one randomly selected bread.
Unused array elements must not be used when creating the ‘daily special’ sandwich.
Using the above examples, the output could be:
"The daily special is Cheese and Onion on Brown bread."
ĬÑĊ¾Ġ´íÈõÏĪÅĊßü·Ā×
,
,
(a) Complete the pseudocode for the procedure Special().
Assume that both arrays are global.
PROCEDURE Special()
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…

50
9618/22/O/N/24 · Question 8Oct/Nov 2024Paper 2218 marks
Loading question…
Question text

8
A program is being developed to implement a game for up to six players.
During the game, each player assembles a team of characters. At the start of the game there are
45 characters available.
Each character has four attributes, as follows:
Attribute
Examples
Comment
Player
0, 1, 3
The player the character is assigned to.
The job that the character will perform in the
Role
Builder, Teacher, Doctor
game.
The name of the character. Several characters
Name
Bill, Lee, Farah, Mo
may perform the same role, but they will each
have a unique name.
The skill level of the character. An integer in the
Level
14, 23, 76
range 0 to 100 inclusive.
The programmer has defined a record type to define each character.
The record type definition is shown in pseudocode as follows:
TYPE CharacterType
DECLARE Player : INTEGER
DECLARE Role : STRING
DECLARE Name : STRING
DECLARE Level : INTEGER
ENDTYPE
The Player field indicates the player to which the character is assigned (1 to 6). The field value is
0 if the character is not assigned to any player.
The programmer has defined a global array to store the character data as follows:
DECLARE Character : ARRAY[1:45] OF CharacterType
At the start of the game all record fields are initialised, and all Player field values are set to 0
The programmer has defined a program module as follows:
Module
Description
Assign()
•
called with two parameters:
○ an integer representing a player
○ a string representing a character role
•
search the Character array for an unassigned character with the
required role
•
If found, assign the character to the given player and output a confirmation
message, for example:
"Bill the Builder has been assigned to player 3"
•
If no unassigned character with the required role is found, output a suitable
message.
ĬÍĊ¾Ġ´íÈõÏĪÅĊßù¸Ă×
,
,
(a) Write pseudocode for module Assign().
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…

51
9618/23/O/N/24 · Question 2Oct/Nov 2024Paper 237 marks
Loading question…
Question text

2
An algorithm will:
1.
prompt and input a sequence of 100 integer values, one at a time
2.
sum the positive integers
3.
output the result of the sum.
(a) Write pseudocode for the algorithm.
Assume the value zero is neither positive nor negative.
You must declare all variables used in the algorithm.
…
…
…
…
…
…
…
…
…
…
…
…
… [5]
(b) The algorithm requires the use of basic constructs. One of these is sequence.
Identify one other basic construct required by the algorithm and describe how it is used.
Construct …
Use …
…
[2]
Ĭ×Ċ®Ġ´íÈõÏĪÅĊÝû·þ×

52
9618/23/O/N/24 · Question 3Oct/Nov 2024Paper 2310 marks
Loading question…
Question text

3
The implementation of a linked list uses an integer variable and a 1D array List of type Node.
Record type Node is declared in pseudocode as follows:
TYPE Node
DECLARE Data : STRING
DECLARE Pointer : INTEGER
ENDTYPE
The array List is declared in pseudocode as follows:
DECLARE List : ARRAY[1:200] OF Node
The linked list will operate as follows:
•
Integer variable HeadPointer will store the array index for the first node in the linked list.
•
The Pointer field of a node contains the index value of the next array element (the next
node) in the linked list.
•
The value 0 is used as a null pointer.
(a) (i)
State why the value 0 has been selected as the null pointer.
…
… [1]
(ii)
Give the range of valid values that could be assigned to variable HeadPointer.
… [1]
ĬÕĊ®Ġ´íÈõÏĪÅĊßù·Ā×
,
,
(b) The array List will be initialised so that each node points to the following node.
The last node will contain a null pointer.
Complete the program flowchart to represent the algorithm for this operation.
START
END
[4]
Ĭ×Ċ®Ġ´íÈõÏĪÅĊßû·Ā×
,
,
(c) An algorithm outputs the Data field from all nodes in the array List. The order the Data is
output should be the same order it is stored in the linked list.
Describe the algorithm in four steps.
Do not use pseudocode statements in your answer.
Step 1 …
…
…
Step 2 …
…
…
Step 3 …
…
…
Step 4 …
…
…
[4]
ĬÙĊ®Ġ´íÈõÏĪÅĊÞû¶þ×

53
9618/23/O/N/24 · Question 4Oct/Nov 2024Paper 2312 marks
Loading question…
Question text

4
An examination 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.
A program is being written to process examination marks.
The five grade boundaries are stored in a global 1D array GB of type INTEGER, for example:
Index
Value
Comment
65
1
The minimum mark for an A grade.
57
2
The minimum mark for a B grade.
43
3
The minimum mark for a C grade.
35
4
The minimum mark for a D grade.
27
5
The minimum mark for an E grade.
Any paper that achieves a mark within 2 marks of a grade boundary must be checked. Using the
given table, a paper with 45 marks would need to be checked.
(a) The pseudocode algorithm to determine whether a paper should be checked is as shown.
The mark for the paper is stored in variable Mark. Global variables Mark, Index, Upper and
Lower are declared as integers.
Complete the pseudocode.
← 1 TO …
FOR Index
Lower ← GB[Index] - 2
Upper ← …
IF Mark … AND Mark … THEN
OUTPUT "Check this paper"
ENDIF
NEXT Index
[4]
(b) An alternative algorithm to determine if a paper needs to be checked uses a global 1D array
Check, containing 76 elements of type BOOLEAN. The indices of the array are from 0 to 75
(inclusive), corresponding to the range of possible marks.
An element value in Check is TRUE if the index is within 2 marks of a grade boundary. For
example, in the case where the C grade boundary is 43 the corresponding part of the Check
array would be as follows:
Index
Value
FALSE
40
TRUE
41
TRUE
42
← The grade boundary for a C grade
TRUE
43
TRUE
44
TRUE
45
FALSE
46
ĬÙĊ®Ġ´íÈõÏĪÅĊàû¶Ā×
,
,
(i)
The mark for a given paper is stored in variable Mark.
Describe how an algorithm would use the Check array to determine whether this paper
should be checked.
…
…
…
… [2]
(ii)
A procedure GBInitialise() will initialise the Check array using values from the GB
array.
Note it can be assumed that the maximum grade boundary value for A is 70 and the
minimum value for E is 15.
Write pseudocode for the procedure.
…
…
…
…
…
…
…
…
…

Advertisement
54
9618/23/O/N/24 · Question 8Oct/Nov 2024Paper 2316 marks
Loading question…
Question text

8
A program is being developed to implement a game for up to six players.
During the game, each player assembles a team of characters. At the start of the game there are
45 characters available.
Each character has four attributes, as follows:
Attribute
Examples
Comment
Player
0, 1, 3
The player the character is assigned to.
The job that the character will perform in the
Role
Builder, Teacher, Doctor
game.
The name of the character. Several characters
Name
Bill, Lee, Farah, Mo
may perform the same role, but they will each
have a unique name.
Skill level
14, 23, 76
An integer in the range 0 to 100, inclusive.
The programmer has defined a record type to define each character. The record type definition is
shown in pseudocode as follows:
TYPE CharacterType
DECLARE Player : INTEGER
DECLARE Role : STRING
DECLARE Name : STRING
DECLARE SkillLevel : INTEGER
ENDTYPE
The Player field indicates the player to which the character is assigned (1 to 6). This field value
is 0 if the character is not assigned to any player.
The programmer has defined a global array to store the character data, as follows:
DECLARE Character : ARRAY[1:45] OF CharacterType
At the start of the game all record fields are initialised, and all Player fields are set to 0
The programmer has defined a program module as follows:
Module
Description
Count()
•
called with two parameters:
○ an integer representing a player
○ a string representing a character role
•
searches the Character array for characters with the given role that are
assigned to the given player
•
counts the number of assigned characters and sums their total skill level
•
outputs the result of the search if characters with the given role are found,
for example:
"Player 3 has 4 characters with the role of Teacher
and the total skill level is 65"
•
if no characters with the given role are found, outputs:
"No characters with that role are assigned to this
player"
ĬÕĊ®Ġ´íÈõÏĪÅĊàúµĂ×
,
,
(a) Complete the pseudocode for module Count().
PROCEDURE Count(ThisPlayer : INTEGER, ThisRole : STRING)
…
…
…
…
…
…
…
…
…
…
…
…
…
…

55
9618/21/M/J/24 · Question 3May/June 2024Paper 218 marks
Loading question…
Question text

3
The diagram shows an Abstract Data Type (ADT) representation of a linked list after data items
have been added.
•
PS is the start pointer.
•
PF is the free list pointer.
•
Labels Df, Dc, Db and Dy represent the data items of nodes in the list.
•
Labels Fg, Fh, Fm and Fw represent the data items of nodes in the free list.
•
The symbol Ø represents a null pointer.
PS
Df
Dc
Db
Dy
Ø
PF
Fg
Fh
Fm
Fw
Ø
(a) Describe the linked list immediately after initialisation, before any data items are added.
…
…
…
…
…
… [3]
(b) A program will be written to include a linked list to store alphanumeric user IDs.
The design uses two variables and two 1D arrays to implement the linked list.
Each array element contains data of a single data type and not a record.
The statements below describe the design.
Complete the statements.
The two variables will be of type … .
The two variables will be used as … to the arrays.
The values stored in the two variables will indicate …
… .
The first 1D array will be of type … .
The first 1D array will be used to … .
The second 1D array will be of type … .
The second 1D array will be used to … .
[5]

56
9618/21/M/J/24 · Question 4May/June 2024Paper 216 marks
Loading question…
Question text

A global 1D array Data contains 100 elements of type integer.
4
A function Check() will:
•
total the element values in odd index locations (1, 3, 5 ... 97, 99)
•
total the element values in even index locations (2, 4, 6 ... 98, 100)
•
return one of three strings ‘Odd’, ‘Even’ or ‘Same’ to indicate which total is the greater, or
whether the totals are the same.
Write pseudocode for the function Check().
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
… [6]

57
9618/21/M/J/24 · Question 7May/June 2024Paper 2112 marks
Loading question…
Question text

7
A fitness club has a computerised membership system. The fitness club offers a number of
different exercise classes.
The following information is stored for each club member: name, home address, email address,
mobile phone number, date of birth and the exercise(s) they are interested in.
(a) When an exercise class is planned, a new module will send personalised text messages to
each member who has expressed an interest in that exercise. Members wishing to join the
class send a text message back. Members may decide not to receive future text messages
by replying with the message ‘STOP’.
The process of abstraction is used to filter out unnecessary information.
(i)
State one advantage of applying abstraction to this problem.
…
… [1]
(ii)
Identify three items of information that will be required by the new module.
Justify your choices with reference to the given scenario.
Item 1 required …
Justification …
…
Item 2 required …
Justification …
…
Item 3 required …
Justification …
…
[3]
(iii)
Identify two operations that would be required to process data when the new module
receives a text message back from a member.
Operation 1 …
…
Operation 2 …
…
[2]
(b) The structure chart illustrates part of the membership program:
Update
A
P2
T1
Name
P1
Sub-A
Sub-B
Sub-C
Data item notes:
•
Name contains the name of a club member
•
P1 and T1 are of type real.
(i)
Explain the meaning of the diamond symbol (labelled with the letter A) in the chart.
…
…
…
… [2]
(ii)
Write the pseudocode module headers for Sub-A and Sub-B.
Sub-A
…

58
9618/22/M/J/24 · Question 1May/June 2024Paper 2210 marks
Loading question…
Question text

1
(a) The following table contains pseudocode examples.
Each example may contain statements that relate to one or more of the following:
•
selection
•
iteration (repetition)
•
input/output.
Complete the table by placing one or more ticks (3) in each row.
Pseudocode example
Selection
Iteration
Input/Output
FOR Index
1 TO 10
0
Data[Index]
NEXT Index
WRITEFILE ThisFile, "****"
UNTIL Level > 25
IF Mark > 74 THEN
READFILE OldFile, Data
ENDIF
[4]
(b) Program variables have data types as follows:
Variable
Data type
MyChar
CHAR
MyString
STRING
MyInt
INTEGER
Complete the table by filling in each gap with a function (from the insert) so that each expression
is valid.
Expression
MyInt
… (3.1415926)
MyChar
… ("Elwood", 3, 1)
MyString
… ( … (27.509))
MyInt
… ( … ("ABC123", 3))
[4]
(c) The variables given in part (b) are chosen during the design stage of the program development
life cycle.
The choices are to be documented to simplify program maintenance.
State a suitable way of documenting the variables and give one piece of information that
should be recorded, in addition to the data type.
…
…
… [2]

Advertisement
59
9618/22/M/J/24 · Question 3May/June 2024Paper 229 marks
Loading question…
Question text

3
A factory needs a program to help manage its production of items.
Data will be stored about each item.
The data for each item will be held in a record structure of type Component.
The programmer has started to define the fields that will be needed as shown in the table.
Field
Example value
Comment
Item_Num
123478
a numeric value used as an array index
Reject
FALSE
TRUE if this item has been rejected
Stage
'B'
a letter to indicate the stage of production
Limit_1
13.5
any value in the range 0 to 100 inclusive
Limit_2
26.4
any value in the range 0 to 100 inclusive
Write pseudocode to declare the record structure for type Component.
(a) (i)
…
…
…
…
…
…
… [4]
A 1D array Item of 2000 elements will store the data for all items.
(ii)
Write pseudocode to declare the Item array.
…
… [2]
(b) State three benefits of using an array of records to store the data for all items.
1 …
…
2 …
…
3 …
…
[3]

60
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