Past paper – A Level Computer Science (9618)
Cambridge International AS & A Level · 9618
Computer Science · Paper 21
May/June 2024 · 9618/21/M/J/24
Answer on paper, open each mark scheme and give yourself marks, then open the Summary.
Question text
1
An algorithm is developed in pseudocode before being coded in a programming language.
(a) The following table shows four valid pseudocode assignment statements.
Complete the table by giving an appropriate data type to declare each of the variables A, B, C
and D.
Assignment statement
Data type
A
LEFT(MyName, 1)
Total * 2
B
INT(ItemCost) / 3
C
"Odd OR Even"
D
[4]
(b) Other variables in the program have example values as shown:
Variable
Value
Sorted
False
Tries
9
ID
"ZGAC001"
Complete the table by evaluating each expression, using the example values.
Expression
Evaluates to
Tries < 10 AND NOT Sorted
Tries MOD 4
TO_LOWER(MID(ID, 3, 1))
LENGTH(ID & "xx") >= Tries
[4]
(c) The variable names A, B, C and D in part (a) are not good programming practice.
(i)
State why these variable names are not suitable.
…
… [1]
(ii)
Identify one problem that these variable names might cause.
…
… [1]
(iii)
The choice of suitable variable names is one example of good programming practice.
Give one other example.
…
… [1]
Question text
2
An algorithm has three steps. It will:
repeatedly input a pair of numeric values A and B
1.
count the number of pairs that are input until A has been greater than B 10 times
2.
3.
output the number of pairs that were input.
(a) Complete the program flowchart.
START
INPUT A, B
Yes
No
END
[5]
(b) Step 1 of the algorithm is changed.
A variable ThisSequence is used to enter a sequence of 10 pairs of numeric values, using
a single input statement.
Following the input of ThisSequence the revised algorithm will extract the pairs of numbers.
Describe the variable ThisSequence and how the numbers are extracted.
…
…
…
… [2]
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]
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]
Question text
5
A global 1D array of strings contains three elements which are assigned values as shown:
"aaaaaa"
Data[1]
"bbbbbb"
Data[2]
"cccccc"
Data[3]
Procedure Process() manipulates the values in the array.
The procedure is written in pseudocode as follows:
PROCEDURE Process(Format : STRING)
DECLARE Count, Index, L : INTEGER
DECLARE Result : STRING
DECLARE C : CHAR
"****"
Result
1 TO LENGTH(Format) STEP 2
FOR Count
MID(Format, Count, 1)
C
STR_TO_NUM(MID(Format, Count + 1, 1))
L
(Count + 1) DIV 2
Index
CASE OF C
TO_UPPER(Data[Index])
'X' : Result
TO_LOWER(Data[Index])
'Y' : Result
"**" & Data[Index]
'Z' : Result
ENDCASE
LEFT(Result, L)
Data[Index]
NEXT Count
ENDPROCEDURE
(a) Complete the trace table by dry running the procedure when it is called as follows:
CALL Process("X3Y2W4")
Count
C
L
Index
Result
Data[1]
Data[2]
Data[3]
[6]
(b) The procedure is to be modified. If variable C is assigned a value other than 'X', 'Y' or 'Z',
then procedure Error() is called and passed the value of variable C as a parameter.
This modification can be implemented by adding a single line of pseudocode.
(i)
Write the single line of pseudocode.
… [1]
(ii)
State where this new line should be placed.
… [1]
Question text
6
Three points on a grid form a triangle with sides of length A, B and C as shown in the example:
y
10
9
8
7
6
5
C
B
4
3
A
2
1
x
0
1
2
3
4
5
6
7
8
9 10
A triangle is said to be right-angled if the following test is true (where A is the length of the longest
side):
A 2 = B 2 + C 2
A 2 means A multiplied by A, for example 3 2 means 3 × 3 which evaluates to 9
You can calculate A 2 , B 2 and C 2 by using the coordinates of the endpoints of each line.
For example, B 2 is calculated as follows:
y
10
9
8
7
P2
6
(x 2 , y 2 )
5
B
4
3
P1
2
(x 1 , y 1 )
1
x
0
1
2
3
4
5
6
7
8
9 10
The endpoints, P1 and P2, have the coordinates (3, 2) and (6, 6).
The value B 2 is given by the formula:
B 2 = (x 1 − x 2 ) 2 + (y 1 − y 2 ) 2
In this example:
B 2 = (3 − 6) 2 + (2 − 6) 2
B 2 = (–3) 2 + (–4) 2
B 2 = 9 + 16
B 2 = 25
(a) A function IsRA() will:
•
take three sets of integers as parameters representing the coordinates of the three
endpoints that form a triangle
•
return TRUE if the endpoints form a right-angled triangle, otherwise return FALSE.
In pseudocode, the operator ‘^’ represents an exponent, which is the number of times a value
is multiplied by itself. For example, the expression Value 2 may be written in pseudocode as
Value ^ 2
Complete the pseudocode for the function IsRA().
FUNCTION IsRA(x1, y1, x2, y2, x3, y3 : INTEGER) RETURNS BOOLEAN
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
ENDFUNCTION
[6]
(b) The test used to check if a triangle is right-angled can be written in two ways:
A 2 = B 2 + C 2
or
A = √(B 2 + C 2 )
The symbol √ represents the square root operation. For example, √81 = 9
A new function SQRT() is written t
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
…
Question text
8
A teacher is designing a program to process pseudocode projects written by her students.
Each student project is stored in a text file.
The process is split into a number of stages. Each stage performs a different task and creates a
new file named as shown:
File name
Comment
MichaelAday_src.txt
student project file produced by student Michael Aday
MichaelAday_S1.txt
file produced by stage 1
MichaelAday_S2.txt
file produced by stage 2
The teacher has defined the first program module as follows:
Module
Description
DeleteComment()
• called with a parameter of type string representing a line of
pseudocode from a student’s project file
• returns the line after removing any comments
Note on comments:
A comment starts with two forward slash characters and includes all the
remaining characters on the line.
The following example shows a string before and after the comment has
been removed:
Before: IF X2 > 13 THEN
//check if limit exceeded
After: IF X2 > 13 THEN
(a) Complete the pseudocode for module DeleteComment().
FUNCTION DeleteComment(Line : STRING) RETURNS STRING
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…