Past paper – A Level Computer Science (old syllabus, to 2021) (9608)
Cambridge International AS & A Level · 9608
Computer Science (old syllabus, to 2021) · Paper 21
May/June 2020 · 9608/21/M/J/20
Answer on paper, open each mark scheme and give yourself marks, then open the Summary.
Question text
1
(a) Complete this definition of the term algorithm.
An algorithm is a solution to a problem expressed as …
…
… [2]
(b) A program design includes the use of subroutines (functions and procedures).
Give three advantages of using subroutines in a program.
1 …
…
2 …
…
3 …
…
[3]
(c) Draw lines on the following diagram to connect each computing term with the appropriate
description.
Term
Description
Checking that a program
Selection
performs as expected
A method for increasing the
Black-box testing
level of detail of an algorithm
To test a condition to determine
Stepwise refinement
the path of program execution
A method of executing certain
Iteration
lines of code more than once
[3]
Question text
2
(a) Three modules form part of a program for a car rental company. A description of the
relationship between the modules is summarised as follows:
Module name
Description
A customer will pay for each car rental either by bank card or by using their
RentCar()
account with the rental company.
Called with parameter HireCost, representing the cost of the rental.
PayByCard()
Returns a BOOLEAN value to indicate whether or not the card payment was
successful.
Called with parameters HireCost, AccountNumber, CurrentBalance
and AccountLimit.
•
Checks whether HireCost plus the CurrentBalance would exceed
PayByAccount()
the AccountLimit. If so, then the rental is not authorised.
•
If the rental is authorised, then the CurrentBalance is updated.
•
Returns a BOOLEAN value to indicate whether or not the rental was
authorised.
Draw a structure chart to show the relationship between the three modules and the
parameters passed between them.
[5]
(b) The following pseudocode algorithm has been developed to check whether a string contains
a valid password.
To be a valid password, a string must:
•
be longer than 6 characters
•
contain at least one lower case letter
•
contain at least one upper case letter
•
contain at least one non-alphabetic character.
10 FUNCTION Check(InString : STRING) RETURNS BOOLEAN
11
12
DECLARE Index : INTEGER
13
DECLARE StrLen : INTEGER
14
DECLARE NumUpper, NumLower : INTEGER
15
DECLARE NumNonAlpha : INTEGER
16
DECLARE NextChar : CHAR
17
0
18
NumUpper
0
19
NumLower
0
20
NumNonAlpha
21
LENGTH(InString)
22
StrLen
23
IF StrLen < 7
24
THEN
25
RETURN FALSE
26
ELSE
1 TO StrLen
27
FOR Index
MID(InString, Index, 1)
28
NextChar
29
IF NextChar >= 'a' AND NextChar <= 'z'
30
THEN
NumLower + 1
31
NumLower
32
ELSE
33
IF NextChar > 'A' AND NextChar <= 'Z'
34
THEN
NumUpper + 1
35
NumUpper
36
ELSE
NumNonAlpha + 1
37
NumNonAlpha
38
ENDIF
39
ENDIF
40
ENDFOR
41
ENDIF
42
43
IF (NumUpper >= 1) AND (NumLower >= 1) AND (NumNonAlpha >= 1)
44
THEN
45
RETURN TRUE
46
ELSE
47
RETURN FALSE
48
ENDIF
49
50 ENDFUNCTION
Refer to the Appendix on page 21 for a list of built-in pseudocode functions and operators.
The pseudocode does not work under all circumstances.
A dry run performed on the function Check(), with the string "crAsh99", produced the
following trace table.
The string is a valid password, but the pseudocode would return the value FALSE.
Trace
StrLen
Index
NextChar
NumUpper
NumLower
NumNonAlpha
table row
7
0
0
0
1
1
'c'
2
1
3
2
'r'
4
2
5
3
'A'
6
1
7
4
's'
8
3
9
5
'h'
10
4
11
6
'9'
12
2
13
7
'9'
14
3
15
(i)
Describe how the completed trace table may be used to identify the error in the
pseudocode. In your answer, refer to the trace table row number(s).
…
…
…
…
… [2]
(ii)
State the pseudocode line number that has to be changed to correct the error and write
the correct pseudocode for the complete line.
Line number …
Correct pseudocode …
…
[2]
(iii)
Rewrite
Question text
3
(a) A mobile phone provider has developed an account management program. The program
includes a procedure, AddCredit(). The procedure is called with two parameters, TopUp
and PhoneNum.
The relevant part of the identifier table and the program flowchart for the procedure are as
shown:
Identifier
Type
Description
TopUp
REAL
The amount of credit to be added
PhoneNum
STRING
The unique customer phone number
Balance
REAL
The current amount of credit
Multiple
REAL
The amount of credit bonus
Takes the phone number as a parameter and returns the current
GetBalance()
FUNCTION
balance
Takes the phone number and the new balance as parameters and
SetBalance()
PROCEDURE
updates the account with the new balance
START
Set Multiple
to 1
Set Balance to
GetBalance(PhoneNum)
Is
YES
Set Multiple to
Balance > 10 ?
1.25
NO
Is
YES
Set Multiple to
Balance > 5 ?
1.1
NO
Set TopUp to
TopUp * Multiple
SetBalance(PhoneNum, Balance + TopUp)
END
Write pseudocode to implement the procedure AddCredit(). The pseudocode must follow
the algorithm represented by the flowchart. Declare any local variables used.
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
Question text
4
(a) An inexperienced user buys a games program. A program fault occurs while the user is
playing the game.
Explain what is meant by a program fault.
…
…
…
…
…
…
… [2]
(b) Give three ways to minimise the risk of faults when writing programs.
1 …
…
2 …
…
3 …
… [3]
(c) Three types of program error are syntax, logic and run-time.
Define these three types.
Syntax error …
…
…
Logic error …
…
…
Run-time error …
…
…
[3]
Question 5 begins on the next page.
Question text
5
(a) A 1D array, Directory, of type STRING is used to store a list of school internal telephone
numbers. There are 1000 elements in the array. Each element stores a single data item. The
format of each data item is as follows:
<Number><Name>
Number is a four-digit numeric string.
Name is a variable-length string.
For example:
"1024Collins Robbie"
The following pseudocode is an initial attempt at defining a procedure SortContacts()
that will perform a bubble sort on Directory. The array is to be sorted in ascending order of
Name.
Fill in the gaps to complete the pseudocode.
Refer to the Appendix on page 21 for a list of built-in pseudocode functions and operators.
PROCEDURE SortContacts ()
DECLARE Temp : STRING
DECLARE FirstName, SecondName : STRING
DECLARE NoSwaps : …
DECLARE Boundary, J : INTEGER
…
Boundary
REPEAT
TRUE
NoSwaps
1 TO Boundary
FOR J
… (Directory[J], LENGTH(Directory[J]) – … )
FirstName
RIGHT(Directory[J + 1], LENGTH(Directory[J + 1]) – 4)
SecondName
IF FirstName …
THEN
Directory[J]
Temp
Directory …
Directory[J]
Temp
Directory[J + 1]
…
NoSwaps
ENDIF
ENDFOR
…
Boundary
UNTIL NoSwaps = TRUE
ENDPROCEDURE
[8]
(b) The pseudocode contains a mechanism designed to make this an efficient bubble sort.
Describe the mechanism and explain why it may be considered to be efficient.
…
…
…
…
…
…
…
…
…
… [4]
Question text
6
A company hires out rowing boats on a lake. The company has ten boats, numbered from 1 to 10.
The company is developing a program to help manage and record the hiring out process.
Hire information is stored in three global 1D arrays when a boat is hired out. Each array contains
10 elements representing each of the ten boats.
The three 1D arrays are summarised as follows:
Array
Data type
Description
Example data value
HireTime
STRING
"10:15"
The time the boat was hired out
Duration
INTEGER
30
The number of minutes of the hire
Cost
REAL
5.75
The cost of the hire
If an individual boat is not currently on hire, the corresponding element of the HireTime array will
be set to "Available".
The programmer has started to define program modules as follows:
Module
Description
•
Called with two parameters:
o a STRING value representing a time
AddTime()
o an INTEGER value representing a duration in minutes
•
Adds the duration to the time to give a new time
•
Returns the new time as a STRING
•
Called with a STRING value representing the time the
hire will start
•
Outputs the boat numbers that will be available for hire at
the given start time. A boat will be available for hire if it is
either:
ListAvailable()
o currently not on hire, or
o due back before the given hire start time
•
Outputs the number of each boat available
•
Outputs the total number of boats available or a suitable
message if there are none
•
Called with four parameters:
o an INTEGER value representing the boat number
o a STRING value representing the hire start time
o an INTEGER value representing the hire duration in
minutes
o a REAL value representing the cost of hire
RecordHire()
•
Updates the appropriate element in each array
•
Adds the cost of hire to the global variable DailyTakings
•
Converts the four input parameters to strings,
concatenated using commas as separators, and writes
the resulting string to the end of the existing text file
HireLog.txt
(a) Write pseudocode for the module ListAvailable().
…
…
…
…
…
…
…
…
…
…
…
…
…
…