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

Oct/Nov 2020 · 9608/22/O/N/20

Questions5
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/O/N/20 · Question 1Oct/Nov 2020Paper 2212 marks
Loading question…
Question text

1
(a) Algorithms usually consist of three different stages.
One stage is INPUT.
Name the other stages.
1 …
2 …
[1]
(b) An algorithm may be documented using different methods. These include structured English,
a program flowchart, and pseudocode.
State what a program designer represents using one or more of these methods.
…
… [2]
(c) Programming languages support different data types.
Complete the table by giving four different data types together with an example data value
for each.
Data type
Example data value
[4]
(d) Draw lines to connect each of the following computing terms with the appropriate description.
Term
Description
A structure for the
Black-box testing
temporary storage of data
A method used when the
File
structure of the program is
unknown
A method of setting the
Assignment
value of a variable
A structure for the
Array
permanent storage of data
[3]
(e) A pseudocode algorithm assigns values to three variables as follows:
TRUE
FlagA
FALSE
FlagB
TRUE
FlagC
Evaluate the expressions given in the following table:
Expression
Evaluates to
NOT FlagB AND FlagC
NOT (FlagB OR FlagC)
(FlagA AND FlagB) OR FlagC
NOT (FlagA AND FlagB) OR NOT FlagC
[2]

2
9608/22/O/N/20 · Question 2Oct/Nov 2020Paper 2214 marks
Loading question…
Question text

2
(a) The following pseudocode is an attempt to define an algorithm that takes two numbers as
input and outputs the larger of the two numbers.
DECLARE A, B : INTEGER
INPUT A
INPUT B
IF A > B
THEN
OUTPUT A
ELSE
OUTPUT B
ENDIF
The algorithm needs to be amended to include the following changes:
Input three values, ensuring that each value input is unique.
1.
2.
Output the average.
3.
Output the largest value.
Write the pseudocode for the amended algorithm.
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…

3
9608/22/O/N/20 · Question 3Oct/Nov 2020Paper 2210 marks
Loading question…
Question text

3
A car has the ability to detect a skid by monitoring the rate of rotation (the rotational speed) of
each wheel. If the rate of rotation of any wheel is not within 10% of the average of all four wheels,
the car skids.
A function, CheckSkid(), is being developed.
The function will:
•
simulate real-time data acquisition, by prompting for the input of four integer values in the
range 0 to 1000 inclusive, representing the rate of rotation of each wheel
•
calculate the average value
•
check whether any individual value is more than 10% greater than the average or more than
10% less than the average
•
return TRUE if any individual value is more than 10% greater than the average or more than
10% less than the average and FALSE otherwise
•
output a suitable warning message.
(a) Write program code for the function CheckSkid().
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
4
9608/22/O/N/20 · Question 4Oct/Nov 2020Paper 2219 marks
Loading question…
Question text

4
(a) The following structured English describes an algorithm used to count the number of odd and
even digits in an input sequence.
1.
Initialise variables OddCount and EvenCount to zero.
2.
Prompt and input an integer.
3.
If the integer is not in the range 0 to 9 then go to step 7.
4.
If the integer is an even number then add 1 to EvenCount.
5.
Otherwise add 1 to OddCount.
6.
Repeat from step 2.
7.
Output "Same" if there are the same number of odd and even integers.
8.
Output "Odd" if there are more odd than even integers.
9.
Output "Even" if there are more even than odd integers.
Draw a flowchart on the following page to represent the algorithm.
[7]
(b) The following pseudocode is an attempt to check whether two equal-length strings consist of
identical characters.
Refer to the Appendix on pages 18–19 for the list of built-in functions and operators.
FUNCTION Compare(String1, String2 : STRING) RETURNS BOOLEAN
DECLARE x, y, Len1, Len2 : INTEGER
DECLARE RetFlag : BOOLEAN
DECLARE NextChar : CHAR
DECLARE New : STRING
LENGTH(String1)
Len1
TRUE
RetFlag
1 TO Len1
// for each char in String1
FOR x
LENGTH(String2)
Len2
MID(String1, x, 1)
// get NextChar from String1
NextChar
""
New
1 TO Len2
// for each char in String2
FOR y
IF NextChar <> MID(String2, y, 1)
// no match
THEN
New & MID(String2, y, 1) // save this char from String2
New
ENDIF
ENDFOR
New
// replace String2 with New
String2
ENDFOR
IF LENGTH(String2) <> 0
// anything left in String2 ?
THEN
FALSE
RetFlag
ENDIF
RETURN RetFlag
ENDFUNCTION
(i)
Complete the trace table below by performing a dry run of the function when it is called
as follows:
Compare("SUB", "BUS")
Result
The first row has been completed for you.
String1 String2 Len1 RetFlag
x
Len2
NextChar
New
y
"SUB"
"BUS"
3
TRUE
1
[5]
(ii)
State the value returned.
… [1]
(iii)
There is an error in the algorithm, which means that under certain circumstances, the
function will return an incorrect value.
Describe the problem. Give two test strings that would demonstrate it.
Problem …
…
…
…
…
Test String1 …
Test String2 …
[2]
(iv)
Describe the modification that needs to be made to the algorithm to correct the error.
Do not use pseudocode or program code in your answer.
…
…
…
…
…

5
9608/22/O/N/20 · Question 5Oct/Nov 2020Paper 2220 marks
Loading question…
Question text

5
A hashtag is used on a social media network. A hashtag is a string consisting of a hash character
‘#’ followed by one or more alphanumeric characters.
A program is being developed to monitor the use of hashtags.
The program will include two global arrays each containing 10 000 elements:
•
A 1D array, TagString, of type STRING stores each hashtag in a single element. All unused
array elements contain an empty string ("").
•
A 1D array, TagCount, of type INTEGER stores a count of the number of times each hashtag
is used. The count value at a given index relates to the element stored at the corresponding
index in the TagString array.
The contents of the two arrays will be stored in a text file Backup.txt. The format of each line of
the file is:
<Hashtag><','><Count>
For example:
"#ComputerScienceClass,978"
A developer has started to define the modules as follows:
Module
Description
•
InitArrays()
Initialise the arrays
•
The contents of the two arrays are stored in the text file Backup.txt
Existing file contents will be overwritten
•
Each hashtag and count are stored in one line of the file, as in the example
SaveArrays()
above
•
Unused TagString elements are not added to the file
•
Returns the total number of unused TagString elements
•
Values from the text file Backup.txt are stored in the two arrays
LoadArrays()
•
The number of elements stored is returned
(a) Write pseudocode for the module InitArrays().
…
…
…
…
…
…
…
…
…
… [4]
(b) Write pseudocode for the module SaveArrays().
…
…
…
…
…
…
…

Advertisement