Cambridge International AS & A Level: Computer Science 9618/42
Cambridge International AS & A Level: Computer Science 9618/42
2 hours 30 minutes
evidence.doc
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 (PQ/CGW) 329377/3
© UCLES 2024 [Turn over
2
Make sure that your name, centre number and candidate number will appear on every page of this
document. This document must contain your answers to each question.
A class declaration can be used to declare a record. If the programming language used does not
support arrays, a list can be used instead.
Three source files are used to answer Question 1. The files are called Easy.txt, Medium.txt and
Hard.txt
1 A program outputs a main word. The program asks the user to enter the different words of 3 or
more letters that can be made from the letters in the main word. These are called the answers.
There are 3 files: Easy.txt, Medium.txt and Hard.txt. Each file has the main word on the
first line. For example, the main word in Easy.txt is house.
The answers are stored in the file. Each answer is on a new line after the main word. For example,
Easy.txt has 14 answers that can be made from the letters in house.
The words read from the text file are stored in the global array WordArray. The number of words
that can be made from the letters in the main word is stored in the global variable NumberWords.
Copy and paste the program code into part 1(a) in the evidence document.
[6]
(b) The main program asks the user to enter "easy", "medium" or "hard" and calls
ReadWords()with the filename that matches the user’s input. For example, if the user enters
"easy", the parameter is "Easy.txt".
Copy and paste the program code into part 1(b) in the evidence document.
[4]
• outputs the main word from the array and the number of answers
• allows the user to enter words until they enter the word ‘no’ to indicate they want to
stop
• outputs whether each word the user enters is an answer or not an answer
• counts the number of answers the user gets correct
• replaces each answer that the user gets correct with a null value in the array.
Copy and paste the program code into part 1(c)(i) in the evidence document.
[6]
(ii) Amend the procedure Play()so that when the user enters the command to stop, the
procedure:
• outputs the percentage of answers the user entered from the array
• outputs all the answers that the user did not enter.
Copy and paste the program code into part 1(c)(ii) in the evidence document.
[3]
(d) (i) The procedure ReadWords()calls Play()after the data in the file has been read.
Copy and paste the program code into part 1(d)(i) in the evidence document.
[1]
(ii) Test your program by inputting these words in the order shown:
easy
she
out
no
Copy and paste the screenshot into part 1(d)(ii) in the evidence document.
[1]
(iii) Test your program by inputting these words in the order shown:
hard
fine
fined
idea
no
Copy and paste the screenshot into part 1(d)(iii) in the evidence document.
[1]
BLANK PAGE
15
8 19
3 10
A computer program stores integers in a binary tree in ascending order. The program uses
Object‑Oriented Programming (OOP).
The binary tree is stored as a 1D array of nodes. Each node contains a left pointer, a data value
and a right pointer.
Node
LeftPointer : INTEGER stores the index of the node to the left in the binary tree
RightPointer : INTEGER stores the index of the node to the right in the binary tree
Constructor() initialises Data to its parameter value
initialises LeftPointer and RightPointer to −1
(a) (i) Write program code to declare the class Node and its constructor.
Copy and paste the program code into part 2(a)(i) in the evidence document.
[4]
© UCLES 2024 9618/42/M/J/24
7
(ii) The get methods GetLeft(), GetRight()and GetData()each return the relevant
attribute.
Copy and paste the program code into part 2(a)(ii) in the evidence document.
[3]
(iii) The set methods SetLeft(), SetRight()and SetData()each take a parameter and
then store this in the relevant attribute.
Copy and paste the program code into part 2(a)(iii) in the evidence document.
[3]
(b) The class TreeClass stores the data about the binary tree.
TreeClass
Tree[0:19] : Node an array of 20 elements of type Node
FirstNode : INTEGER stores the index of the first node in the tree
OutputTree() outputs the left pointer, data and right pointer of each
node in Tree
(i) Write program code to declare the class TreeClass and its constructor.
Copy and paste the program code into part 2(b)(i) in the evidence document.
[4]
© UCLES 2024 9618/42/M/J/24 [Turn over
8
(ii) The method InsertNode()takes a Node object, NewNode, as a parameter and inserts
it into the array Tree.
Copy and paste the program code into part 2(b)(ii) in the evidence document.
[6]
(iii) The method OutputTree()outputs the left pointer, the data and the right pointer for
each node that has been inserted into the tree. The outputs are in the order they are
saved in the array.
If there are no nodes in the array, the procedure outputs ‘No nodes’.
Copy and paste the program code into part 2(b)(iii) in the evidence document.
[4]
(c) (i) The main program declares an instance of TreeClass with the identifier TheTree.
Copy and paste the program code into part 2(c)(i) in the evidence document.
[1]
(ii) The main program inserts the following integers into the binary tree in the order given:
10
11
20
15
Copy and paste the program code into part 2(c)(ii) in the evidence document.
[4]
Copy and paste the screenshot into part 2(c)(iii) in the evidence document.
[1]
3 A program sorts an array of integers and searches the array for a particular value.
(a) The array of integers, NumberArray, stores the following data in the order given:
100 85 644 22 15 8 1
Copy and paste the program code into part 3(a) in the evidence document.
[1]
(b) (i) The following recursive pseudocode function sorts the array into ascending order using
an insertion sort and returns the sorted array.
Copy and paste the program code into part 3(b)(i) in the evidence document.
[4]
Copy and paste the program code into part 3(b)(ii) in the evidence document.
[2]
Copy and paste the screenshot into part 3(b)(iii) in the evidence document.
[1]
(i) Write program code for the function IterativeInsertion()to perform the same
processes as RecursiveInsertion()but using iteration instead of recursion.
Copy and paste the program code into part 3(c)(i) in the evidence document.
[4]
Copy and paste the program code into part 3(c)(ii) in the evidence document.
[1]
Copy and paste the screenshot into part 3(c)(iii) in the evidence document.
[1]
The function uses recursion to perform a binary search for ToFind in IntegerArray.
The function returns the index where ToFind is stored or returns −1 if ToFind is not in the
array.
Copy and paste the program code into part 3(d)(i) in the evidence document.
[6]
• call BinarySearch()with the sorted array and the integer 644 as the search value
• output ‘Not found’ if 644 is not found in the array
• output the index if 644 is found in the array.
Copy and paste the program code into part 3(d)(ii) in the evidence document.
[2]
Copy and paste the screenshot into part 3(d)(iii) in the evidence document.
[1]
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.