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

10 questions

0 / 0Answer a question to start your score.
New quizSaved 0

Quick quiz: 10 random questions from this topic. Answer them all, then open the Summary.

Advertisement
1
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

2
9618/42/O/N/25 · Question 1Oct/Nov 2025Paper 4228 marks
Loading question…
Question text

1
A program stores data about birds using Object-Oriented Programming (OOP).
The class Bird stores the data about the birds:
Bird
DistancePerHour : Real
stores the number of kilometres per hour (km/h) the bird
can fly (between 0.0 and 100.0 inclusive)
Species : String
stores the species of the bird, for example Pigeon
XPosition : Real
stores the current horizontal position of the bird
YPosition : Real
stores the current vertical position of the bird
Constructor()
initialises Species and DistancePerHour to the
parameter values; initialises XPosition and YPosition
to 500.0
GetPosition()
returns a string message that contains the horizontal and
vertical position of the bird
GetSpecies()
returns the species of the bird
Move()
takes a direction and number of minutes flying (between
0 and 500 inclusive) as parameters and updates the
appropriate horizontal or vertical position
Write program code to declare the class Bird and its constructor.
(a) (i)
Do not declare the other methods.
All attributes should be private.
Use your programming language appropriate constructor.
If you are writing in Python, include attribute declarations using comments.
Save your program as Question1_N25.
Copy and paste the program code into part 1(a)(i) in the evidence document.
[4]
The method GetSpecies() returns the species of the bird.
(ii)
Write program code for GetSpecies()
Save your program.
Copy and paste the program code into part 1(a)(ii) in the evidence document.
[2]
The method GetPosition() returns a string of the bird’s data in the format:
(iii)
"X = " & <XPosition> & " Y = " & <YPosition>
An example string for a bird is:
X = 500.0 Y = 250.0
Write program code for GetPosition()
Save your program.
Copy and paste the program code into part 1(a)(iii) in the evidence document.
[3]
(iv)
If the bird is travelling north, the vertical position increases. If the bird is travelling south,
the vertical position decreases.
If the bird is travelling east, the horizontal position increases. If the bird is travelling west,
the horizontal position decreases.
The method Move():
•
takes the direction of travel as a parameter in the form ‘N’ for north, ‘S’ for south,
‘E’ for east or ‘W’ for west
•
takes the number of minutes that the bird has been flying (to the nearest minute) as
a parameter
•
calculates the distance travelled by the bird using the formula:
distance travelled = (distance per hour / 60) * minutes flying
•
updates the vertical or horizontal position using the distance calculated.
You do not need to validate the parameters.
Write program code for Move()
Save your program.
Copy and paste the program code into part 1(a)(iv) in the evidence document.
[5]
(b) The main program creates two instances of Bird
The first bird is the species ‘Cockatiel’ and flies 71.0 km/h.
The second bird is the species ‘Macaw’ and flies 56.0 km/h.
Write program code to declare and initialise the two birds.
Save your program.
Copy and paste the program code into part 1(b) in the evidence document.
[3]
(c) (i)
The main program needs to:
•
output a message that includes the species and current X position and Y position for
each bird
•
prompt the user to select one of the birds to move and take this as an input
•
prompt the user to enter the direction the bird has been travelling and take this as
an input
•
prompt the user to enter the time to the nearest minute that the bird has been
travelling and take this as an input
•
call the appropriate method to update the chosen bird’s position
•
output an update on the bird’s new position.
Each input needs to repeat until valid data is entered. All outputs must be meaningful.
Write program code to amend the main program.
Save your program.
Copy and paste the program code into part 1(c)(i) in the evidence document.
[8]
(ii)
Test your program four times to meet these criteria:
Test 1: The Cockatiel travels north for 60 minutes.
Test 2: The Macaw travels south for 30 minutes.
Test 3:

3
9618/33/M/J/24 · Question 8May/June 2024Paper 338 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
4
9618/42/O/N/24 · Question 1Oct/Nov 2024Paper 4229 marks
Loading question…
Question text

1
A computer game is designed for users to select characters. Each character can take part in a
group of events. Each group has five events. There are four types of event: jump, swim, run, drive.
The program is written using object-oriented programming.
(a) The class EventItem stores data about the events.
EventItem
EventName : STRING
stores the name of the event
Type : STRING
stores the type of event, either: jump, swim, run or drive
Difficulty : INTEGER
stores the difficulty of the event from 1 (easiest) to 5
(hardest)
Constructor()
initialises EventName, Type and Difficulty to its
parameter values
GetName()
returns the name of the event
GetDifficulty()
returns the difficulty of the event
GetEventType()
returns the type of event
Write program code to declare the class EventItem and its constructor.
(i)
Do not declare the other methods.
Use your programming language’s appropriate constructor.
All attributes must be private.
If you are writing in Python, include attribute declarations, using comments.
Save your program as Question1_N24.
Copy and paste the program code into part 1(a)(i) in the evidence document.
[4]
The get methods GetName(), GetDifficulty() and GetEventType() each return
(ii)
the relevant attribute.
Write program code for the three get methods.
Save your program.
Copy and paste the program code into part 1(a)(ii) in the evidence document.
[3]
(b) The array Group stores five objects of type EventItem.
Write program code to declare Group local to the main program.
(i)
Save your program.
Copy and paste the program code into part 1(b)(i) in the evidence document.
[1]
(ii)
One group has the following events:
Event name
Event type
Event difficulty
Bridge
jump
3
Water wade
swim
4
100 mile run
run
5
Gridlock
drive
2
Wall on wall
jump
4
Write program code to create an instance of EventItem for each of the five events, and
store them in Group.
Save your program.
Copy and paste the program code into part 1(b)(ii) in the evidence document.
[3]
(c) The class Character stores data about the characters in the game.
Each character has a skill level for each type of event. The skill level is an integer between
1 and 5 inclusive. Skill level 1 is the lowest skill level, and skill level 5 is the highest skill level.
Character
CharacterName : STRING
stores the name of the character
Jump : INTEGER
stores the character’s skill level at events of type jump
Swim : INTEGER
stores the character’s skill level at events of type swim
Run : INTEGER
stores the character’s skill level at events of type run
Drive : INTEGER
stores the character’s skill level at events of type drive
Constructor()
initialises CharacterName, Jump, Swim, Run and
Drive to its parameter values
GetName()
returns the name of the character
CalculateScore()
takes the type of event and difficulty as parameters.
Calculates and returns the chance of the character
completing the event
Write program code to declare the class Character, its constructor and get method.
Use your programming language’s appropriate constructor.
All attributes must be private.
If you are writing in Python, include attribute declarations, using comments.
Save your program.
Copy and paste the program code into part 1(c) in the evidence document.
[4]
(d) The method CalculateScore() in the Character class calculates and returns the
percentage chance of a character completing an event.
When a character’s skill level is greater than or equal to the difficulty of that event, the
percentage chance of completing the event is 100%.
When a character’s skill level is less than the difficulty of that event, the character’s skill level
is subtracted from the difficulty of that event. This difference is used to identify the percentage
chance of success using this table:
Percentage chance
Difference
of success
1
80
2
60
3
40
4
20
For example:
•
A character has a skill level of 3 for events of type run.
•
An event of type run has a difficulty level of 5
•
The

5
9618/31/O/N/25 · Question 10Oct/Nov 2025Paper 313 marks
Loading question…
Question text

10 Explain what is meant by exception handling.
Include an example of a possible cause of an exception in your answer.
Explanation …
…
…
…
Example …
[3]
ĬÙú¾Ġ´íÈõÏĪÅĊàû·þ×

6
9618/31/M/J/22 · Question 2May/June 2022Paper 316 marks
Loading question…
Question text

2
A declarative language is used to represent the following facts about cats.
01
type(leopard, wild).
02
type(lion, wild).
03
type(cheetah, wild).
04
type(savannah, hybrid).
05
type(persian, domestic).
06
07
hair(leopard, medium).
08
hair(lion, short).
09
hair(cheetah, medium).
10
hair(savannah, medium).
11
hair(persian, long).
12
13
spots(leopard, yes).
14
spots(lion, no).
15
spots(cheetah, yes).
16
spots(savannah, yes).
17
spots(persian, no).
These clauses have the following meaning:
Clause
Meaning
01
A leopard is a type of wild cat.
08
A lion has short hair.
16
A savannah has spots.
(a) More facts are to be included. A caracal is a wild cat with short hair.
Write the additional clauses to record these facts.
18 …
19 …
[2]
(b) Using the variable Cat, the goal:
hair(Cat, medium)
returns
Cat = leopard, cheetah, savannah
Write the result returned by the goal:
hair(Cat, long)
Cat = … [1]
(c) (i)
Write the goal, using the variable Pet, to find all the domestic cats.
…
… [1]
(ii)
Write the goal, using the variable WildSpotty, to find all the wild cats with spots.
…
…
…
… [2]

7
9618/31/M/J/21 · Question 9May/June 2021Paper 318 marks
Loading question…
Question text

9
(a) Describe what is meant by an imperative (procedural) programming language.
…
…
…
… [2]
(b) Describe what is meant by a declarative programming language.
…
…
…
… [2]
(c) Identify the programming paradigm for each of these program code examples.
Program code example
Programming paradigm
male(john).
female(ethel).
parent(john, ethel).
FOR Counter = 1 TO 20
X = X * Counter
NEXT Counter
Start: LDD Counter
INC ACC
STO Counter
public class Vehicle
{
private speed;
public Vehicle()
{
speed = 0;
}
}
[4]
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 the Cambridge Assessment Group. Cambridge Assessment is the brand name of the University of

8
9618/33/O/N/24 · Question 3Oct/Nov 2024Paper 335 marks
Loading question…
Question text

3
(a) Describe circuit switching as a method of data transmission.
…
…
…
…
…
… [3]
(b) State one benefit and one drawback of circuit switching as a method of data transmission.
Benefit …
…
Drawback …
…
[2]
ĬÏĊ®Ġ´íÈõÏĪÅĊÝû¸þ×

Advertisement
9
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]

10
9618/43/O/N/25 · Question 1Oct/Nov 2025Paper 4331 marks
Loading question…
Question text

1
A program stores data for a board game using Object-Oriented Programming (OOP). The game
has objects that are placed on the board. Each object has a string code (for example "A") and an
integer value (for example, 2).
The class BoardObject stores the data about the objects that can be placed on the board:
BoardObject
Code : String
stores the board object’s code
Value : Integer
stores the integer value of the board object
Constructor()
initialises the attributes to the parameter values
GetCode()
returns Code
GetValue()
returns Value
Write program code to declare the class BoardObject 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 Question1_N25.
Copy and paste the program code into part 1(a)(i) in the evidence document.
[5]
The methods GetCode() and GetValue() return the appropriate attribute.
(ii)
Write program code for GetCode() and GetValue()
Save your program.
Copy and paste the program code into part 1(a)(ii) in the evidence document.
[3]
(iii)
The table shows the code and value of five board objects. The table has the variable
identifier where each of the objects are stored.
Variable
Code
Value
identifier
Object1
"A"
2
Object2
"B"
3
Object3
"C"
5
Object4
"D"
2
Object5
"E"
7
Write program code for the main program to instantiate each of the five board objects
and store them in the variables with the identifiers given.
Save your program.
Copy and paste the program code into part 1(a)(iii) in the evidence document.
[3]
(b) The board objects are placed on a board that is represented by a 0-indexed 2D array:
•
the board is a 10 x 10 grid
•
each position on the board is identified by a row and column number
•
rows are numbered 0 to 9
•
columns are numbered 0 to 9
•
board objects can be placed at a row and column position
•
each board position is initialised with an empty BoardObject, an empty BoardObject
has Code = "-" and Value = 0
For example, the element highlighted in the given board is in row 1 and column 3.
Row
Column
0
1
2
3
4
5
6
7
8
9
0
1
2
3
4
5
6
7
8
9
The class Board stores the data about the board and where the board objects are placed.
Board
TheBoard : ARRAY[0:9, 0:9] of BoardObject
stores the board contents as a 2D array of
10 x 10 elements of type BoardObject
Constructor()
initialises each of TheBoard elements to
an empty BoardObject with Code = "-"
and Value = 0
GetObject()
takes a row and column number as
parameters and returns the BoardObject
at the row, column position
SetObject()
takes a BoardObject, row number and
column number as parameters. Stores the
BoardObject in TheBoard at the given
row, column position
DisplayBoard()
outputs the code of each BoardObject
stored in TheBoard, one row at a time
Write program code to declare the class Board 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 1(b)(i) in the evidence document.
[4]
The method GetObject() takes a row number and column number as parameters.
(ii)
The method returns the BoardObject stored at the parameter position.
Write program code for GetObject()
Save your program.
Copy and paste the program code into part 1(b)(ii) in the evidence document.
[2]
The method SetObject() takes three parameters: a BoardObject, row number and
(iii)
column number.
The method stores the BoardObject parameter in the row, column position in
TheBoard
Write program code for SetObject()
Save your program.
Copy and paste the program code into part 1(b)(iii) in the evidence document.
[2]
The method DisplayBoard() outputs the Code of each BoardObject stored in
(iv)
TheBoard using GetCode()
Each row in TheBoard is output on one li

Advertisement