Programming – A Level Computer Science (9618)

153 questions · page 5 of 11 · Clear filters

0 / 0Answer a question to start your score.
Quick quiz (10)Saved 0
Advertisement
61
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)
…
…
…
…
…
…
…
…
…
…
…
…
…
…

62
9618/21/M/J/24 · Question 1May/June 2024Paper 2111 marks
Loading question…
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]

63
9618/21/M/J/24 · Question 5May/June 2024Paper 2120 marks
Loading question…
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]

Advertisement
64
9618/21/M/J/24 · Question 6May/June 2024Paper 218 marks
Loading question…
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

65
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
…

66
9618/21/M/J/24 · Question 8May/June 2024Paper 2115 marks
Loading question…
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
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…

67
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]

68
9618/22/M/J/24 · Question 4May/June 2024Paper 225 marks
Loading question…
Question text

4
A triangle has sides of length A, B and C.
C
B
A
In this example, A is the length of the longest side.
This triangle is said to be right‑angled if the following equation is true:
A × A = (B × B) + (C × C)
A procedure will be written to check whether three lengths represent a right‑angled triangle.
The lengths will be input in any sequence.
The procedure IsRA() will:
•
prompt and input three integer values representing the three lengths
•
test whether the three lengths correspond to the sides of a right‑angled triangle
•
output a suitable message.
The length of the longest side may not be the first value input.
Write pseudocode for the procedure IsRA().
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…

Advertisement
69
9618/22/M/J/24 · Question 5May/June 2024Paper 226 marks
Loading question…
Question text

5
A program is being designed in pseudocode.
The program contains a global 1D array Data of type string containing 200 elements.
The first element has the index value 1.
A procedure Process() is written to initialise the values in the array:
PROCEDURE Process(Label : STRING)
DECLARE Index : INTEGER
0
Index
INPUT Data[Index]
WHILE Index < 200
Index + 1
Index
CASE OF (Index MOD 2)
TO_UPPER(Label)
0 : Data[Index]
TO_LOWER(Label)
1 : Data[Index]
OTHERWISE : OUTPUT "Alarm 1201"
ENDCASE
NEXT Index
OUTPUT "Completed " & Index & " times"
ENDPROCEDURE
(a) (i)
The pseudocode contains two syntax errors and one other error.
Identify the errors.
Syntax error 1 …
…
Syntax error 2 …
…
Other error …
…
[3]
(ii)
The procedure contains a statement that is not needed.
Identify the pseudocode statement and explain why it is not needed.
Statement …
Explanation …
…
[2]
(b) After correcting all syntax errors, the pseudocode is translated into program code which
compiles without generating any errors.
When the program is executed it unexpectedly stops responding.
Identify the type of error that has occurred.
… [1]

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

6
A music player stores music in a digital form and has a display which shows the track being
played.
(a) Up to 16 characters can be displayed. Track titles longer than 16 characters will need to be
trimmed as follows:
•
Words must be removed from the end of the track title until the resulting title is less than
14 characters.
•
When a word is removed, the space in front of that word is also removed.
•
Three dots are added to the end of the last word displayed when one or more words
have been removed.
The table below shows some examples:
Original title
Display string
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
B
a
t
o
u
t
o
f
H
u
l
l
Bat out of Hull
B
o
h
e
m
i
a
n
.
.
.
Bohemian Symphony
P
a
p
e
r
b
o
o
k
W
r
i
t
e
r
Paperbook Writer
C
h
r
i
s
S
i
n
g
s
.
.
.
Chris Sings the Blues
G
r
e
e
n
H
o
m
e
.
.
.
Green Home Alabama
A function Trim() will:
•
take a string representing the original title
•
return the string to be displayed.
Assume:
•
Words in the original title are separated by a single space character.
•
There are no spaces before the first word or after the last word of the original title.
•
The first word of the original title is less than 14 characters.
Write pseudocode for the function Trim().
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…

71
9618/22/M/J/24 · Question 7May/June 2024Paper 229 marks
Loading question…
Question text

7
A fitness club has a computerised membership system.
The system stores information for each club member: name, home address, email address, mobile
phone number, date of birth and exercise preferences.
Many classes are full, and the club creates a waiting list for each class. The club adds details of
members who want to join a class that is full to the waiting list for that class.
When the system identifies that a space is available in one of the classes, a new module will send
a text message to each member who is on the waiting list.
(a) Decomposition will be used to break the new module into sub‑modules (sub‑problems).
Identify three sub‑modules that could be used in the design and describe their use.
Sub‑module 1 …
Use …
…
…
…
Sub‑module 2 …
Use …
…
…
…
Sub‑module 3 …
Use …
…
…
…
[3]
(b) A different part of the program is represented by the following state‑transition diagram.
Input-B | Output-W
Input-B
Input-B
START
S1
S3
S2
S5
Input-A
Input-A
Input-A | Output-W
Input-B | Output-Y
Input-A | Output-X
S4
(i)
Complete the table to show the inputs, outputs and next states.
Assume that the current state for each row is given by the ‘Next state’ on the previous
row. For example, the first Input‑A is made when in state S1.
If there is no output for a given transition, then the output cell should contain ‘none’.
The first two rows have been completed.
Input
Output
Next state
S1
Input‑A
none
S3
Output‑W
none
Input‑B
Input‑A
S4
[5]
(ii)
Identify the input sequence that will cause the minimum number of state changes in the
transition from S1 to S4.
… [1]

72
9618/22/M/J/24 · Question 8May/June 2024Paper 2216 marks
Loading question…
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.
For example:
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
(a) Suggest a reason why the teacher’s program has been split into a number of stages and give
the benefit of producing a different file from each stage.
Reason …
…
Benefit …
…
[2]
(b) The teacher has defined the first program module as follows:
Module
Description
DeleteSpaces()
• called with a parameter of type string representing a line of
pseudocode from a student’s project file
• returns the line after removing any leading space characters
The following example shows a string before and after the leading
spaces have been removed:
Before: "
IF X2 > 13 THEN"
After: "IF X2 > 13 THEN"
Complete the pseudocode for module DeleteSpaces().
FUNCTION DeleteSpaces(Line : STRING) RETURNS STRING
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…

73
9618/23/M/J/24 · Question 1May/June 2024Paper 239 marks
Loading question…
Question text

1
A program uses many complex algorithms.
One algorithm is repeated in several places. The code for the algorithm is the same wherever it is
used, but the calculations within the algorithm may operate on different data.
The result of each calculation is used by the code that follows it.
It is decided to modify the program and implement the algorithm as a separate module.
(a) (i)
State two benefits of this modification to the existing program.
1 …
…
2 …
…
[2]
(ii)
Describe how the modification would be implemented.
…
…
…
…
…
…
…
… [3]
,
,
(b) Four of the expressions used in the program are represented by pseudocode in the table.
Complete each pseudocode expression with a function or operator so that it evaluates to the
value shown.
Any functions and operators used must be defined in the insert.
Pseudocode expression
Evaluates to
"and"
… ("Random", 2, 3)
15
5 + … (10/11/2023)
TRUE
… ("45000")
3
(20 … 3) + 1
[4]

Advertisement
74
9618/23/M/J/24 · Question 4May/June 2024Paper 2311 marks
Loading question…
Question text

4
A procedure TwoParts() will input a sequence of real values, one at a time.
The procedure will:
•
process the sequence in two parts
•
form a first total by adding the values until the first zero
•
form a second total by adding the values after the first zero until the second zero
•
output the average of the two totals, together with a suitable message.
Values input in the first part are totalled using global variable TotalA and those input in the
second part are totalled using global variable TotalB.
(a) Write pseudocode for the procedure TwoParts().
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
… [6]
,
,
(b) The value zero denotes the split between the two parts of the sequence.
The requirement changes and now there may be up to 20 parts.
(i)
Identify a suitable data structure that could be used to store the different total values.
…

75
9618/23/M/J/24 · Question 5May/June 2024Paper 236 marks
Loading question…
Question text

5
A program is being designed in pseudocode.
The program contains the following declaration:
DECLARE Data : ARRAY[1:1000] OF STRING
A procedure ArrayInitialise() is written to initialise the values in the array:
PROCEDURE ArrayInitialise(Label : STRING)
DECLARE Index : INTEGER
1
Index
WHILE Index <= 1000
CASE OF (Index MOD 2)
FormatA(Label)
0 : Data[Index]
Index + 1
Index
FormatB(Label)
1 : Data[Index]
Index + 1
Index
ENDCASE
ENDWHILE
ENDPROCEDURE
Functions FormatA() and FormatB() apply fixed format case changes to the parameter string.
(a) The design of the procedure does not use the most appropriate loop construct.
Suggest a more appropriate construct that could be used and explain your choice.
Construct …
Explanation …
…
[2]
(b) The algorithm calls one of the functions FormatA() and FormatB() each time within the
loop.
Explain why this is not efficient and suggest a more efficient solution.
…
…
…
…
…
…
…
… [4]

Advertisement