Cambridge International AS & A Level: Computer Science 9618/41
Cambridge International AS & A Level: Computer Science 9618/41
Cambridge International AS & A Level: Computer Science 9618/41
2 hours 30 minutes
You will need: Candidate source files (listed on page 2)
evidence.doc
* 8 8 1 5 7 3 7 7 9 3 *
INSTRUCTIONS
● Carry out every instruction in each task.
● Save your work using the file names given in the task as and when instructed.
● You must not have access to either the internet or any email system during this examination.
● You must save your work in the evidence document as stated in the tasks. If work is not saved in the
evidence document, you will not receive marks for that task.
● You must use a high-level programming language from this list:
Java (console mode)
Python (console mode)
Visual Basic (console mode)
● A mark of zero will be awarded if a programming language other than those listed here is used.
INFORMATION
● The total mark for this paper is 75.
● The number of marks for each question or part question is shown in brackets [ ].
DC (LK) 316229/3
© UCLES 2023 [Turn over
2
Make sure that your name, centre number and candidate number appear on every page of this
document. This document must contain your answers to each question.
If the programming language used does not support arrays, a list can be used instead.
One source file is used to answer Question 2. The file is called QueueData.txt
1 This iterative pseudocode algorithm for the function IterativeVowels() takes a string as a
parameter and counts the number of lower-case vowels in this string.
The vowels are the letters a, e, i, o and u.
The pseudocode function MID(X, Y, Z) returns Z number of characters from string X, starting
at the character in position Y. The first character in a string is in position 0, for example:
The pseudocode function LENGTH(X) returns the number of characters in the string X, for
example:
LENGTH("computer") returns 8
Copy and paste the program code into part 1(a)(i) in the evidence document.
[5]
(ii) Write program code to call the function IterativeVowels() with the parameter
"house" from the main program.
Copy and paste the program code into part 1(a)(ii) in the evidence document.
[2]
Copy and paste the screenshot into part 1(a)(iii) in the evidence document.
[1]
(b) (i) Rewrite the function IterativeVowels() as a recursive function with the identifier
RecursiveVowels().
Copy and paste the program code into part 1(b)(i) in the evidence document.
[6]
(ii) Write program code to call the function RecursiveVowels() with the parameter
"imagine" from the main program.
Copy and paste the program code into part 1(b)(ii) in the evidence document.
[1]
Copy and paste the screenshot into part 1(b)(iii) in the evidence document.
[1]
© UCLES 2023 9618/41/O/N/23 [Turn over
4
2 A linear queue is implemented using the 1D array, Queue. The index of the first element in the
array is 0.
Copy and paste the program code into part 2(a)(i) in the evidence document.
[2]
If the queue is full, the procedure outputs a suitable message. If the queue is not full, the
procedure inserts the parameter into the queue and updates the relevant pointer(s).
Copy and paste the program code into part 2(a)(ii) in the evidence document.
[4]
If the queue is empty, the function outputs a suitable message and returns the string
"Empty".
If the queue is not empty, the function returns the first element in the queue and updates
the relevant pointer(s).
Copy and paste the program code into part 2(a)(iii) in the evidence document.
[4]
(b) A shop sells computer games. Each game has a unique identifier (ID) of string data type.
The procedure ReadData() reads the data from the text file and inserts each item of data
into the array Queue.
Copy and paste the program code into part 2(b) in the evidence document.
[6]
(c) Some game IDs appear in the text file more than once.
The program needs to total the number of times each game ID appears in the text file.
Copy and paste the program code into part 2(c)(i) in the evidence document.
[2]
The global variable NumberRecords stores the number of records currently in the array
Records and is initialised to 0.
Copy and paste the program code into part 2(c)(ii) in the evidence document.
[2]
PROCEDURE TotalData()
DECLARE DataAccessed : STRING
DECLARE Flag : BOOLEAN
DataAccessed ← Dequeue()
Flag ← FALSE
IF NumberRecords = 0 THEN
Records[NumberRecords].ID ← DataAccessed
Records[NumberRecords].Total ← 1
Flag ← TRUE
NumberRecords ← NumberRecords + 1
ELSE
FOR X ← 0 TO NumberRecords - 1
IF Records[X].ID = DataAccessed THEN
Records[X].Total ← Records[X].Total + 1
Flag ← TRUE
ENDIF
NEXT X
ENDIF
IF Flag = FALSE THEN
Records[NumberRecords].ID ← DataAccessed
Records[NumberRecords].Total ← 1
NumberRecords ← NumberRecords + 1
ENDIF
ENDPROCEDURE
Copy and paste the program code into part 2(c)(iii) in the evidence document.
[5]
(d) The procedure OutputRecords() outputs the ID and total of each record in Records in the
format:
ID 1234 Total 4
Copy and paste the program code into part 2(d) in the evidence document.
[1]
• call ReadData()
• call TotalData() for each element in the queue
• call OutputRecords().
Copy and paste the program code into part 2(e)(i) in the evidence document.
[2]
Copy and paste the screenshot into part 2(e)(ii) in the evidence document.
[1]
The game has multiple characters that can move around the screen.
The class Character stores data about the characters. Each character has a name, a current X
(horizontal) position and a current Y (vertical) position.
Character
Name : STRING stores the name of the character as a string
(a) (i) Write program code to declare the class Character and its constructor.
Copy and paste the program code into part 3(a)(i) in the evidence document.
[4]
(ii) The get methods GetXPosition() and GetYPosition() each return the relevant
attribute.
Copy and paste the program code into part 3(a)(ii) in the evidence document.
[3]
(iii) The set methods SetXPosition() and SetYPosition() each take a value as a
parameter and add this to the current X or Y position.
Copy and paste the program code into part 3(a)(iii) in the evidence document.
[4]
(iv) The method Move() takes a string parameter: "up", "down", "left" or "right".
The table shows the change each direction will make to the X or Y position.
Copy and paste the program code into part 3(a)(iv) in the evidence document.
[4]
(b) Write program code to declare a new instance of Character with the identifier Jack.
The starting X position is 50 and the starting Y position is 50, the character’s name is Jack.
Copy and paste the program code into part 3(b) in the evidence document.
[2]
© UCLES 2023 9618/41/O/N/23 [Turn over
10
BikeCharacter
(i) Write program code to declare the class BikeCharacter and its constructor.
Copy and paste the program code into part 3(c)(i) in the evidence document.
[3]
(ii) The method Move() overrides the method from the parent class.
The table shows the change each direction will make to the X or Y position.
up Y position + 20
down Y position − 20
left X position − 20
right X position + 20
Copy and paste the program code into part 3(c)(ii) in the evidence document.
[2]
(d) Write program code to declare a new instance of BikeCharacter with the identifier Karla.
The starting X position is 100, the starting Y position is 50 and the character’s name is Karla.
Copy and paste the program code into part 3(d) in the evidence document.
[1]
• take as input which of the two characters the user would like to move
• take as input the direction the user would like the character to move
• call the appropriate method to move the character
• output the character’s new X and Y position in an appropriate format, for example:
"Karla's new position is X = 100 Y = 200"
Copy and paste the program code into part 3(e)(i) in the evidence document.
[5]
Copy and paste the screenshot into part 3(e)(ii) in the evidence document.
[2]
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.