Past paper – A Level Computer Science (old syllabus, to 2021) (9608)
Cambridge International AS & A Level · 9608
Computer Science (old syllabus, to 2021) · Paper 23
Oct/Nov 2021 · 9608/23/O/N/21
Answer on paper, open each mark scheme and give yourself marks, then open the Summary.
Question text
1
(a) An algorithm contains the following steps:
1.
prompt and input a product number
2.
validate the product number
3.
save the validated product number to FILE_A.txt
(i)
Write the pseudocode statement for step 1.
…
… [2]
(ii)
State the purpose of FILE_A.txt.
…
… [1]
(b) State two benefits of creating program flowcharts when documenting a program.
1 …
…
2 …
…
[2]
(c) Draw one line from each technical term to its appropriate description.
Technical term
Description
Stores data of the same data type
Corrective maintenance
in memory
Amends an algorithm following
Array
identification of errors
Amends an algorithm in response
Adaptive maintenance
to specification changes
Shows parameters passed between
Structure chart
program modules
[3]
(d) The following pseudocode procedure, SetupVars(), initialises the variables used to check
the status of a product.
PROCEDURE SetupVars()
"CONCRETE-SLAB"
Description
"ELY"
Destination
200
Mileage
1
EndOfYear
20000
Limit
FALSE
Overdue
ENDPROCEDURE
Complete the table by evaluating each pseudocode expression.
If the expression is invalid, write “ERROR” in the Evaluates to column.
Refer to the Appendix on pages 22–23 for a list of built-in pseudocode functions and
operators.
Pseudocode expression
Evaluates to
EndOfYear * Limit / Mileage
LENGTH(Description) / NUM_TO_STRING(Limit)
MOD(20, LENGTH(Destination))
(EndOfYear < 2) AND (Limit = 20000) AND NOT(Overdue)
MID(Description, 1, 5) & LEFT(Destination, 2)
& NUM_TO_STRING(Limit / 1000)
[5]
Question text
2
A company owns 50 cars that are available for hire. The cars are numbered from 1 to 50. The size
of a car can be small, medium, or large.
The following pseudocode procedure, SetOut(), takes as input the size of the car the customer
has requested for hire and outputs details of the cars that are available for hire for that size of car.
Line numbers are given for reference only.
Refer to the Appendix on pages 22–23 for a list of built-in pseudocode functions and operators.
01
DECLARE Available : ARRAY[1:50] OF BOOLEAN
02
DECLARE CarSize : ARRAY[1:50] OF STRING
03
04
PROCEDURE SetOut(Size: STRING)
05
DECLARE Index : REAL
06
0 TO 50
07
FOR Index
08
IF Size = CarSize[Index] AND Available[Index] = "TRUE"
09
THEN
10
OUTPUT NUM_TO_STRING(Index) & ": " & Size & " Available"
11
ENDIF
12
ENDFOR
13
14
ENDPROCEDURE
(a) Complete the table by identifying four line numbers that contain errors and give the correct
pseudocode statement.
Line number
Correct pseudocode statement
[4]
(b) Study the pseudocode algorithm on page 4.
Describe the algorithm using structured English.
Do not use pseudocode or program code in your answer.
…
…
…
…
…
…
…
… [4]
(c) The function PayUsingAccount() is required to process a payment for hiring a car as
follows:
1.
The function takes two parameters with REAL data type:
•
Balance is the amount of money in the account
•
CostOfHire is the cost of hiring the car.
2.
If CostOfHire exceeds Balance, the rental is not authorised and FALSE is returned,
otherwise TRUE is returned.
Write pseudocode for the function PayUsingAccount().
…
…
…
…
…
…
…
…
…
Question text
3
The function AddressChecker() checks if an email address is in the format:
<user>@<host> • <domain>
The design requirements of the function are:
•
The <user> contains only lower-case characters.
•
The <domain> contains exactly three alphabetic characters.
AddressChecker() will use three functions as described in the following table.
Function
Description
Split()
•
Takes two parameters:
•
a STRING value containing the email address
•
a BOOLEAN value representing the required return value
•
Returns two different values:
•
a STRING containing <user> if the BOOLEAN parameter
value is TRUE
•
a STRING containing <domain> if the BOOLEAN
parameter value is FALSE
IsLowerCase()
•
Takes an element of the email address as a STRING
parameter
•
Returns a BOOLEAN value of TRUE if the string contains only
lower-case characters, otherwise returns FALSE
IsThreeLetter()
•
Takes the domain as a STRING parameter
•
Returns a BOOLEAN value of TRUE if the string consists of
exactly three alphabetic characters, otherwise returns FALSE
AddressChecker() will:
•
prompt and input an email address
•
check that the email address is valid
•
return the string "Invalid" if the email address does not meet the design requirements,
otherwise return the email address.
(a) Draw a program flowchart to represent the algorithm for the AddressChecker() function.
Variable declarations are not required in program flowcharts.
[6]
(b) The function AddressChecker() is changed to check a list of email addresses stored in a
text file.
The function’s header is changed as follows:
FUNCTION AddressChecker(Filename : STRING, StartLine : INTEGER,
LastLine : INTEGER) RETURNS BOOLEAN
Assume that:
•
The function is called with a valid filename of the text file.
•
The text file exists and contains at least one email address.
•
Each email address is stored in a separate line in the text file.
•
The function does not contain logical errors.
Give two reasons why the function may return an unexpected result.
Reason 1 …
…
Reason 2 …
…
[2]
(c) (i)
Explain what is meant by the term syntax error.
…
…
…
… [2]
(ii)
Give an example of a syntax error in program code.
Programming language …
Program code
…
…
…
… [1]
(d) The following
Question text
4
The following pseudocode contains a function that searches a text file for the string contained in
the parameter Match.
01 DECLARE MatchItems : ARRAY[1:100] OF STRING
10 FUNCTION Extract(FileName : STRING, Match : STRING,
Signal : INTEGER) RETURNS BOOLEAN
11
12
DECLARE FileLine : INTEGER
13
DECLARE Counter : INTEGER
14
DECLARE FileData, SubMatch : STRING
15
DECLARE Result : BOOLEAN
16
0
17
Counter
1
18
FileLine
FALSE
19
Result
20
21
OPENFILE FileName FOR READ
22
23
WHILE NOT EOF(FileName) AND FileLine <= 100
24
READFILE FileName, FileData
LEFT(FileData, LENGTH(Match))
25
SubMatch
26
IF SubMatch = Match
27
THEN
FileData
28
MatchItems[Counter]
Counter + 1
29
Counter
30
ENDIF
FileLine + 1
31
FileLine
32
ENDWHILE
33
34
CLOSEFILE FileName
35
IF Counter >= Signal
36
THEN
TRUE
37
Result
38
ENDIF
39
RETURN Result
40
41 ENDFUNCTION
(a) Complete the trace table when the function is called using this statement:
Extract("DATA.txt", "TG12367", 1)
Present
You may assume that the text file DATA.txt contains the following lines:
"XD43668#23/11/19#DSCP"
"TG12367#24/01/19#MAHA"
"HD44356#24/11/19#MAHA"
"TG12367#24/11/19#GHFI"
FileLine
Counter
LEFT(FileData,
SubMatch = Match
Result
LENGTH(Match))
[5]
(b) The function is changed as follows:
•
The statement on line 25 is changed to compare the last ten characters of FileData
and the parameter Match.
If the comparison is successful:
•
store the first seven characters of FileData in a global 1D array called Original
•
store the last four characters of FileData in a global 1D array called Backup
•
The count of the number of items stored in the array Backup is returned.
(i)
Rewrite the function header in pseudocode so that it meets the new requirements.
…
…
…
… [2]
(ii)
Rewrite the WHILE structure in pseudocode so that it meets the new requirements. The
WHILE structure is given here for reference.
23
WHILE NOT EOF(FileName) AND FileLine <= 100
24
READFILE FileName, FileData
LEFT(FileData, LENGTH(Match))
25
SubMatch
26
IF SubMatch = Match
27
THEN
FileData
28
MatchItems[Counter]
Counter + 1
29
Counter
30
ENDIF
FileLine + 1
31
FileLine
32
ENDWHILE
…
…
…
…
…
…
…
…
…
…
Question text
5
A geocode string contains four alphanumeric characters, followed by the character '+' and then
two alphanumeric characters.
For example, the geocode string for the Avocado Restaurant in Cambridge UK is:
"1DFG+9N"
A website allows a user to upload a review of a restaurant.
A programmer has defined the following two arrays:
Array
Description
GeoData
•
a global 1D array of data type STRING
•
stores the geocode for each restaurant
Example:
"1DFG+9N"
GeoData[1]
Review
•
a global 1D array of data type STRING
•
stores the following data items as a single element in the array:
•
the four-character user ID of the reviewer
•
the geocode of the restaurant
•
the text of the review
•
the hash symbol (#) separates the data items in each single element
Example of a review for the Avocado restaurant submitted by user ID JH76:
"JH76#1DFG+9N#Good restaurant"
Review[1000]
Assume that:
•
both arrays are initialised with an empty string
•
both arrays can store up to 20 000 elements
•
new reviews are added in the next unused element of the Review array.
(a) The programmer writes a function CheckReview().
The design requirements of the function are shown in the following table:
Description
Parameter
Returns
•
•
•
searches the
a STRING value
the comment from the review
GeoData array to
containing the
if the geocode exists in the
determine if the user’s
user ID of the
GeoData array
latest review contains
reviewer
•
a STRING value of "LOCATION
a listed geocode
NOT FOUND" if the geocode of
the user’s review does not exist
in the GeoData array
•
a STRING value of "NO
REVIEW" if no review exists for
the user ID
Write pseudocode to complete the function CheckReview().
DECLARE GeoData : ARRAY[1:20000] OF STRING
DECLARE Review : ARRAY[1:20000] OF STRING
FUNCTION CheckReview(UserID : STRING) RETURNS STRING
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…