Further programming: paradigms, OOP, files and exceptions – A Level Computer Science (9618)

33 questions · page 1 of 3 · Clear filters

0 / 0Answer a question to start your score.
Quick quiz (10)Saved 0
Advertisement
1
9618/31/M/J/26 · Question 11May/June 2026Paper 318 marks
Loading question…
Question text

11
A declarative programming language is used to show which home cinema devices customers
already have and which devices they want.
01
device(projector).
02
device(large_tv).
03
device(medium_tv).
04
device(bluray_player).
05
device(amplifier).
06
device(media_player).
07
device(main_speakers).
08
device(centre_speaker).
09
device(surround_speakers).
10
customer(petrov).
11
customer(margaret).
12
customer(steffan).
13
customer(susan).
14
customer(allan).
15
customer(sammy).
16
owns(projector, petrov).
17
owns(media_player, petrov).
18
owns(projector, susan).
19
owns(projector, sammy).
20
owns(media_player, allan).
21
owns(bluray_player, steffan).
22
wants(main_speakers, margaret).
23
wants(surround_speakers, susan).
24
wants(medium_tv, steffan).
These facts (clauses) have the meanings:
fact
meaning
01
A projector is a device.
10
Petrov is a customer.
16
Petrov owns a projector.
22
Margaret wants main speakers.
(a) Betty is a customer who owns a large TV and wants a Blu‑ray player.
Write additional facts to represent this information.
25 …
26 …
27 …
[3]
© Cambridge University Press & Assessment 2026
,
,
(b) Using the variable Owner, the goal:
owns(media_player, Owner)
returns
Owner = petrov, allan
Write the result of using the goal:
owns(projector, Owner)
Owner = … [1]
(c) D may be available for A to buy if D is a device and A is a customer and A does not own
that device.
Write this as a rule:
may_buy_device(D, A)
IF …
…
…
… [4]
© Cambridge University Press & Assessment 2026
,
,
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 (Cambridge University Press & Assessment) 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 our 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 International Education is the name of our awarding body and a part of Cambridge University Press & Assessment, which is a department of the
University of Cambridge.
© Cambridge University Press & Assessment 2026

2
9618/32/M/J/26 · Question 11May/June 2026Paper 329 marks
Loading question…
Question text

11
(a) Object-Oriented Programming (OOP) is used to design a class called Node.
A partial design of the Node class includes the STRING attribute Content and the INTEGER
attribute Pointer, together with their getters and setters.
The class also includes a constructor, with two parameters, to set the values of
these attributes.
Write pseudocode statements to declare the Node class, its attributes and the constructor.
…
…
…
…
…
…
…
…
…
… [5]
© Cambridge University Press & Assessment 2026
,
,
(b) Complete the table by filling in the missing OOP terms and descriptions.
OOP term
description
A method used to change values in private attributes in
…
a class.
…
An occurrence of a class during the execution of a program.
…
aggregation
…
…
…
inheritance
…
…
[4]
© Cambridge University Press & Assessment 2026
,
,
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 (Cambridge University Press & Assessment) 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 our 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 International Education is the name of our awarding body and a part of Cambridge University Press & Assessment, which is a department of the
University of Cambridge.
© Cambridge University Press & Assessment 2026

3
9618/41/M/J/26 · Question 3May/June 2026Paper 4121 marks
Loading question…
Question text

3
A prototype for a game is designed using Object‑Oriented Programming (OOP).
The game will allow a character to move along a path (for example a road or sidewalk).
The prototype requires the classes setting up and the path creating ready for the character to
be implemented.
(a) Each space in the path can contain an object. The path and objects are created as classes.
The class TheObject stores the data about the objects. The attributes are public.
TheObject
ObjectType : String
stores the type of object, either "Money" or "Experience"
Amount : Integer
stores the amount of the object, for example 200
Constructor()
initialises the attributes to the parameter values
The class Path stores the data about the objects. The attributes are public.
Path
BoardArray[0:99] : TheObject
an array of 100 objects of type TheObject
NumberSpaces : Integer
stores the number of spaces in the path
Constructor()
initialises NumberSpaces to the parameter value.
Initialises all 100 array objects to an empty object of type
TheObject. An empty object has the values
ObjectType = "" and Amount = –1
GetNumberSpaces()
returns NumberSpaces
InitialiseData()
takes an array of objects of type TheObject as a
parameter and stores them in BoardArray
ReturnPath()
returns a string created using data from each object
in BoardArray
GetPathObject()
takes a number as a parameter and returns the object in
that index in BoardArray
Write program code to declare the class TheObject and its constructor.
(i)
Use your programming language appropriate constructor.
If you are writing in Python, include attribute declarations using comments.
Save your program as Question3_J26.
Copy and paste the program code into 3(a)(i) in the evidence document.
[4]
© Cambridge University Press & Assessment 2026
Write program code to declare the class Path, its constructor and
(ii)
method GetNumberSpaces()
Use your programming language appropriate constructor.
Do not declare the other methods.
If you are writing in Python, include attribute declarations using comments.
Save your program.
Copy and paste the program code into 3(a)(ii) in the evidence document.
[4]
The method InitialiseData() takes an array of type TheObject as a parameter.
(iii)
The method stores each element from the parameter array into the array BoardArray
in the same order.
If there are more objects in the parameter array than in NumberSpaces, the method
does not store the data and returns FALSE. Otherwise, it returns TRUE
Write program code for InitialiseData()
Save your program.
Copy and paste the program code into 3(a)(iii) in the evidence document.
[3]
The method ReturnPath() creates and returns a string containing the type and
(iv)
amount of each object that is not a null object in BoardArray, in the format:
<ObjectType>-<Amount>
For example, an array with two not null objects produces the string:
Money-100 Experience-50
You can assume that there will always be an object that is not null in BoardArray
Write program code for ReturnPath()
Save your program.
Copy and paste the program code into 3(a)(iv) in the evidence document.
[2]
© Cambridge University Press & Assessment 2026
The method GetPathObject() takes an integer index as a parameter and returns the
(v)
object at the parameter index in BoardArray
Write program code for GetPathObject()
Save your program.
Copy and paste the program code into 3(a)(v) in the evidence document.
[1]
(b) (i)
Write program code for the main program to:
•
create a new array, ArrayOfObjects, of type TheObject with five spaces
•
store the following objects in each space in ArrayOfObjects in the order given:
money with amount 50
experience with amount 100
money with amount 200
money with amount 20
experience with amount 30
•
create a new object, Path1, of type Path with five spaces
•
call InitialiseData() for Path1 with ArrayOfObjects
•
call ReturnPath() for Path1 and output the return value.
Save your program.
Copy and paste the program code into 3(b)(i)

Advertisement
4
9618/42/M/J/26 · Question 2May/June 2026Paper 4230 marks
Loading question…
Question text

2
A program stores data about avatars in a program using Object‑Oriented Programming (OOP).
An avatar is a character that a user can control in a game.
The class Avatar stores the data about avatars.
Avatar
TheName : String
stores the name of the avatar
Glasses : Boolean
stores TRUE if the avatar wears glasses
stores FALSE if the avatar does not wear glasses
Hair : String
stores the colour of the avatar's hair
Age : Integer
stores the age of the avatar
Constructor()
initialises all attributes to its parameter values
GetName()
returns the name of the avatar
GetAge()
returns the age of the avatar
MeetCriteria()
takes the glasses choice and hair choice as parameters
and returns whether the avatar matches the choices
Write program code to declare the class Avatar and its constructor. All attributes must
(a) (i)
be private.
Do not declare the other methods.
Use your programming language appropriate constructor.
If you are writing in Python, include attribute declarations using comments.
Save your program as Question2_J26.
Copy and paste the program code into 2(a)(i) in the evidence document.
[4]
The get methods GetName() and GetAge() each return the relevant attribute.
(ii)
Write program code for GetName() and GetAge()
Save your program.
Copy and paste the program code into 2(a)(ii) in the evidence document.
[3]
© Cambridge University Press & Assessment 2026
The method MeetCritera() takes two parameters:
(iii)
•
a Boolean value to identify whether the avatar wears glasses
•
a string value to identify the hair colour.
The method checks whether this avatar’s attributes match both of the parameters.
Boolean TRUE is returned when both of the attributes match the parameters, otherwise
Boolean FALSE is returned.
Write program code for MeetCriteria()
Save your program.
Copy and paste the program code into 2(a)(iii) in the evidence document.
[2]
The text file AvatarFile.txt stores data for 30 avatars. Each avatar is on a new line
(b) (i)
in the file. The data is stored in the order: name, glasses, hair colour, age. Each value is
separated by a space.
For example, the first line in the file is:
Kit True blonde 21
The name of the avatar is Kit, the avatar wears glasses, the avatar has blonde hair, the
avatar is 21 years old.
The procedure LoadAvatars() reads the data from the text file into the program. The
function creates a new object for each avatar in the file and stores the avatar objects in
a global array with the identifier AvailableAvatars
The procedure uses exception handling when opening and reading from the file.
Write program code for LoadAvatars()
Save your program.
Copy and paste the program code into 2(b)(i) in the evidence document.
[7]
Write program code for the main program to call LoadAvatars()
(ii)
Save your program.
Copy and paste the program code into 2(b)(ii) in the evidence document.
[1]
© Cambridge University Press & Assessment 2026
The procedure EnterChoices() prompts the user to enter whether they want an
(c) (i)
avatar that wears glasses and the hair colour they want.
The procedure takes these two values as input until they are valid:
•
wearing glasses can only be yes or no
•
the hair colour can be black, blonde, brown, pink, red or green.
The procedure calls the method MeetCriteria() for each avatar in
AvailableAvatars and stores the avatars that match the criteria in a global array.
Write program code for EnterChoices()
Save your program.
Copy and paste the program code into 2(c)(i) in the evidence document.
[6]
(ii)
Write program code to extend the main program to:
•
call EnterChoices()
•
output the quantity of avatars that match the criteria
•
output the name and age of each avatar that matches the criteria.
All outputs must include an appropriate message.
Save your program.
Copy and paste the program code into 2(c)(ii) in the evidence document.
[5]
© Cambridge University Press & Assessment 2026
(d) (i)
Test your program with the following data as input:

5
9618/43/M/J/26 · Question 2May/June 2026Paper 4329 marks
Loading question…
Question text

2
A prototype for a game is being developed using Object‑Oriented Programming (OOP).
The game has a set of characters that have data stored about their characteristics, for example
if the character can fly or not fly. A user has to select their requirements, for example a character
that can fly, and the program will output the characters that meet the user’s requirements.
The class Character stores the data about the characters. The attributes are public.
Character
CharacterName : String
stores the character’s name
Colour : String
stores the colour of the character, for
example "Green"
SuperStrength : String
stores whether the character has super strength
("Yes") or not ("No")
Fly : String
stores whether the character can fly ("Yes") or
not ("No")
Invisible : String
stores whether the character can become
invisible ("Yes") or not ("No")
Constructor()
initialises the attributes to its parameter values
GetCharacterName()
returns CharacterName
GetColour()
returns Colour
GetSuperStrength()
returns SuperStrength
GetFly()
returns Fly
GetInvisible()
returns Invisible
Write program code to declare the class Character and its constructor.
(a) (i)
Use your programming language appropriate constructor.
If you are writing in Python, include attribute declarations using comments.
Save your program as Question2_J26.
Copy and paste the program code into 2(a)(i) in the evidence document.
[4]
© Cambridge University Press & Assessment 2026
The get methods GetCharacterName(), GetColour(), GetSuperStrength(),
(ii)
GetFly() and GetInvisible() each return the appropriate attribute.
Write program code for GetCharacterName(), GetColour(),
GetSuperStrength(), GetFly() and GetInvisible()
Save your program.
Copy and paste the program code into 2(a)(ii) in the evidence document.
[3]
(b) The text file Characters.txt stores data about 15 characters. Each character is on a new
line in the file. The data is stored in the order: Character name, colour, super strength, fly,
invisible. Each value is separated by a comma.
For example, the first line in the file is:
Jet,Black,Yes,No,No
The name of the character is Jet. The colour of the character is Black. The character has
super strength. The character cannot fly. The character cannot become invisible.
The function ReadData():
•
opens the file Characters.txt and reads in the data
•
creates a new Character object for each character in the file
•
stores each Character object in a local array
•
returns the populated array.
The function uses exception handling when opening and reading from the file.
Write program code for ReadData()
Save your program.
Copy and paste the program code into 2(b) in the evidence document.
[7]
© Cambridge University Press & Assessment 2026
(c) The procedure OutputCharacters() takes an array of Character objects as a
parameter. The procedure outputs the data for each character on a new line, in the format:
Name: <Character name> Colour: <Colour> Super strength: <Super
strength> Fly: <Fly> Invisible: <Invisible>
For example:
Name: Jet Colour: Black Super strength: Yes Fly: No Invisible: No
Write program code for OutputCharacters()
Save your program.
Copy and paste the program code into 2(c) in the evidence document.
[3]
The main program calls ReadData() and then OutputCharacters() with the
(d) (i)
returned array.
Write program code for the main program.
Save your program.
Copy and paste the program code into 2(d)(i) in the evidence document.
[2]
(ii)
Test your program
Take a screenshot of the output(s).
Save your program.
Copy and paste the screenshot into 2(d)(ii) in the evidence document.
[1]
© Cambridge University Press & Assessment 2026
(e) The main program needs to give the user two choices to limit the characters that they can
choose from. For example, they could choose to only see characters that are green and that
can fly.
(i)
The main program needs extending to:
•
prompt the user to enter two criteria and take both as input.

6
9618/31/M/J/25 · Question 11May/June 2025Paper 318 marks
Loading question…
Question text

11
(a) A medical centre uses objects of the class Appointment to record treatments given and
medication prescribed during each doctor’s appointment. Some of the attributes required in
the class are listed in the table.
Attribute
Data type
Description
DateSeen
DATE
date of treatment
Treatments
STRING
treatments given
Medications
STRING
medications prescribed
Patients are identified by a unique 8-digit number, beginning with the patient’s year of birth,
for example, 20108989.
Doctors are identified by their name, for example, A N Other.
Complete the class diagram for Appointment, to include:
•
attribute and data type for the identification of the patient
•
attribute and data type for the identification of the doctor
•
methods to assign date seen, treatments given and medications prescribed
•
method to return the date seen and the attributes for the patient and the doctor.
Appointment
DateSeen
: DATE
… : …
… : …
Treatments
: STRING
Medications
: STRING
…
SetPatientID(PatientNumber : INTEGER)
SetDoctor(DoctorID : STRING)
…
…
…
…
…
GetTreatments()
GetMedications()
[5]
ĬÑĊ®Ġ´íÈõÏĪÅĊÞû¸Ā×
,
,
(b) (i)
Identify the object-oriented programming (OOP) feature whose function includes
restricting external access to the data.
… [1]
(ii)
Describe what is meant by the OOP feature inheritance.
…
…
…
… [2]

7
9618/31/M/J/25 · Question 12May/June 2025Paper 315 marks
Loading question…
Question text

12 The pseudocode algorithm checks whether a location in a stock file StockList.dat is empty
or not. The location is given by the user. If the location is empty, a suitable message is displayed,
otherwise the item stored at that location is displayed.
Complete this file-handling pseudocode algorithm.
DECLARE Location : INTEGER
DECLARE Item : STRING
DECLARE Continue : BOOLEAN
DECLARE Answer : CHAR
TRUE
Continue
OPENFILE …
WHILE Continue
OUTPUT "Enter a location between 1 and 500: "
INPUT Location
…
GETRECORD …
IF Item = "" THEN
OUTPUT "This record is missing."
ELSE
OUTPUT "The item in stock is ", …
ENDIF
OUTPUT "Another location (Y or N)?"
INPUT Answer
IF Answer <> 'Y' THEN
FALSE
Continue
ENDIF
ENDWHILE
…
OUTPUT "End of program"
[5]
ĬÓĊ®Ġ´íÈõÏĪÅĊÞù¸Ā×
,
,
Permission to reproduce items where third-party owned material protected by copyright is included has been sought and cleared where possible. Every
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
ĬÍĊ®Ġ´íÈõÏĪÅĊßúµĄ×

8
9618/32/M/J/25 · Question 12May/June 2025Paper 328 marks
Loading question…
Question text

12 (a) A medical clinic uses objects of the class Patient to assign a priority and a doctor to a
patient. Some of the attributes required in the class are listed in the table.
Attribute
Data type
Description
PatientID
STRING
Unique identifier of the patient
Name
STRING
Patient’s full name, surname first
DoctorID
STRING
ID of doctor administering treatment
Treatment is prioritised with a numeric scale of 1 to 5.
Complete the class diagram for Patient, to include:
•
attribute and data type for the date of birth
•
attribute and data type for the priority
•
methods to assign the patient ID, priority and doctor ID
•
methods to return the patient ID, patient date of birth and the priority.
Patient
PatientID
: STRING
Name
: STRING
… : …
… : …
DoctorID
: STRING
…
SetName(FullName : STRING)
SetDateOfBirth(DOB : DATE)
…
…
…
GetName()
…
…
GetDoctorID()
[5]
ĬÑĊ®Ġ´íÈõÏĪÅĊàù¸Ā×
,
,
(b) (i)
Identify the object-oriented programming (OOP) term described as ‘an occurrence of an
object’.
… [1]
(ii)
Describe what is meant by the OOP term polymorphism.
…
…
…
… [2]

Advertisement
9
9618/32/M/J/25 · Question 13May/June 2025Paper 325 marks
Loading question…
Question text

13 The pseudocode algorithm below uses random file access to copy 50 records from a live file
CurrentResults.dat to a stored file StoredResults.dat one record at a time. It uses the
user-defined type StudentResult.
TYPE StudentResult
DECLARE LastName : STRING
DECLARE FirstName : STRING
DECLARE ExamGrade : STRING
ENDTYPE
If any grades are missing in CurrentResults.dat, the text "Missing grade" is added to the
ExamGrade field in StoredResults.dat
Complete this file handling pseudocode algorithm.
DECLARE Grade : StudentResult
DECLARE Position : INTEGER
…
OPENFILE "StoredResults.dat" FOR RANDOM
…
SEEK "CurrentResults.dat", Position
GETRECORD "CurrentResults.dat", Grade
IF Grade.ExamGrade = "" THEN
…
ENDIF
…
…
NEXT Position
CLOSEFILE "CurrentResults.dat"
CLOSEFILE "StoredResults.dat"
[5]
ĬÓĊ®Ġ´íÈõÏĪÅĊàû¸Ā×
,
,
Permission to reproduce items where third-party owned material protected by copyright is included has been sought and cleared where possible. Every
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
ĬÍĊ®Ġ´íÈõÏĪÅĊÝüµĄ×

10
9618/33/M/J/25 · Question 5May/June 2025Paper 334 marks
Loading question…
Question text

5
Complete the table by filling in the missing object-oriented programming (OOP) terms and
descriptions.
OOP term
Description
A method that accesses the value of a property.
…
A method that changes the value of a property.
…
…
Object
…
…
…
Method
…
…
[4]

11
9618/33/M/J/25 · Question 11May/June 2025Paper 335 marks
Loading question…
Question text

11
The pseudocode algorithm below allows a user to input a new stock item. The random file is
searched for the next empty location in the file and the new item is inserted there.
A suitable message is displayed if the file is full.
Complete this pseudocode.
DECLARE Location : INTEGER
DECLARE NewStock : STRING
DECLARE CurrentStock : STRING
DECLARE Stored : BOOLEAN
DECLARE Max : INTEGER
←
100000
Max
←
FALSE
Stored
←
1
Location
…
OUTPUT "Enter the new item you wish to store: "
INPUT NewStock
WHILE NOT Stored AND Location <= Max
…
GETRECORD "StockList.dat", …
IF CurrentStock = "" THEN
… "StockList.dat", NewStock
←
TRUE
Stored
ELSE
←
Location + 1
Location
ENDIF
ENDWHILE
… THEN
OUTPUT "The new item has not been stored as the file was full."
ENDIF
CLOSEFILE "StockList.dat"
[5]
ĬÓĊ®Ġ´íÈõÏĪÅĊßú¸Ā×

12
9618/41/M/J/25 · Question 3May/June 2025Paper 4130 marks
Loading question…
Question text

3
A program stores data in a binary tree that is designed using Object‑Oriented Programming
(OOP).
The tree stores data in ascending numerical order, for example:
30
20
45
1
21
33
63
The class Node stores data about the nodes.
Node
NodeData : Integer
stores the node’s integer data
LeftNode : Node
stores the node that is stored to the left of the current
node, or a null value if there is no node to the left
RightNode : Node
stores the node that is stored to the right of the current
node, or a null value if there is no node to the right
Constructor()
initialises NodeData to its parameter value; initialises
LeftNode and RightNode to a null value
GetLeft()
returns LeftNode
GetRight()
returns RightNode
GetData()
returns NodeData
SetLeft()
takes an object of type Node as a parameter and stores
it in LeftNode
SetRight()
takes an object of type Node as a parameter and stores
it in RightNode
Write program code to declare the class Node and its constructor.
(a) (i)
Do not declare the other methods.
Use your programming language appropriate constructor.
If you are writing in Python, include attribute declarations using comments.
Save your program as Question3_J25.
Copy and paste the program code into part 3(a)(i) in the evidence document.
[4]
(ii)
Write program code for the three get methods.
Save your program.
Copy and paste the program code into part 3(a)(ii) in the evidence document.
[3]
The method SetLeft() takes an object of type Node as a parameter. The method
(iii)
stores the parameter in the attribute LeftNode
The method SetRight() takes an object of type Node as a parameter. The method
stores the parameter in the attribute RightNode
Write program code for SetLeft() and SetRight()
Save your program.
Copy and paste the program code into part 3(a)(iii) in the evidence document.
[3]
(b) Write the main program to declare five objects of type Node :
•
Node 1 with the data 10
•
Node 2 with the data 20
•
Node 3 with the data 5
•
Node 4 with the data 15
•
Node 5 with the data 7
Save your program.
Copy and paste the program code into part 3(b) in the evidence document.
[2]
(c) The class Tree stores the tree.
Tree
FirstNode : Node
stores the root node in the tree
Constructor()
initialises FirstNode to its parameter value
GetRootNode()
returns the node stored in FirstNode
Insert()
stores its parameter node in the correct position in the
tree
Write program code to declare the class Tree and its constructor.
(i)
Do not declare the other methods.
Use your programming language appropriate constructor.
If you are writing in Python, include attribute declarations using comments.
Save your program.
Copy and paste the program code into part 3(c)(i) in the evidence document.
[2]
Write program code for GetRootNode()
(ii)
Save your program.
Copy and paste the program code into part 3(c)(ii) in the evidence document.
[1]
The method Insert() takes a node as a parameter and then searches the tree to find
(iii)
the position to insert the new node by:
•
checking whether the node’s data is less than or greater than the root node’s data
•
moving to the left node if the data is less than the root node’s data
•
moving to the right node if the data is greater than or equal to the root node’s data
•
repeating until the final position of the node is found and stores the node in that
position.
Write program code for Insert()
Save your program.
Copy and paste the program code into part 3(c)(iii) in the evidence document.
[6]
(d) The recursive procedure OutputInOrder() outputs the data stored in the binary tree in
ascending numerical order.
The procedure takes a Node object as a parameter and then:
•
checks if the left node is null. If there is a left node, the function calls itself with the left
node
•
outputs the data of the current node
•
checks if the right node is null. If there is a right node, the function calls itself with the
right node.
Write program code for OutputInOrder()
Save your program.
Copy an

13
9618/42/M/J/25 · Question 3May/June 2025Paper 4226 marks
Loading question…
Question text

3
A program stores data about animals using Object‑Oriented Programming (OOP).
The class Animal stores the data about animals.
Animal
Name : String
stores the name of the animal
Sound : String
stores the sound the animal makes
Size : Integer
stores the size of the animal as an integer between 1 (smallest)
and 10 (largest)
Intelligence : Integer
stores the intelligence of the animal as an integer between 1 (least)
and 10 (most)
Constructor()
initialises all attributes to its parameter values
Description()
returns a string message that contains the data from the attributes
Write program code to declare the class Animal and its constructor.
(a) (i)
Do not declare the other methods.
Use your programming language appropriate constructor.
If you are writing in Python, include attribute declarations using comments.
Save your program as Question3_J25.
Copy and paste the program code into part 3(a)(i) in the evidence document.
[4]
The method Description() creates and returns a string of the animal’s data in the
(ii)
format:
"The animal's name is " <Name> ", it makes a " <Sound> ", its size
is " <Size> " and its intelligence level is " <Intelligence>
For example:
The animal's name is Teddy, it makes a Bark, its size is 4 and its
intelligence level is 6
Write program code for Description()
Save your program.
Copy and paste the program code into part 3(a)(ii) in the evidence document.
[3]
(b) The class Parrot inherits from the class Animal
Parrot inherits the attributes from Animal and overrides the Description() method. The
additional attributes and methods in the class Parrot are:
Parrot
WingSpan : Integer
the width of the parrot’s wings to the nearest cm
NumberWords : Integer
the number of words the parrot can speak
Constructor()
calls the parent constructor using its parameter values;
initialises WingSpan and NumberWords to its parameter values
ChangeNumberWords()
takes an integer parameter and adds this to the number currently
in NumberWords
Write program code to declare the class Parrot, its constructor and the method
(i)
ChangeNumberWords()
Use your programming language appropriate constructor.
If you are writing in Python, include attribute declarations using comments.
Save your program.
Copy and paste the program code into part 3(b)(i) in the evidence document.
[4]
The method Description() in the class Parrot creates and returns a string of the
(ii)
animal’s data in the format:
"The animal's name is " <Name> ", it makes a " <Sound> ", its size
is " <Size> " and its intelligence level is " <Intelligence> ". It
has a wingspan of " <WingSpan> "cm and can say " <NumberWords> "
words."
For example:
The animal's name is Chewie, it makes a Squawk, its size is 1 and
its intelligence level is 10. It has a wingspan of 30cm and can
say 29 words.
Write program code for Description()
Save your program.
Copy and paste the program code into part 3(b)(ii) in the evidence document.
[2]
(c) The class Wolf inherits from the class Animal
Wolf inherits the attributes from Animal and overrides the Description() method. The
additional attributes and methods in the class Wolf are:
Wolf
TerritorySize : Integer
stores the size of the area where the wolf lives, to the nearest
square mile
Constructor()
calls the parent constructor using its parameter values;
initialises TerritorySize to its parameter value
SetTerritorySize()
takes an integer parameter and adds this to the number currently
in TerritorySize
Write program code to declare the class Wolf, its constructor and the method
(i)
SetTerritorySize()
Use your programming language appropriate constructor.
If you are writing in Python, include attribute declarations using comments.
Save your program.
Copy and paste the program code into part 3(c)(i) in the evidence document.
[4]
The method Description() in the class Wolf creates and returns a string of the
(ii)
animal’s data in the format:
"The animal's name is " <Name> ", it makes a " <Sound> ", its size
is " <Size

Advertisement
14
9618/43/M/J/25 · Question 3May/June 2025Paper 4329 marks
Loading question…
Question text

3
A program stores data in a linked list that is designed using Object‑Oriented Programming (OOP).
The class Node stores data about the nodes.
Node
TheData : Integer
stores the integer data
NextNode : Node
stores the next node in the linked list
Constructor()
initialises TheData to its parameter value, initialises NextNode
to a null value
GetData()
returns TheData
GetNextNode()
returns NextNode
SetNextNode()
takes an object of type Node as a parameter and stores it in
NextNode
Write program code to declare the class Node and its constructor.
(a) (i)
Do not declare the other methods.
Use your programming language appropriate constructor.
If you are writing in Python, include attribute declarations using comments.
Save your program as Question3_J25.
Copy and paste the program code into part 3(a)(i) in the evidence document.
[4]
(ii)
Write program code for the two get methods.
Save your program.
Copy and paste the program code into part 3(a)(ii) in the evidence document.
[3]
The method SetNextNode() takes an object of type Node as a parameter. The method
(iii)
stores the parameter in the attribute NextNode
Write program code for SetNextNode()
Save your program.
Copy and paste the program code into part 3(a)(iii) in the evidence document.
[2]
(b) The class LinkedList stores the linked list.
LinkedList
HeadNode : Node
stores the first node in the linked list
Constructor()
initialises HeadNode to a null value
InsertNode()
creates a new node using its integer parameter. Sets this
node as the new head node and updates NextNode
RemoveNode()
finds the first node that contains its integer parameter and
removes this node from the linked list
Traverse()
concatenates and returns the integer data in each node in
the linked list
Write program code to declare the class LinkedList and its constructor.
(i)
Do not declare the other methods.
Use your programming language appropriate constructor.
If you are writing in Python, include attribute declarations using comments.
Save your program.
Copy and paste the program code into part 3(b)(i) in the evidence document.
[2]
The method InsertNode():
(ii)
•
takes an integer as a parameter
•
creates a new node with the parameter as the integer data
•
uses the new node’s method SetNextNode() to store the current HeadNode as
the next node
•
replaces HeadNode with the current node.
Write program code for InsertNode()
Save your program.
Copy and paste the program code into part 3(b)(ii) in the evidence document.
[4]
The method Traverse() concatenates the integer data from the nodes in the linked
(iii)
list, starting with the node stored in HeadNode. The method returns the final string with
each integer data separated with a space.
Write program code for Traverse()
Save your program.
Copy and paste the program code into part 3(b)(iii) in the evidence document.
[3]
The method RemoveNode() takes an integer parameter to search for and remove from
(iv)
the linked list.
The method first checks if the linked list is empty. If the linked list is empty the method
returns FALSE
If the linked list is not empty, the integer data in HeadNode is compared to the parameter.
If it matches the parameter, HeadNode is changed to store the next node.
If the parameter does not match, the nodes are followed until either:
•
the node with matching integer data is found. This node is removed, the appropriate
nodes updated and TRUE returned
or
•
none of the nodes contain matching integer data to the parameter. No nodes are
removed and FALSE is returned.
Write program code for RemoveNode()
Save your program.
Copy and paste the program code into part 3(b)(iv) in the evidence document.
[6]
The main program creates a new LinkedList object and uses the appropriate method
(c) (i)
to insert five nodes with the following integer data values in the order given:
10
20
30
40
50
The main program then:
•
calls Traverse()
•
removes the node containing the integer data 30 using Remov

15
9618/31/M/J/24 · Question 8May/June 2024Paper 318 marks
Loading question…
Question text

8
A declarative programming language is used to represent the features that are available and the
features that are unavailable on different body styles of a car.
01
feature(sunroof).
02
feature(automatic_tailgate).
03
feature(heated_seats).
04
feature(extra_seats).
05
feature(reversing_camera).
06
feature(dashboard_camera).
07
feature(air_conditioning).
08
feature(heated_windscreen).
09
feature(satnav).
10
bodystyle(saloon).
11
bodystyle(hatchback).
12
bodystyle(estate).
13
bodystyle(minivan).
14
bodystyle(convertible).
15
available(sunroof, hatchback).
16
available(sunroof, minivan).
17
available(reversing_camera, hatchback).
18
available(extra_seats, minivan).
19
available(reversing_camera, saloon).
20
unavailable(sunroof, convertible).
21
unavailable(automatic_tailgate, saloon).
22
unavailable(extra_seats, hatchback).
These clauses have the meanings:
Clause
Meaning
01
Sunroof is a feature.
10
Saloon is a body style.
15
Sunroof is available on a hatchback.
20
Sunroof is unavailable on a convertible.
(a) Sliding doors is a feature that is available on a minivan but unavailable on a hatchback.
Write additional clauses to represent this information.
23 …
24 …
25 …
[3]
(b) Using the variable Options, the goal:
available(Options, saloon)
returns
Options = reversing_camera
Write the result returned by the goal:
available(Options, hatchback)
Options = … [1]
(c) F may be available for B if F is a feature and B is a body style and F is not unavailable for that
body style.
Write this as a rule:
may_choose_option(F, B)
IF …
…
…
… [4]

Advertisement