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

May/June 2019 · 9608/23/M/J/19

Questions6
Marks76
TypeWritten

Answer on paper, open each mark scheme and give yourself marks, then open the Summary.

0 / 0Answer a question to start your score.
Saved 0
Advertisement
1
9608/23/M/J/19 · Question 1May/June 2019Paper 2317 marks
Loading question…
Question text

1
The following pseudocode searches for the longest run of identical characters in the array
Message.
DECLARE Message : ARRAY[1:100] OF CHAR
PROCEDURE Search()
DECLARE
Index : INTEGER
DECLARE
ThisChar : CHAR
DECLARE
ThisRun : INTEGER
DECLARE
LongRun : INTEGER
Message[1]
ThisChar
1
ThisRun
1
LongRun
2 TO 100
FOR Index
IF Message[Index] = ThisChar
THEN
ThisRun + 1
ThisRun
ELSE
Message[Index]
ThisChar
IF ThisRun > LongRun
THEN
ThisRun
LongRun
ENDIF
1
ThisRun
ENDIF
ENDFOR
OUTPUT "The longest run was " , LongRun
ENDPROCEDURE
(a) Draw a program flowchart to represent the procedure Search().
Variable and array declarations are not required in program flowcharts.
[6]
(b) (i)
Program variables have values as follows:
Variable
Value
MeltingPoint
180.5
Soluble
FALSE
Attempt
3
ProductName
"Mushroom Compost"
Version
'A'
ProductID
"BZ27-4"
Evaluate each expression in the following table.
If an expression is invalid, write ERROR.
For the built-in functions list, refer to the Appendix on page 18.
Expression
Evaluates to
STRING_TO_NUM(MID(ProductID, 3, 2)) + 4
INT(MeltingPoint / 2)
Soluble AND Attempt > 3
LENGTH(ProductID & NUM_TO_STRING(MeltingPoint))
RIGHT(ProductName, 4) & MID(ProductName, 5, 4)
[5]
(ii)
Programming languages support different data types.
Give an appropriate data type for the following variables from part (b)(i).
Variable
Data type
MeltingPoint
Soluble
Attempt
Version
ProductID
[5]

2
9608/23/M/J/19 · Question 2May/June 2019Paper 2315 marks
Loading question…
Question text

2
(a) A student is learning about arrays. She wants to write a program to:
•
search through a 1D array of 100 elements
•
count the number of elements that contain the string “Empty”
•
output the number of elements containing “Empty” together with a suitable message.
Use structured English to describe the algorithm she could use.
…
…
…
…
…
…
…
…
…
…
… [5]
(b) She uses the process of stepwise refinement to develop her algorithm.
Explain this process.
…
…
…
…
…
… [3]
(c) The student is learning about file handling.
She has been told that there are different file modes that can be used when opening a text
file. She wants to make sure that the existing contents are not deleted when the file is opened.
Identify two file modes she could use and describe their use.
Mode …
Description …
…
…
Mode …
Description …
…

3
9608/23/M/J/19 · Question 3May/June 2019Paper 238 marks
Loading question…
Question text

3
The following pseudocode represents three separate modules from an algorithm design. The
module contents are not shown.
FUNCTION Search(AA : INTEGER, BB : STRING) RETURNS INTEGER
ENDFUNCTION
FUNCTION Allocate() RETURNS BOOLEAN
ENDFUNCTION
PROCEDURE Enable(CC : INTEGER, BYREF DD : INTEGER)
ENDPROCEDURE
A fourth module, Setup(), refers to the previous three modules as follows:
PROCEDURE Setup()
WHILE Authorised = TRUE
ThisValue
Search(27, "Thursday")
Authorised
Allocate()
CALL Enable(ThisValue, 4)
ENDWHILE
ENDPROCEDURE
(a) Draw a structure chart to show the four modules and the parameters that these pass between
them.
[6]
(b) The algorithm is implemented in a high-level language. Changes are required and the
program is given to Albert, who is an experienced programmer. He is not familiar with the
language that has been used.
Explain why Albert would be able to understand the program.
…
…
…
… [2]

Advertisement
4
9608/23/M/J/19 · Question 4May/June 2019Paper 235 marks
Loading question…
Question text

4
A program is being written to process student information. One task involves inputting the names
of all students in a class.
A first attempt at the pseudocode for this task is as follows:
DECLARE Name1 : STRING
DECLARE Name2 : STRING
DECLARE Name3 : STRING
DECLARE Name40 : STRING
OUTPUT "Input the name for student 1"
INPUT Name1
OUTPUT "Input the name for student 2"
INPUT Name2
OUTPUT "Input the name for student 3"
INPUT Name3
OUTPUT "Input the name for student 40"
INPUT Name40
(a)
Re-write the pseudocode to perform this task in a more efficient way, to allow for the class of
40 students.
…
…
…
…
…
…
…
…
…
… [4]
(b)
Give one advantage of your solution.
… [1]
Question 5 begins on the next page.

5
9608/23/M/J/19 · Question 5May/June 2019Paper 2311 marks
Loading question…
Question text

5
Nigel is learning about string handling. He wants to write code to count the number of words in a
given string. A word is defined as a sequence of alphabetic characters that is separated by one or
more space characters.
His first attempt at writing an algorithm in pseudocode is as follows:
PROCEDURE CountWords(Message : STRING)
DECLARE NumWords : INTEGER
DECLARE Index : INTEGER
CONSTANT Space = ' '
0
NumWords
1 TO LENGTH(Message)
FOR Index
IF MID(Message, Index, 1) = Space
THEN
NumWords + 1
NumWords
ENDIF
ENDFOR
OUTPUT "Number of words : " , NumWords
ENDPROCEDURE
For the built-in functions list, refer to the Appendix on page 18.
His first attempt is incorrect. He will use white-box testing to help him to identify the problem.
(a) (i)
State the purpose of white-box testing.
…
… [1]
(ii)
Dry running the code is often used in white-box testing. In this method, the programmer
records the values of variables as they change.
Identify what the programmer would normally use to record the changes.
… [1]
(b) (i)
Write a test string containing two words that gives the output:
Number of words : 2
Use the symbol '∇' to represent each space character in your test string.
Explain why the algorithm gives the output shown above.
String …
Explanation …
…
…
…
…
[3]
(ii)
Nigel tested the procedure with the strings:
String 1: "Red∇and∇Yellow"
String 2: "Green∇∇and∇∇Pink∇"
Give the output that is produced for each of the strings.
Describe the changes that would need to be made to the algorithm to give the correct
output in each case.
Do not write pseudocode or program code.
String 1 …
Description …
…
…
…
String 2 …
Description …
…
…

6
9608/23/M/J/19 · Question 6May/June 2019Paper 2320 marks
Loading question…
Question text

6
A text file, StudentContact.txt, contains a list of names and telephone numbers of students
in a school. Not all students in the school have provided a contact telephone number. In this case,
their name will not be in the file.
Each line of the file is stored as a string that contains a name and telephone number, separated by
the asterisk character ('*') as follows:
<Name>'*'<TelNumber>, for example:
"Bill Smith*081234567"
A 1D array, ClassList, contains the names of students in a particular class. The array consists
of 40 elements of string data type. You can assume that student names are unique.
Unused elements contain the empty string "".
A program is to be written to produce a new text file, ClassContact.txt, containing student
names and numbers for all students in a particular class.
For each name contained in the ClassList array, the program will:
•
search the StudentContact.txt file
•
copy the matching string into ClassContact.txt if the name is found
•
write the name together with “*No number” into ClassContact.txt if the name is not found.
The program will be implemented as three modules. The description of these is as follows:
Module
Description
ProcessArray()
•
Check each element of the array:
Read the student name from the array
○
Ignore unused elements
○
Call SearchFile() with the student name
○
If the student name is found, call AddToFile() to
○
write the student details to the class file
If the student name is not found, call AddToFile()
○
to write a new string to the class file, formed as
follows:
<Name>“*No number”
•
Return the number of students who have not provided a
telephone number
SearchFile()
•
Search for a given student name at the start of each line
in the file StudentContact.txt:
If the search string is found, return the text line from
○
StudentContact.txt
If the search string is not found, return an empty
○
string
AddToFile()
•
Append the given string to a specified file, for example,
AddToFile(StringName, FileName)
(a) Write program code for the module SearchFile().
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
…
…
…
…
…
…
…
…
…
…
…
…

Advertisement