Cambridge International AS & A Level: Computer Science 9618/21
Cambridge International AS & A Level: Computer Science 9618/21
Cambridge International AS & A Level: Computer Science 9618/21
* 6 7 8 5 4 5 4 5 5 5 *
2 hours
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 total mark for this paper is 75.
● 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.
DC (RW/CGW) 303754/3
© UCLES 2022 [Turn over
2
Refer to the insert for the list of pseudocode functions and operators.
1 (a) A programmer draws a program flowchart to show the sequence of steps required to solve a
problem.
Give the technical term for a sequence of steps that describe how to solve a problem.
algorithm
...................................................................................................................................................
............................................................................................................................................. [1]
(i) Complete the table by writing the most appropriate data type for each variable.
[4]
(ii) One of the names used for a variable in the table in part 1(b)(i) is not an example of
good practice.
Identify the variable and give a reason why it is not good practice to use that name.
Variable .............................................................................................................................
MyDOB
Reason ..............................................................................................................................
could be mistaken for the date of birth
...........................................................................................................................................
...........................................................................................................................................
[2]
Expression Evaluation
INT((31 / 3) + 1) 11
MID(TO_UPPER("Version"), 4, 2) SI
[4]
Button-Y
Button-Z | Output-C
START
S1 Button-Z S3
Button-Y
Button-Y | Output-A
Button-X
S2
S4
Button-Z | Output-B
Answer
The number of different inputs 3
[3]
Complete the table to show the inputs, outputs and next states.
Button-Y A S4
Button y none S4
Button-Z B S2
Button X none S2
[4]
3 The manager of a cinema wants a program to allow users to book seats. The cinema has several
screens. Each screen shows a different film.
(a) Decomposition will be used to break the problem down into sub-problems.
...................................................................................................................................................
...................................................................................................................................................
Module buying tickets for movies
Module 2 ...................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
Module to show which seats are booked and how many seats left
Module 3 ...................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
[3]
(b) Two types of program modules may be used in the design of the program.
Identify the type of program module that should be used to return a value.
Function
............................................................................................................................................. [1]
BLANK PAGE
4 A stack is created using a high-level language. Memory locations 200 to 207 are to be used to
store the stack.
Stack Pointer
Memory
Value
location
200
201
202
204 'C'
205 'D'
206 'E'
207 'H'
Answer
The value that has been on the stack for the longest time. 'H'
[2]
(b) The following diagram shows the current state of the stack:
Stack Pointer
Memory
Value
location
200
201
203 'Y'
204 'X'
205 'Z'
206 'N'
207 'P'
POP
POP
PUSH 'A'
PUSH 'B'
POP
PUSH 'C'
PUSH 'D'
Complete the diagram to show the state of the stack after the operations have been
performed.
Stack Pointer
Memory
Value
location
200
202 'C'
203 'A'
204 'X'
205 'Z'
206 'N'
207 'P'
[4]
5 Each line of a text file contains data organised into fixed-length fields as shown:
An algorithm is required to search for the first instance of a given value of Field 2 and, if found, to
output the corresponding values for Field 1 and Field 3.
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
.................................................................................................................................................... [6]
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
............................................................................................................................................. [5]
CASE OF MySwitch
1: ThisChar 'a'
2: ThisChar 'y'
3: ThisChar '7'
OTHERWISE: ThisChar '*'
ENDCASE
Write pseudocode with the same functionality without using a CASE structure.
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
............................................................................................................................................. [4]
Upper-case and lower-case characters need to be treated the same. For example, 'A' is equivalent
to 'a'.
(a) A function IsPalindrome() will take a string parameter. The function will return TRUE if the
string is a palindrome and will return FALSE if the string is not a palindrome.
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
............................................................................................................................................. [7]
For example, the string "never odd or even" becomes a palindrome if the spaces are removed.
START
Set Index to 1
NO
B
E
YES
F
C
D
END
Complete the table by writing the text that should replace each of the labels B, C, D, F and G.
Label Text
G
[4]
© UCLES 2022 9618/21/M/J/22 [Turn over
14
8 A program allows a user to save passwords used to login to websites. A stored password is
inserted automatically when the user logs into the corresponding website.
A student is developing a program to generate a password. The password will be of a fixed format,
consisting of three groups of four alphanumeric characters. The groups are separated by the
hyphen character '-'.
A global 2D array Secret of type STRING stores the passwords together with the website domain
name where they are used. Secret contains 1000 elements organised as 500 rows by 2 columns.
Unused elements contain the empty string (""). These may occur anywhere in the array.
Secret[27, 1] "www.thiswebsite.com"
Secret[27, 2] ""
Secret[28, 1] "www.thatwebsite.com"
Secret[28, 2] ""
Note:
• For security, passwords are stored in an encrypted form, shown as "" in the
example.
• The passwords cannot be used without being decrypted.
• Assume that the encrypted form of a password will not be an empty string.
Module Description
RandomChar() • Generates a single random character from within one of the
following ranges:
○ 'a' to 'z'
○ 'A' to 'Z'
○ '0' to '9'
• Returns the character
Encrypt() • Takes a password as a parameter of type string
• Returns the encrypted form of the password as a string
Decrypt() • Takes an encrypted password as a parameter of type string
• Returns the decrypted form of the password as a string
'A' to 'Z' 65 to 90
'0' to '9' 48 to 57
You may wish to refer to the insert for a description of the CHR() function. Other functions
may also be required.
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
............................................................................................................................................. [6]
Module Description
FindPassword() • Takes a website domain name as a parameter of type string
• Searches for the website domain name in the array Secret
• If the website domain name is found, the decrypted password
is returned
• If the website domain name is not found, a warning message
is output, and an empty string is returned
Assume that modules Encrypt() and Decrypt() have already been written.
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
............................................................................................................................................. [7]
© UCLES 2022 9618/21/M/J/22
17
(c) The modules Encrypt() and Decrypt() are called from several places in the main
program.
Identify a method that could have been used to test the main program before these modules
were completed. Describe how this would work.
Method ......................................................................................................................................
Description ................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
............................................................................................................................................. [3]
(d) A validation function is written to check that the passwords generated are valid.
Note: lower-case and upper-case characters are not the same. For example, 'a' is not the
same as 'A'.
Give two password strings that could be used to test different areas of the validation rules.
A1B2-C3D4-E5F6
Password 1 ...............................................................................................................................
a1b2-c3d4-e5f6
Password 2 ...............................................................................................................................
[2]
(e) The RandomChar() module is to be modified so that alphabetic characters are generated
twice as often as numeric characters.
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
............................................................................................................................................. [3]
BLANK PAGE
BLANK PAGE
BLANK PAGE
Permission to reproduce items where third-party owned material protected by copyright is included has been sought and cleared where possible. Every
reasonable effort has been made by the publisher (UCLES) to trace copyright holders, but if any items requiring clearance have unwittingly been included, the
publisher will be pleased to make amends at the earliest possible opportunity.
To avoid the issue of disclosure of answer-related information to candidates, all copyright acknowledgements are reproduced online in the Cambridge
Assessment International Education Copyright Acknowledgements Booklet. This is produced for each series of examinations and is freely available to download
at www.cambridgeinternational.org after the live examination series.
Cambridge Assessment International Education is part of Cambridge Assessment. Cambridge Assessment is the brand name of the University of Cambridge
Local Examinations Syndicate (UCLES), which is a department of the University of Cambridge.