Further programming: paradigms, OOP, files and exceptions – A Level Computer Science (9618)
60 questions · page 3 of 4
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]
Question text
2
A computer program will store data about trees.
The user can enter their requirements for a tree and a suitable tree will be selected.
The program is written using object‑oriented programming.
The class Tree stores data about the trees.
Tree
TreeName : STRING
stores the name of the tree
HeightGrowth : INTEGER
stores the number of cm the tree will grow each year
MaxHeight : INTEGER
stores the maximum height in cm that the tree will grow
MaxWidth : INTEGER
stores the maximum width in cm that the tree will grow
Evergreen : STRING
stores whether the tree keeps its leaves as "Yes", or
loses its leaves as "No"
Constructor()
initialises TreeName, HeightGrowth, MaxHeight,
MaxWidth and Evergreen to its parameter values
GetTreeName()
returns the name of the tree
GetGrowth()
returns the number of cm the tree will grow each year
GetMaxHeight()
returns the maximum height in cm that the tree will grow
GetMaxWidth()
returns the maximum width in cm that the tree will grow
GetEvergreen()
returns whether the tree keeps its leaves or loses its
leaves
Write program code to declare the class Tree and its constructor.
(a) (i)
Do not declare the other methods.
Use the appropriate constructor for your programming language.
All attributes must be private.
If you are writing in Python, include attribute declarations using comments.
Save your program as Question2_J24.
Copy and paste the program code into part 2(a)(i) in the evidence document.
[4]
The get methods GetTreeName(), GetGrowth(), GetMaxHeight(),
(ii)
GetMaxWidth() and GetEvergreen() each return the relevant attribute.
Write program code for the get methods.
Save your program.
Copy and paste the program code into part 2(a)(ii) in the evidence document.
[3]
(b) The text file Trees.txt stores data about 9 trees.
The data in the file is stored in the format:
Tree name,Height growth each year,Maximum height,Maximum width,Evergreen
For example, the first row of data is:
Beech,30,400,200,No
The tree is a Beech. It can grow 30 cm each year. It has a maximum height of 400 cm.
It has a maximum width of 200 cm. It is not evergreen (it loses its leaves).
The function ReadData():
•
creates an array of type Tree
•
reads the data from the file
•
raises an exception if the file is not found
•
creates a new object of type Tree for each tree in the file
•
appends each object to the array
•
returns the array.
Write program code for ReadData().
Save your program.
Copy and paste the program code into part 2(b) in the evidence document.
[7]
(c) The procedure PrintTrees() takes a Tree object as a parameter and outputs the tree’s
name, height growth each year, maximum height, maximum width and whether it is evergreen.
The output message changes depending on whether it is evergreen.
If it is evergreen, it is in the format:
TreeName has a maximum height MaxHeight a maximum width MaxWidth and grows
HeightGrowth cm a year. It does not lose its leaves.
If it is not evergreen, it is in the format:
TreeName has a maximum height MaxHeight a maximum width MaxWidth and grows
HeightGrowth cm a year. It loses its leaves each year.
Write program code for PrintTrees().
Save your program.
Copy and paste the program code into part 2(c) in the evidence document.
[4]
(d) The main program calls ReadData(), stores the return value and calls PrintTrees() with
the first object in the returned array.
(i)
Write program code for the main program.
Save your program.
Copy and paste the program code into part 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 part 2(d)(ii) in the evidence document.
[1]
(e) The procedure ChooseTree() takes an array of Tree objects as a parameter.
The procedure prompts the user to input their requirements for a tree.
The user needs to enter:
•
the maximum height the tree can be in cm
•
the maximum width the tree can be in cm
•
whether they want the tree to
Question text
2
A binary tree stores data in ascending order. For example:
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.
The class Node stores the data about a node.
Node
LeftPointer : INTEGER
stores the index of the node to the left in the binary tree
Data : INTEGER
stores the node’s data
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
GetLeft()
returns the left pointer
GetRight()
returns the right pointer
GetData()
returns the data value
SetLeft()
assigns the parameter to the left pointer
SetRight()
assigns the parameter to the right pointer
SetData()
assigns the parameter to the data
Write program code to declare the class Node and its constructor.
(a) (i)
Do not declare the other methods.
Use the appropriate constructor for your programming language.
If you are writing in Python, include attribute declarations using comments.
Save your program as Question2_J24.
Copy and paste the program code into part 2(a)(i) in the evidence document.
[4]
The get methods GetLeft(), GetRight()and GetData()each return the relevant
(ii)
attribute.
Write program code for the three get methods.
Save your program.
Copy and paste the program code into part 2(a)(ii) in the evidence document.
[3]
The set methods SetLeft(), SetRight()and SetData()each take a parameter and
(iii)
then store this in the relevant attribute.
Write program code for the three set methods.
Save your program.
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
NumberNodes : INTEGER
stores the quantity of nodes in the tree
Constructor()
initialises FirstNode to −1 and NumberNodes to 0
initialises each element in Tree to a Node object with the
data value of −1
InsertNode()
takes a Node object as a parameter, inserts it in the array
and updates the pointer for its parent node
OutputTree()
outputs the left pointer, data and right pointer of each
node in Tree
Nodes cannot be deleted from this tree.
Write program code to declare the class TreeClass and its constructor.
(i)
Do not declare the other methods.
Use the appropriate constructor for your programming language.
If you are writing in Python, include attribute declarations using comments.
Save your program.
Copy and paste the program code into part 2(b)(i) in the evidence document.
[4]
The method InsertNode()takes a Node object, NewNode, as a parameter and inserts
(ii)
it into the array Tree.
InsertNode()first checks if the tree is empty.
If the tree is empty, InsertNode():
•
stores NewNode in the array Tree at index NumberNodes
•
increments NumberNodes
•
stores 0 in FirstNode.
If the tree is not empty, InsertNode():
•
stores NewNode in the array Tree at index NumberNodes
•
accesses the data in the array Tree at index FirstNode and compares it to the
data in NewNode
•
repeatedly follows the pointers until the correct position for NewNode is found
•
once the position is found, InsertNode()sets the left or right pointer of its parent
node
•
increments NumberNodes.
Write program code for InsertNode().
Save your program.
Copy and paste the program code into part 2(b)(ii) in the evidence document.
[6]
The method OutputTree()outputs the left pointer, the data and the right pointer for
(iii)
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’.
Write program code for OutputTree().
Save your program.
Copy and paste the progra
Question text
8
(a) A pseudocode algorithm finds a customer account record in a random file and outputs it. The
records are stored using the user-defined data type TAccount.
TYPE TAccount
DECLARE AccountNumber : INTEGER
DECLARE LastName : STRING
DECLARE FirstName : STRING
DECLARE Address : STRING
DECLARE ContactNumber : STRING
ENDTYPE
Complete the file handling pseudocode.
The function Hash() takes the customer account number as a parameter, calculates and
returns the hash value.
DECLARE Customer : TAccount
DECLARE Location : INTEGER
DECLARE AccountFile : STRING
…
"AccountRecords.dat"
… AccountFile …
OUTPUT "Please enter an account number"
INPUT Customer.AccountNumber
Hash( … )
Location
SEEK … , Location
… AccountFile, …
OUTPUT Customer
// output customer record
CLOSEFILE AccountFile
[5]
(b) Define the term exception handling.
…
… [1]
(c) State two possible causes of an exception.
…
… [2]
Question text
11
A declarative programming language is used to represent subjects that students can choose to
study.
Students must choose two subjects.
01 subject(mathematics).
02 subject(physics).
03 subject(chemistry).
04 subject(computer_science).
05 subject(geography).
06 subject(history).
07 subject(english).
08 subject(biology).
09 student(tomaz).
10 student(josephine).
11 student(elspeth).
12 student(nico).
13 student(teresa).
14 student(pietre).
15 choice1(tomaz, mathematics).
16 choice1(teresa, chemistry).
17 choice1(pietre, mathematics).
18 choice1(nico, mathematics).
19 choice1(elspeth, chemistry).
20 choice2(tomaz, computer_science).
21 choice2(nico, geography).
These clauses have the meanings:
Clause
Meaning
01
Mathematics is a subject.
09
Tomaz is a student.
15
Tomaz has chosen mathematics as his first choice.
20
Tomaz has chosen computer science as his second choice.
(a) Anthony is a student who would like to study history and geography.
Write additional clauses to represent this information.
22 …
23 …
24 …
[3]
(b) Using the variable X, the goal:
choice1(X, chemistry)
returns
X = teresa, elspeth
Write the result returned by the goal:
choice1(X, mathematics)
X = … [1]
(c) Students must choose two different subjects such that:
N may choose S, if N is a student and S is a subject and N has not chosen S as the first
choice.
Write this as a rule.
may_choose_subject(N, S)
IF …
…
…
… [4]
Question text
11
A declarative programming language is used to represent some facts about people and their
hobbies.
01 hobby(music).
02 hobby(caving).
03 hobby(climbing).
04 hobby(camping).
05 hobby(baking).
06 hobby(travelling).
07 person(toby).
08 person(natasha).
09 person(fatima).
10 person(joseph).
11 person(elijah).
12 person(nina).
13 enjoys(natasha, travelling).
14 enjoys(toby, climbing).
15 enjoys(nina, climbing).
16 enjoys(elijah, camping).
17 enjoys(fatima, baking).
18 enjoys(joseph, camping).
19 dislikes(toby, caving).
These clauses have the meanings:
Clause
Meaning
01
Music is a hobby
07
Toby is a person
13
Natasha enjoys travelling
19
Toby dislikes caving
(a) Carlos is a person who enjoys the hobby of cycling but does not like music.
Write additional clauses to represent this information.
20 …
21 …
22 …
23 …
[4]
(b) Using the variable P, the goal:
enjoys(P, camping)
returns
P = elijah, joseph
Write the result returned by the goal:
enjoys(P, climbing)
P = … [1]
(c) N is a person who might enjoy H if H is a hobby and N does not dislike H.
Write this as a rule.
might_enjoy(N, H)
IF …
…
…
… [4]
Question text
12 (a) Describe, with an example, what is meant by an exception.
…
…
…
… [2]
(b) A pseudocode algorithm searches for a customer record
in
a
random
file
AccountRecord.dat. A user inputs the name of the customer.
The records are stored using the user‑defined data type TAccount.
TYPE TAccount
DECLARE AccountNumber : INTEGER
DECLARE Name : STRING
DECLARE Address : STRING
DECLARE Telephone : STRING
ENDTYPE
If the record is found, it is output, otherwise an error message is displayed.
Complete the file handling pseudocode.
DECLARE Customer : TAccount
DECLARE Location : INTEGER
DECLARE MaxSize : INTEGER
DECLARE FoundFlag : BOOLEAN
DECLARE SearchCustomer : STRING
MaxSize
1000
OPENFILE …
Location
1
…
FALSE
OUTPUT "Enter the customer’s name"
…
… AND Location <= MaxSize
… "AccountRecord.dat", …
GETRECORD "AccountRecord.dat", Customer
IF SearchCustomer = Customer.Name THEN
OUTPUT "Customer found: "
OUTPUT Customer
// output customer record
FoundFlag
TRUE
ENDIF
Location
Location + 1
ENDWHILE
IF NOT FoundFlag THEN
OUTPUT " … "
ENDIF
[7]
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
Question text
3
A computer game is written using object-oriented programming.
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
XPosition : INTEGER
stores the X position as an integer
YPosition : INTEGER
stores the Y position as an integer
Constructor()
initialises Name, XPosition and YPosition to its
parameter values
GetXPosition()
returns the X position
GetYPosition()
returns the Y position
SetXPosition()
adds the parameter to the X position
validates that the new X position is between 0 and 10 000
inclusive
SetYPosition()
adds the parameter to the Y position
validates that the new Y position is between 0 and 10 000
inclusive
Move()
takes a direction as a parameter and calls either
SetXPosition or SetYPosition with an integer value
(a) (i)
Write program code to declare the class Character and its constructor.
Do not declare the other methods.
Use your programming language’s appropriate constructor.
If you are writing in Python, include attribute declarations using comments.
Save your program as Question3_N23.
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.
Write program code for the get methods.
Save your program.
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.
If the new value exceeds 10 000, it is limited to 10 000.
If the new value is below 0, it is limited to 0.
Write program code for the set methods.
Save your program.
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.
Use the appropriate method to change the position value.
Direction
Value change
up
Y position + 10
down
Y position − 10
left
X position − 10
right
X position + 10
Write program code for Move().
Save your program.
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.
Save your program.
Copy and paste the program code into part 3(b) in the evidence document.
[2]
(c) The class BikeCharacter inherits from the class Character.
BikeCharacter
Constructor()
takes Name, XPosition and YPosition as parameters
calls its parent class constructor with the appropriate values
Move()
overrides the method Move() from the parent class by
changing either the X position or the Y position by 20
instead of 10
(i)
Write program code to declare the class BikeCharacter and its constructor.
Do not declare the other method.
Use your programming language’s 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.
[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.
Direction
Value change
up
Y position + 20
down
Y position − 20
left
X position − 20
right
X position + 20
Write program code for Move().
Save your program.
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.
Save your program.
Copy and paste the
Question text
3
A computer game is written using object-oriented programming.
The game has multiple characters.
The class Character stores data about the game characters. Each character has a name, date
of birth, intelligence value and speed value.
Character
CharacterName : STRING
stores the name of the character
DateOfBirth : DATE
stores the date of birth of the character
Intelligence : REAL
stores the intelligence value of the character
Speed : INTEGER
stores the speed value of the character
Constructor()
initialises CharacterName, DateOfBirth,
Intelligence and Speed to the parameter values
SetIntelligence()
assigns the value of the parameter to Intelligence
GetIntelligence()
returns the value of Intelligence
GetName()
returns the name of the character
ReturnAge()
calculates and returns the age of the character as an integer
Learn()
increases the value of Intelligence by 10%
(a) (i)
Write program code to declare the class Character and its constructor.
Do not declare the other methods.
Use your programming language’s appropriate constructor.
If you are writing in Python, include attribute declarations using comments.
Save your program as Question3_N23.
Copy and paste the program code into part 3(a)(i) in the evidence document.
[5]
(ii)
The get methods GetIntelligence() and GetName() return the attribute values.
Write program code for the methods GetIntelligence() and GetName().
Save your program.
Copy and paste the program code into part 3(a)(ii) in the evidence document.
[3]
(iii)
The method SetIntelligence() assigns the value of its parameter to the attribute.
Write program code for SetIntelligence().
Save your program.
Copy and paste the program code into part 3(a)(iii) in the evidence document.
[2]
(iv)
The method Learn() increases the current value of Intelligence by 10%.
Write program code for Learn().
Save your program.
Copy and paste the program code into part 3(a)(iv) in the evidence document.
[1]
(v)
The method ReturnAge() calculates and returns the age of the character in years as
an integer.
Assume that the current year is 2023 and only use the year from the date of birth for the
calculation. For example, the method returns 18 if the character was born on any date in
2005.
Write program code for the method ReturnAge().
Save your program.
Copy and paste the program code into part 3(a)(v) in the evidence document.
[2]
(b) (i)
Write program code to create a new instance of Character with the identifier
FirstCharacter.
The name of the character is Royal, date of birth is 1 January 2019, intelligence is 70
and speed is 30.
Save your program.
Copy and paste the program code into part 3(b)(i) in the evidence document.
[2]
(ii)
Write program code to call the method Learn() for the character created in part 3(b)(i).
Output the name, age and intelligence of the character in an appropriate message.
Save your program.
Copy and paste the program code into part 3(b)(ii) in the evidence document.
[3]
(iii)
Test your program.
Take a screenshot of the output.
Save your program.
Copy and paste the screenshot into part 3(b)(iii) in the evidence document.
[1]
(c) The class MagicCharacter inherits from the class Character. A magic character has an
element, for example, water. This element changes how they learn. The magic character’s
element is stored in the additional attribute Element.
MagicCharacter
Element : STRING
stores the element for the character
Constructor()
takes Element, CharacterName, DateOfBirth,
Intelligence and Speed as parameters
calls its parent class constructor with the appropriate values
initialises Element to its parameter value
Learn()
alters the intelligence of the character depending on the
character’s element
(i)
Write program code to declare the class MagicCharacter and its constructor.
Do not declare the other method.
Use your programming language’s appropriate constructor.
If you are writing in Python, include attribute declarations using comments.
Save your program.
Copy and p
Question text
10 The pseudocode algorithm shown copies an active accounts text file ActiveFile.txt to an
archive accounts text file ArchiveFile.txt, one line at a time. Any blank lines found in the
active accounts text file are replaced with the words "Account not present" in the archive
accounts text file.
Complete this file-handling pseudocode.
DECLARE Account : STRING
…
OPENFILE "ArchiveFile.txt" FOR WRITE
WHILE NOT …
READFILE "ActiveFile.txt", Account
IF Account = "" THEN
WRITEFILE "ArchiveFile.txt", " … "
ELSE
WRITEFILE "ArchiveFile.txt", …
ENDIF
ENDWHILE
…
CLOSEFILE "ArchiveFile.txt"
[5]
Question text
4
Draw one line from each Object‑Oriented Programming (OOP) term to its most appropriate
description.
OOP term
Description
methods used to return the value of
a property
Encapsulation
the process of putting data and
methods together as a single unit
Getters
methods used to update the value of
a property
Polymorphism
allows methods to be redefined for
derived classes
Setters
enables the defining of a new class
that inherits from a parent class
[4]
Question text
6
(a) Write pseudocode statements to declare the composite data type, TAppointments, to hold
data about patients for a dental clinic. It will include for each patient:
•
name (first name and last name)
•
date of birth
•
telephone number
•
date of last appointment
•
date of next appointment
•
all treatments are complete (yes or no).
…
…
…
…
…
…
…
… [4]
(b) This pseudocode algorithm reads dental records stored in a random file using the user‑defined
data type TAppointments and prints the contents of the file, one record at a time.
Complete this file handling pseudocode:
DECLARE DentalRecord : ARRAY[1:250] OF TAppointments
DECLARE DentalFile : STRING
DECLARE Count : INTEGER
"DentalFile.dat"
DentalFile
OUTPUT "The file ", DentalFile, " contains these records:"
OPENFILE …
…
1
REPEAT
SEEK DentalFile, Count
…
OUTPUT DentalRecord[Count]
Count + 1
Count
… (DentalFile)
…
[5]
Question text
2
A computer game is being designed that will include different vehicles. A prototype for the game is
being developed using object‑oriented programming.
The class Vehicle stores data about the vehicles. Each vehicle has an identification name,
a maximum speed, a current speed and a horizontal position. The value IncreaseAmount is
added to the current speed each time the vehicle increases its speed.
Vehicle
ID : STRING
stores the identification name for the vehicle
MaxSpeed : INTEGER
stores the maximum speed
CurrentSpeed : INTEGER
stores the current speed
IncreaseAmount : INTEGER
stores the amount CurrentSpeed increases by
HorizontalPosition : INTEGER
stores the horizontal position
Constructor()
initialises ID, MaxSpeed and IncreaseAmount to the
parameter values
initialises both CurrentSpeed and
HorizontalPosition to 0
GetCurrentSpeed()
returns the current speed
GetIncreaseAmount()
returns the increase amount
GetHorizontalPosition()
returns the horizontal position
GetMaxSpeed()
returns the maximum speed
SetCurrentSpeed()
assigns the parameter to the current speed
SetHorizontalPosition()
assigns the parameter to the horizontal position
IncreaseSpeed()
calculates and stores the new speed and horizontal
position of the vehicle
(a) (i)
Write program code to declare the class Vehicle. All attributes must be private.
You only need to declare the class and its constructor. Do not declare any other methods.
Use your programming language’s appropriate constructor.
If you are writing program code in Python, include attribute declarations using comments.
Save your program as Question2_J2023.
Copy and paste the program code into part 2(a)(i) in the evidence document.
[5]
(ii)
Write
program
code
for
the
get
methods
GetCurrentSpeed(),
GetIncreaseAmount(), GetMaxSpeed() and GetHorizontalPosition()
Save your program.
Copy and paste the program code into part 2(a)(ii) in the evidence document.
[3]
(iii)
Write program code for
the
set
methods
and
SetCurrentSpeed()
SetHorizontalPosition()
Save your program.
Copy and paste the program code into part 2(a)(iii) in the evidence document.
[3]
(iv)
The method IncreaseSpeed():
•
adds IncreaseAmount to the current speed
•
adds the updated current speed to the horizontal position.
The current speed of a vehicle cannot exceed its maximum speed.
Write program code for the method IncreaseSpeed()
Save your program.
Copy and paste the program code into part 2(a)(iv) in the evidence document.
[3]
(b) The child class Helicopter inherits from the parent class Vehicle. A helicopter also has a
vertical position and changes the vertical position when it increases speed.
Helicopter
VerticalPosition : INTEGER
stores the vertical position
VerticalChange : INTEGER
stores the amount VerticalPosition changes by
MaxHeight : INTEGER
stores the maximum height the helicopter can reach
Constructor()
takes the ID, maximum speed, increase amount, vertical
change and maximum height as parameters
initialises the vertical position to 0
GetVerticalPosition()
returns the vertical position
IncreaseSpeed()
changes the current speed, horizontal and vertical
position of the helicopter
(i)
Write program code to declare the class Helicopter. You only need to declare the
class and its constructor. You do not need to 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.
Copy and paste the program code into part 2(b)(i) in the evidence document.
[5]
(ii)
The Helicopter method IncreaseSpeed() overrides the method from the parent
class and:
•
adds the amount of vertical change to the vertical position
•
adds IncreaseAmount to the current speed
•
adds the updated current speed to the horizontal position.
The vertical position of a helicopter cannot exceed its maximum height.
The current speed of a helicopter cannot exceed its maximum speed.
Write pro
Question text
3
A company needs a computer program to store data about its employees.
Part of the program is being written using object‑oriented programming.
The class Employee stores data about the employees. Each employee has an employee number,
a job title and hourly pay rate. The class will also store the amount they are paid each week over a
52‑week year in a 1D array.
Employee
HourlyPay : REAL
stores the amount each employee gets paid each
hour
EmployeeNumber : STRING
stores the employee’s unique number
JobTitle : STRING
stores the employee’s job title
PayYear2022 : ARRAY[0:51] OF REAL
stores the amount the employee has been paid each
week
Constructor()
initialises HourlyPay, EmployeeNumber and
JobTitle from the values passed as parameters
initialises all 52 elements in PayYear2022 to 0.0
GetEmployeeNumber()
returns the employee number
SetPay()
takes the week number and number of hours worked
that week as parameters
calculates and stores the pay for that week in
PayYear2022
returns the total of all the values in PayYear2022
GetTotalPay()
(a) (i)
Write program code to declare the class Employee.
You only need to declare the class and its constructor. Do not declare any other methods.
Use your programming language appropriate constructor.
If you are writing program code in Python, include attribute declarations using comments.
Save your program as Question3_J2023.
Copy and paste the program code into part 3(a)(i) in the evidence document.
[5]
(ii)
The method GetEmployeeNumber() returns the employee number.
Write program code for the method GetEmployeeNumber().
Save your program.
Copy and paste the program code into part 3(a)(ii) in the evidence document.
[2]
(iii)
The method SetPay():
•
takes a week number and the number of hours worked that week as parameters
•
calculates the pay for that week by multiplying the hourly pay by the number of
hours worked that week
•
stores the calculated pay in the appropriate index for that week in PayYear2022.
Write program code for the method SetPay().
Save your program.
Copy and paste the program code into part 3(a)(iii) in the evidence document.
[3]
(iv)
The method GetTotalPay() returns the total of all the values in PayYear2022.
Write program code for the method GetTotalPay().
Save your program.
Copy and paste the program code into part 3(a)(iv) in the evidence document.
[2]
(b) The child class Manager inherits from the parent class Employee.
A manager gets a bonus. This bonus value is a percentage, for example 10.0%.
When calculating the pay, the number of hours the manager worked that week is increased
by the bonus value.
Manager
stores the bonus value, for example 10.0 represents a
BonusValue : REAL
10.0% increase
Constructor()
takes bonus value, hourly pay, employee number and job title
as parameters
initialises BonusValue to its parameter value
SetPay()
takes the week number and number of hours worked as
parameters
increases the number of hours worked by the bonus value
calls the SetPay() method from the parent class
(i)
Write program code to declare the class Manager.
You only need to declare the class and its constructor. Do not declare any 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.
[4]
(ii)
The Manager method SetPay() overrides the method from the parent class and:
•
takes the week number and number of hours worked as parameters
•
increases the number of hours worked by the bonus value
•
calls SetPay() from the parent class.
Write program code for the method SetPay().
Save your program.
Copy and paste the program code into part 3(b)(ii) in the evidence document.
[3]
(c) The main program has a global 1D array, EmployeeArray, to store data about
eight employees. Each employee is stored as an object of type Employee.
The file Employees.txt sto
Question text
11
(a) Define these Object-Oriented Programming (OOP) terms:
Instance …
…
Inheritance …
…
Polymorphism …
…
[3]
(b) In OOP, a class contains attributes and methods.
Complete the pseudocode for the class Car to enable objects to be created. The class needs
to include:
•
string attributes to store the make, model, body type and fuel type
•
an integer attribute to store the number of cars of that type built.
The attributes must be available only through the methods of the class.
CLASS …
PRIVATE Make : STRING
PRIVATE …
…
…
…
PUBLIC PROCEDURE New(CarMake : STRING, … ,
… )
← …
Make
Model ← …
BodyType ← CarBodyType
Fuel ← ""
NumberBuilt ← 0
ENDPROCEDURE
GetFuel()
GetNumberBuilt()
…
[5]