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
Oct/Nov 2019 · 9608/21/O/N/19
Answer on paper, open each mark scheme and give yourself marks, then open the Summary.
Question text
1
Study the following pseudocode.
FUNCTION Search() RETURNS INTEGER
DECLARE N, C : INTEGER
DECLARE V, L : REAL
GetLevel()
V
V * 1.34
L
0
C
1 TO 10
FOR N
GetLevel()
V
IF V > L
THEN
C + 1
C
ENDIF
ENDFOR
OUTPUT "Process complete"
RETURN C
ENDFUNCTION
(a) (i)
This pseudocode lacks features that would make it easier to read and understand.
State three such features.
Feature 1 …
Feature 2 …
Feature 3 …
[3]
(ii)
Draw a program flowchart to represent the algorithm implemented in the pseudocode.
Variable declarations are not required in program flowcharts.
[5]
(b) (i)
Programming languages support different data types.
Complete the table by giving a suitable data type for each example value.
Example value
Data type
"NOT TRUE"
− 4.5
NOT FALSE
132
[4]
(ii)
Evaluate each expression in the following table.
If an expression is invalid then write ‘ERROR’.
Refer to the Appendix on page 16–17 for the list of built-in functions and operators.
Expression
Evaluates to
LEFT("Start", 3) & RIGHT("Apple", 3)
MID("sample", 3, 5)
NUM_TO_STRING(12.3 * 2)
INT(STRING_TO_NUM("53.4")) + 7
[4]
Question text
2
(a) A structure chart is often used in modular program design. One feature shown is the sequence
of module execution.
State four other features that may be shown.
Feature 1 …
…
Feature 2 …
…
Feature 3 …
…
Feature 4 …
…
[4]
(b) Identify and describe one feature of an Integrated Development Environment (IDE) that can
help with program presentation.
Feature …
Description …
…
[2]
(c) By value is one method of passing a parameter to a subroutine.
Identify and describe the other method.
Method …
Description …
…
…
[2]
(d) Explain the term adaptive maintenance.
…
…
…
… [2]
Question text
3
The following is a function design in pseudocode.
Line numbers are given for reference only.
10 FUNCTION Check(InString : STRING) RETURNS BOOLEAN
11
12
DECLARE NumDots : INTEGER
13
DECLARE Index : INTEGER
14
DECLARE NumOthers : INTEGER
15
0
16
NumDots
0
17
NumOthers
1
18
Index
19
20
WHILE NumDots < 3 AND Index <= LENGTH(InString)
21
22
IF MID(InString, Index, 1) = '.'
23
THEN
NumDots + 1
24
NumDots
25
ELSE
NumOthers + 1
26
NumOthers
27
ENDIF
Index + 1
28
Index
29
30
ENDWHILE
31
32
IF NumDots = NumOthers
33
THEN
34
RETURN TRUE
35
ELSE
36
RETURN FALSE
37
ENDIF
38
39 ENDFUNCTION
Study the pseudocode. Identify the relevant features in the following table.
Refer to the Appendix on pages 16–17 for the list of built-in functions and operators.
Feature
Answer
The number of the line containing a variable being incremented
The range of line numbers containing a pre-condition loop
The number of initialisation statements
The number of the line containing a logical operator
The range of line numbers containing a selection statement
The name of a built-in function
The name of a parameter
[7]
Question text
4
A student is developing a program to count how many times each character of the alphabet (A to Z)
occurs in a given string. Upper case and lower case characters will be counted as the same. The
string may contain non-alphabetic characters, which should be ignored.
The program will:
•
check each character in the string to count how many times each alphabetic character occurs
•
store the count for each alphabetic character in a 1D array
•
output each count together with the corresponding character.
(a) The student has written a structured English description of the algorithm:
1.
START at the beginning of the string
2.
SELECT a character from the string
3.
CONVERT the character to upper case
4.
CHECK whether the character is alphabetic and INCREMENT as required.
5.
REPEAT from step 2 until last character has been checked
6.
OUTPUT a suitable message giving the count of each alphabetic character
Step 4 above is not described in sufficient detail.
The student decides to apply a process to increase the level of detail given in step 4.
State the name of the process and use this process to write step 4 in more detail. Use
structured English for your answer.
Process …
Structured English …
…
…
…
…
…
[4]
(b) Write pseudocode to implement the program.
You should note the following:
•
InString contains the string to be checked. It has been assigned a value.
•
The elements of the array Result have all been initialised to zero.
•
The ASCII value of letter ‘A’ is 65.
You should assume the following lines of pseudocode have been written:
DECLARE InString : STRING
DECLARE Result : ARRAY [1:26] OF INTEGER
Declare any further variables you use. Do not implement the code as a subroutine.
Refer to the Appendix on pages 16–17 for the list of built-in functions and operators.
…
…
…
…
…
…
…
…
…
Question text
5
The following pseudocode checks whether a string is a valid password.
FUNCTION CheckPassword(InString : STRING) RETURNS BOOLEAN
DECLARE Index, Upper, Lower, Digit, Other : INTEGER
DECLARE NextChar : CHAR
Upper
0
Lower
0
Digit
0
Other
0
FOR Index
1 TO LENGTH(InString)
NextChar
MID(InString, Index, 1)
IF NextChar >= 'A' AND NextChar <= 'Z'
THEN
Upper
Upper + 1
ELSE
IF NextChar >= 'a' AND NextChar <= 'z'
THEN
Lower
Lower + 1
ELSE
IF NextChar >= '0' AND NextChar <= '9'
THEN
Digit
Digit + 1
ELSE
Other
Other + 1
ENDIF
ENDIF
ENDIF
ENDFOR
IF Upper > 1 AND Lower >= 5 AND (Digit - Other) > 0
THEN
RETURN TRUE
ELSE
RETURN FALSE
ENDIF
ENDFUNCTION
(a) Describe the validation rules that are implemented by this pseudocode. Refer only to the
contents of the string and not to features of the pseudocode.
…
…
…
…
…
… [3]
(b) (i)
Complete the trace table by dry running the function when it is called as follows:
CheckPassword("Jim+Smith*99")
Result
Index
NextChar
Upper
Lower
Digit
Other
[5]
(ii)
State the value returned when the function is called using the expression shown. Justify
your answer.
Value …
Justification …
…
…
[2]
Question text
6
Account information for users of a library is held in one of two text files; UserListAtoM.txt and
UserListNtoZ.txt
The format of the data held in the two files is identical. Each line of the file is stored as a string that
contains an account number, name and telephone number separated by the asterisk character
('*') as follows:
<Account Number>'*'<Name>'*'<Telephone Number>
An example of one line from the file is:
"GB1234*Kevin Mapunga*07789123456"
The account number string may be six or nine characters in length and is unique for each
person. It is made up of alphabetic and numeric characters only.
An error has occurred and the same account number has been given to different users in the two
files. There is no duplication of account numbers within each individual file.
A program is to be written to search the two files and to identify duplicate entries. The account
number of any duplicate found is to be written to an array, Duplicates, which is a 1D array of
100 elements of data type STRING.
The program is to be implemented as several modules. The outline description of three of these is
as follows:
Module
Outline description
•
Initialise the global array Duplicates. Set all elements to the
ClearArray()
empty string.
•
Read each line from the file UserListAtoM.txt
Check whether the account number appears in file
•
UserListNtoZ.txt using SearchFileNtoZ()
FindDuplicates()
If the account number does appear then add the account
•
number to the array.
•
Output an error message and exit the module if there are more
duplicates than can be written to the array.
•
Search for a given account number in file UserListNtoZ.txt
SearchFileNtoZ()
If found, return TRUE, otherwise return FALSE
•
(a) State one reason for storing data in a file rather than in an array.
…
… [1]
(b) Write program code for the module SearchFileNtoZ().
Visual Basic and Pascal: You should include the declaration statements for variables.
Python: You should show a comment statement for each variable used with its data type.
Programming language …
Program code
…
…
…
…
…
…
…
…
…
…
…