Past paper – A Level Computer Science (9618)
Cambridge International AS & A Level · 9618
Computer Science · Paper 22
Oct/Nov 2024 · 9618/22/O/N/24
Answer on paper, open each mark scheme and give yourself marks, then open the Summary.
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]
ĬÍĊ¾Ġ´íÈõÏĪÅĊÝú¸þ×
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.
…
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]
ĬÑĊ¾Ġ´íÈõÏĪÅĊÞüµþ×
Question text
4
A global integer variable Tick is always incremented every millisecond (1000 times per second)
regardless of the other programs running.
The value of Tick can be read by any program but the value should not be changed.
Assume that the value of Tick does not overflow.
As an example, the following pseudocode algorithm would output "Goodbye" 40 seconds after
outputting "Hello".
DECLARE Start : INTEGER
OUTPUT "Hello"
Tick
Start
REPEAT
//do nothing
UNTIL Tick = Start + 40000
OUTPUT "Goodbye"
A program is needed to help a user to time an event such as boiling an egg.
The time taken for the event is known as the elapsed time.
The program contains a procedure Timer() which will:
•
take two integer values representing an elapsed time in minutes and seconds
•
use the value of variable Tick to calculate the elapsed time
•
output a warning message 30 seconds before the elapsed time is up
•
output a final message when the total time has elapsed.
For example, to set an alarm for 5 minutes and 45 seconds the program makes the following call:
CALL Timer(5, 45)
When 5 minutes and 15 seconds have elapsed, the program will output:
"30 seconds to go"
When 5 minutes and 45 seconds have elapsed, the program will output:
"The time is up!"
ĬÑĊ¾Ġ´íÈõÏĪÅĊàüµĀ×
,
,
Write pseudocode for the procedure Timer().
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
Question text
5
A program contains a global 1D array Data with 100 elements of type INTEGER.
The program contains a function Process() expressed in pseudocode as follows:
FUNCTION Process(Number : INTEGER, Label : STRING) RETURNS STRING
DECLARE Index, Count : INTEGER
DECLARE ReturnValue : STRING
INT(100 / Number)
Count
Data[Number]
Index
CASE OF (Index MOD 2)
TO_UPPER(RIGHT(Label, Count))
0 : ReturnValue
"****"
1 : ReturnValue
ENDCASE
RETURN RetVal
ENDFUNCTION
(a) Run-time errors can be generated in different ways. For example, a run-time error will be
generated if a function is called with invalid parameters.
The pseudocode contains three statements that could generate a run-time error.
Write the three statements and explain how each could generate a run-time error.
Statement 1 …
Explanation …
…
Statement 2 …
Explanation …
…
Statement 3 …
Explanation …
…
[3]
ĬÑĊ¾Ġ´íÈõÏĪÅĊÝü·þ×
,
,
(b) One type of run-time error can cause a program to stop responding (‘freezing’).
Identify a particular type of programming construct that can generate this type of error and
explain why it occurs.
Construct …
Explanation …
…
…
[2]
(c) The function Process() contains a selection construct using a CASE structure.
Write pseudocode using a single selection construct with the same functionality without
using a CASE structure.
…
…
…
…
… [2]
ĬÓĊ¾Ġ´íÈõÏĪÅĊÝú·þ×
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()
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
Question text
7
A coffee shop runs a computerised loyalty card system.
Customers are issued with a loyalty card with their name together with a unique customer ID.
Loyalty points are added to their card each time they spend money at the shop.
The following information is stored for each customer: ID, name, home address, email address,
mobile phone number, date of birth, number of points, date of last visit and amount of money
spent at last visit.
A new module will generate a personalised email message to each loyalty card customer who has
not visited the coffee shop in the last three months. The message will include a unique voucher
code which can be used to authorise a discount if the customer goes to the shop within the next
two weeks.
(a) Identify three items of customer information that will be used by the new module and justify
your choices.
Item 1 …
Justification …
…
Item 2 …
Justification …
…
Item 3 …
Justification …
…
[3]
(b) Identify the computational thinking skill that you needed to use to answer part (a).
… [1]
(c) It is decided to adopt a formal program development life cycle model for the development of
the new module.
The analysis of the new module is complete and the project moves on to the design stage.
During this stage all the necessary algorithms and module designs will be defined.
State three other items that will be defined for the new module during the design stage.
1 …
2 …
3 …
[3]
ĬÏĊ¾Ġ´íÈõÏĪÅĊàû¶Ă×
,
,
(d) Part of the coffee shop program contains three program modules as follows:
•
Module Init() has no parameters and returns a Boolean.
•
Module Reset() takes a string as a parameter and returns an Integer.
•
Module Check() repeatedly calls Init() followed by Reset().
Draw a structure chart to represent the relationship between the three modules, including all
parameters and return values.
[3]
ĬÍĊ¾Ġ´íÈõÏĪÅĊÞù¶Ą×
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().
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…