Past paper – A Level Computer Science (old syllabus, to 2021) (9608)

Cambridge International AS & A Level · 9608

Computer Science (old syllabus, to 2021) · Paper 22

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

Questions6
Marks75
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/22/M/J/19 · Question 1May/June 2019Paper 2217 marks
Loading question…
Question text

1
(a) Algorithms are used in computer programming.
(i)
Explain the term algorithm.
…
…
…
… [2]
(ii)
Algorithms usually consist of three different types of activity.
Complete the table below.
The third activity type is given.
Activity type
Pseudocode example
…
…
…
…
…
…
…
Output
…
[5]
(b) Program variables have values as follows:
Variable
Value
Married
03/04/1982
ID
"M1234"
MiddleInitial
'J'
Height
5.6
IsMarried
TRUE
Children
2
(i)
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 16.
Expression
Evaluates to
STRING_TO_NUM(RIGHT(ID, 3))
INT(Height * Children)
IsMarried AND Married < 31/12/1999
LENGTH(ID & NUM_TO_STRING(Height))
MID(ID, INT(Height) – Children, 2)
[5]
(ii)
Programming languages support different data types.
Give an appropriate data type for the following variables from part (b).
Variable
Data type
Married
ID
MiddleInitial
Height
IsMarried
[5]

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

2
(a) (i)
Procedures and functions are examples of subroutines.
State a reason for using subroutines in the construction of an algorithm.
…
… [1]
(ii)
Give three advantages of using subroutines in a program.
1 …
…
2 …
…
3 …
…
[3]
(iii)
The following pseudocode uses the subroutine DoSomething().
23 + DoSomething("Yellow")
Answer
State whether the subroutine is a function or a procedure. Justify your answer.
Type of subroutine …
Justification …
…
[2]
(b) The program development cycle involves writing, translating and testing a high-level language
program.
Describe these activities with reference to each of the following:
•
editor
•
translator
•
debugger
…
…
…
…
…
… [3]
(c) The following lines of code are taken from a high-level language program.
WHEN Result < 20
{
Call ResetSensor(3)
Result := GetSensor(3)
}
Identify the type of control structure and describe the function of the code.
Control structure …
Function of code …
…
…
…
…

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

3
The following structure chart shows the relationship between three modules.
TopLevel
B
D
A
C
E
SubA
SubB
Parameters A to E have the following data types:
A, D : STRING
C
: CHAR
B, E : INTEGER
(a) (i)
Write the pseudocode header for module SubA().
…
…
… [3]
(ii)
Write the pseudocode header for module SubB().
…
…
… [3]
(b) Module hierarchy and parameters are two features that may be represented on a structure
chart.
State two other features than can be represented.
Feature 1 …
Feature 2 …
[2]
Question 4 begins on the next page.

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

4
The following is pseudocode for a string handling function.
For the built-in functions list, refer to the Appendix on page 16.
FUNCTION Search(InString : STRING) RETURNS INTEGER
DECLARE
NewString : STRING
DECLARE
Index : INTEGER
DECLARE
NextChar : CHAR
DECLARE
Selected : INTEGER
DECLARE
NewValue : INTEGER
'0'
NewString
0
Selected
1 TO LENGTH(InString)
FOR Index
MID(InString, Index, 1)
NextChar
IF NextChar < '0' OR NextChar > '9'
THEN
STRING_TO_NUM(NewString)
NewValue
IF NewValue > Selected
THEN
NewValue
Selected
ENDIF
'0'
NewString
ELSE
NewString & NextChar
NewString
ENDIF
ENDFOR
RETURN Selected
ENDFUNCTION
(a) (i)
The following assignment calls the Search() function:
Search("12∇34∇5∇∇39")
Result
Complete the following trace table by performing a dry run of this function call.
The symbol '∇' represents a space character. Use this symbol to represent a space
character in the trace table.
Index
NextChar
Selected
NewValue
NewString
[5]
(ii)
State the value returned by the function when it is called as shown in part (a)(i).
…
[1]
(b) There is an error in the algorithm. When called as shown in part (a)(i), the function did not
return the largest value as expected.
(i)
Explain why this error occurred when the program called the function.
…
…
…
… [2]
(ii)
Describe how the algorithm could be amended to correct the error.
…
…
…
… [2]

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

5
A student is learning about text files. She wants to write a program to count the number of lines in
a file.
(a) Use structured English to describe an algorithm she could use.
…
…
…
…
…
… [3]
(b) A procedure, CountLines(), is being written to count the number of lines in a text file. The
procedure will:
•
take a filename as a string parameter
•
count the number of lines in the file
•
output a single suitable message that includes the total number of lines.
Write pseudocode for the procedure CountLines().
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…

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

6
Nadine is developing a program to store the ID and preferred name for each student in a school.
For example, student Pradeep uses the preferred name “Prad”.
The program will:
1.
prompt and input a valid user ID and a preferred name
2.
write the user ID and preferred name to one of two files
3.
allow the user to end the program or repeat from step 1.
The program will consist of three separate modules. Each module will be implemented using
either a procedure or a function.
Nadine has defined the modules as follows:
Module
Description
TopLevel()
•
Call GetInfo() to obtain a string containing a valid user ID and a
preferred name
•
Call WriteInfo() to write the string to either File1.txt or
File2.txt depending on the first character of the user ID as follows:
‘A’ to ‘M’: writes to File1.txt
○
‘N’ to ‘Z’: writes to File2.txt
○
For example, a string with a user ID of "G1234" writes to File1.txt
•
End the program if the file write was unsuccessful
•
Input (Y/N) to either repeat for the next user ID or to end the program
GetInfo()
•
Input a user ID and repeat until the user ID is valid
•
Input a preferred name. This will be an empty string if no preferred
name is input.
•
Concatenate the user ID and preferred name using a '*' character as
a separator and return this string
WriteInfo()
•
Open the file
•
Append the concatenated string to the file
•
Close the file
•
Return a Boolean value:
TRUE if the file write was successful
○
FALSE if the file write failed, for example, if the disk was full
○
A valid user ID:
•
is five characters in length
•
has a single upper case alphabetic character followed by four numeric characters, for
example “G1234”.
Nadine has decided that global variables and nested modules must not be used.
Nadine wants all inputs to have suitable prompts.
(a) Write program code for the module GetInfo().
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