Cambridge International AS & A Level
* 8 4 1 6 1 0 0 9 4 2 *
COMPUTER SCIENCE 9618/21
Paper 2 Fundamental Problem-solving and Programming Skills
You must answer on the question paper.
You will need: Insert (enclosed)
INSTRUCTIONS
● Answer all questions.
● Use a black or dark blue pen.
● Write your name, centre number and candidate number in the boxes at the top of the page.
● Write your answer to each question in the space provided.
● Do not use an erasable pen or correction fluid.
● Do not write on any bar codes.
● You may use an HB pencil for any diagrams, graphs or rough working.
● Calculators must not be used in this paper.
INFORMATION
● The number of marks for each question or part question is shown in brackets [ ].
● No marks will be awarded for using brand names of software packages or hardware.
● The insert contains all the resources referred to in the questions.
This document has 24 pages. Any blank pages are indicated.
DC (PQ/CGW) 329348/4
© UCLES 2024 [Turn over
Refer to the insert for the list of pseudocode functions and operators.
1 An algorithm is developed in pseudocode before being coded in a programming language.
(a) The following table shows four valid pseudocode assignment statements.
Complete the table by giving an appropriate data type to declare each of the variables A, B, C
and D.
Assignment statement Data type
A LEFT(MyName, 1)
B Total * 2
C INT(ItemCost) / 3
D "Odd OR Even"
[4]
(b) Other variables in the program have example values as shown:
Variable Value
Sorted False
Tries 9
ID "ZGAC001"
Complete the table by evaluating each expression, using the example values.
Expression Evaluates to
Tries < 10 AND NOT Sorted
Tries MOD 4
TO_LOWER(MID(ID, 3, 1))
LENGTH(ID & "xx") >= Tries
[4]
© UCLES 2024 9618/21/M/J/24
3
(c) The variable names A, B, C and D in part (a) are not good programming practice.
(i) State why these variable names are not suitable.
...........................................................................................................................................
..................................................................................................................................... [1]
(ii) Identify one problem that these variable names might cause.
...........................................................................................................................................
..................................................................................................................................... [1]
(iii) The choice of suitable variable names is one example of good programming practice.
Give one other example.
...........................................................................................................................................
..................................................................................................................................... [1]
© UCLES 2024 9618/21/M/J/24 [Turn over
4
2 An algorithm has three steps. It will:
1. repeatedly input a pair of numeric values A and B
2. count the number of pairs that are input until A has been greater than B 10 times
3. output the number of pairs that were input.
(a) Complete the program flowchart.
START
INPUT A, B
Yes
No
END
[5]
© UCLES 2024 9618/21/M/J/24
5
(b) Step 1 of the algorithm is changed.
A variable ThisSequence is used to enter a sequence of 10 pairs of numeric values, using
a single input statement.
Following the input of ThisSequence the revised algorithm will extract the pairs of numbers.
Describe the variable ThisSequence and how the numbers are extracted.
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
............................................................................................................................................. [2]
© UCLES 2024 9618/21/M/J/24 [Turn over
10
3 A global 1D array of strings contains three elements which are assigned values as shown:
Data[1] "aaaaaa"
Data[2] "bbbbbb"
Data[3] "cccccc"
Procedure Process() manipulates the values in the array.
The procedure is written in pseudocode as follows:
PROCEDURE Process(Format : STRING)
DECLARE Count, Index, L : INTEGER
DECLARE Result : STRING
DECLARE C : CHAR
Result "****"
FOR Count 1 TO LENGTH(Format) STEP 2
C MID(Format, Count, 1)
L STR_TO_NUM(MID(Format, Count + 1, 1))
Index (Count + 1) DIV 2
CASE OF C
'X' : Result TO_UPPER(Data[Index])
'Y' : Result TO_LOWER(Data[Index])
'Z' : Result "**" & Data[Index]
ENDCASE
Data[Index] LEFT(Result, L)
NEXT Count
ENDPROCEDURE
© UCLES 2024 9618/21/M/J/24
11
(a) Complete the trace table by dry running the procedure when it is called as follows:
CALL Process("X3Y2W4")
Count C L Index Result Data[1] Data[2] Data[3]
[6]
(b) The procedure is to be modified. If variable C is assigned a value other than 'X', 'Y' or 'Z',
then procedure Error() is called and passed the value of variable C as a parameter.
This modification can be implemented by adding a single line of pseudocode.
(i) Write the single line of pseudocode.
..................................................................................................................................... [1]
(ii) State where this new line should be placed.
..................................................................................................................................... [1]
© UCLES 2024 9618/21/M/J/24 [Turn over