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 2020 · 9608/21/O/N/20
Answer on paper, open each mark scheme and give yourself marks, then open the Summary.
Question text
1
(a) Translation is one stage of the program development cycle.
State three other stages.
1 …
2 …
3 …
[3]
(b) Define the following types of maintenance.
Corrective maintenance …
…
…
Adaptive maintenance …
…
…
[2]
(c) Experienced programmers have a transferable skill.
Explain how this skill might be useful for a programmer.
…
…
…
… [2]
(d) Jackie has written a program and has used the identifier names I1, I2, and I3.
Explain why this is not good practice.
…
…
…
… [2]
(e) A pseudocode algorithm assigns values to three variables as follows:
FALSE
GateOpen
Alarm
TRUE
PowerFail
TRUE
Evaluate the expressions given in the following table:
Expression
Evaluates to
Alarm OR NOT PowerFail
NOT (Alarm AND PowerFail)
(GateOpen OR Alarm) AND PowerFail
(GateOpen AND Alarm) OR NOT PowerFail
[2]
Question text
2
(a) User names are stored in a text file. Each line of the file represents one name. Before a new
user name can be issued, a check has to be made to ensure that the new name is unique.
Use structured English to describe an algorithm that would prompt and input a new user
name and output a message to indicate whether or not it is unique.
…
…
…
…
…
…
…
…
…
…
…
…
…
…
… [6]
(b) Complete the pseudocode expressions in the following table.
Use only the functions and operators described in the Appendix on pages 18–19.
Expression
Evaluates to
"Start"
… ("Stepwise" , … ) & "art"
"ten"
… ("Concatenate" , … , … )
12
2 * … ("Kipper")
TRUE
TRUE … FALSE
1
… (9, 2)
[5]
(c) Study the following pseudocode.
Line numbers are given for reference only.
01
PROCEDURE StringClean(InString : STRING)
02
03
DECLARE NextChar : CHAR
04
DECLARE OutString : STRING
05
DECLARE Index : INTEGER
06
""
07
OutString
08
1 TO LENGTH(InString)
09
FOR Index
10
MID(InString, Index, 1)
11
NextChar
LCASE(NextChar)
12
NextChar
13
14
IF NextChar >= 'a' AND NextChar <= 'z'
15
THEN
OutString & NextChar
16
OutString
17
ENDIF
18
19
ENDFOR
20
21
OUTPUT OutString
22
23
ENDPROCEDURE
Complete the following table by entering an appropriate answer.
Answer
The name for the type of loop used
A line number of a selection statement
The scope of OutString
The name of a function that is called
A line number containing a logical operator
[5]
Question text
3
The procedure OutputLines() outputs a number of lines from a text file.
An example of the use of the procedure is given by the following pseudocode:
CALL OutputLines(FileName, StartLine, NumberLines)
Parameter
Data type
Description
FileName
STRING
The name of the text file
StartLine
INTEGER
The number of the first line to be output
NumberLines
INTEGER
The number of lines to be output
The procedure is tested using the file MyFile.txt that contains 100 lines of text.
The procedure gives the expected result when called as follows:
CALL OutputLines("MyFile.txt", 1, 10)
(a) The procedure is correctly called with three parameters of the appropriate data types, but the
procedure does not give the expected result.
Give three different reasons why this might happen.
1 …
…
2 …
…
3 …
…
[3]
(b) Write program code for the procedure OutputLines().
Note: Parameter validation is not necessary.
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
…
…
…
…
…
…
…
…
…
…
…
…
…
Question text
4
A function, FormOut(), takes an integer parameter in the range 0 to 999 999 and returns a
formatted string depending on two other parameter values.
Formatting may incorporate the use of:
•
A prefix string to be added before the integer value (e.g. '$' or "Total: ")
•
A comma as a thousand-separator (e.g. "1,000")
The function will be called as follows:
FormOut(Number, Prefix, AddComma)
MyString
Parameter
Data type
Description
Number
INTEGER
The positive integer value to be formatted.
A string that will appear in front of the numeric value. Set to an
Prefix
STRING
empty string if no prefix is required.
TRUE if a comma is required in the formatted string.
AddComma
BOOLEAN
FALSE if a comma is not required in the formatted string.
(a) Fill in the tables to show two tests that could be carried out to test different aspects of the
function.
Give the expected result for each test.
TEST 1
Parameter
Value
Expected return string:
Number
…
Prefix
AddComma
TEST 2
Parameter
Value
Expected return string:
Number
Prefix
…
AddComma
[4]
(b) Write pseudocode for the function FormOut().
Refer to the Appendix on pages 18–19 for the list of built-in functions and operators.
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
Question text
5
A message may contain several hashtags.
A hashtag is a string consisting of a hash character ‘#’, followed by one or more alphanumeric
characters.
A hashtag may be terminated by a space character, the start of the next hashtag, any other
non-alphanumeric character, or by the end of the message.
For example, the following message contains three hashtags:
"#Error27 is the result of #PoorPlanning by the #Designer"
The hashtags in the message are "#Error27", "#PoorPlanning" and "#Designer".
A program is being developed to process a message and extract each hashtag.
A global 1D array of strings, TagString, will store each hashtag in a single element.
Unused array elements will contain an empty string. The array will contain 10 000 elements.
A developer has started to define the modules as follows:
Module
Description
•
Called with two parameters:
•
a message string
•
an integer giving the number of the required hashtag.
For example, GetStart(Message, 3) would search
GetStart()
for the third hashtag in the string Message
•
Returns an integer value representing the start position
of the hashtag in the message string, or value −1 if that
hashtag does not exist
•
Called with two parameters:
•
a message string
•
an integer giving the hashtag start position within the
GetTag()
message
•
Returns the hashtag or an empty string if the character in
the message at the hashtag start position is not '#'
•
Called with a hashtag as a parameter
•
Returns the index position of the hashtag in array
GetIndex()
TagString
•
Returns the value −1 if the hashtag is not present in the
array
(a) Write pseudocode for the module GetIndex().
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…