1. Consider the following algorithm in Fig.
2, expressed in pseudocode, as a function S:
i. Describe what is meant by recursion.
[2]
ii. Identify one example of where recursion occurs in this algorithm.
[1]
2. Christoff is writing a program to simulate a city using object-oriented programming. He is
designing classes to store different types of buildings and their location on the road. He has
created the following plan for some of the buildings:
The classes office and house inherit from building.
Describe what is meant by inheritance with reference to these classes.
[2]
3. A supermarket uses an object-oriented approach to organise items that it offers for sale. Part of
the class definition for the ItemForSale class is shown below.
class ItemForSale
public itemName
public price
public discount
endclass
Some items in a supermarket are only available through home delivery. These items are the same
as ItemsForSale with the following exceptions:
• the supermarket also stores the location of the stock
• the percentage discount allowed is up to 75 rather than the standard 50.
Explain how inheritance can be used to implement the above requirements.
[4]
4. * Procedural programming and object-oriented programming are two paradigms commonly used
by programmers when developing computer games.
Discuss the advantages of using object-oriented programming over procedural programming when
developing computer games. You should refer to inheritance, encapsulation and polymorphism in
your answer.
[12]
5. Mobile Treasure Hunt is a game played on a mobile phone. The game shows the user's position
on a map of their local area. Treasure randomly appears on the map and users must move to the
appropriate area to collect the treasure before it disappears.
Describe what is meant by the term ‘inheritance’, referring to the code in Fig. 2.1.
[3]
6. A software development company is building an operating system for a mobile phone that is in
the process of being designed.
* The code is written using an object-oriented programming (OOP) language. Discuss the
advantages and disadvantages to the team of developers of using OOP over procedural
programming. You should refer to inheritance, encapsulation and polymorphism in your answer.
[9]
7. Livid Lizards is a computer game in which players get to fire lizards from a cannon to knock
down walls. Players get to pick different types of lizards, each with qualities and special powers.
The game is coded using an object-oriented language. Below is the code for the lizard class:
i. Describe what is meant by the term inheritance.
[3]
ii. Explain one way the game’s developers might use inheritance for Livid Lizards.
[3]
8. A program is written using an object-oriented programming paradigm and uses a class called
video to organise videos that are streamed to customers.
The class video has these attributes:
• name
• number of views
• star rating.
The constructor method will set the name attribute to the name that is passed in as a parameter.
The constructor will also initially set the number of views to 0 and the star rating to 3.
i. Write program code or pseudocode to declare the class video and initialise the required
attributes as private.
You should include both the attribute definitions and the constructor method in your
answer.
[7]
ii. A public method called updateviews() will update the number of views after a video has
been viewed. This method is defined inside the video class.
Write program code or pseudocode for the method updateviews() to increase the
number of views by one.
[2]
9.
An object-oriented system is implemented to organize a company’s information about staff
attendance. Classes, objects, methods and attributes are used in this system.
i. State the meaning of each of the following terms:
Object
Method
Attribute
[3]
ii. Each worker has a name and an attendance figure which can be between 0 and 100.
Write a definition for a fully encapsulated worker class, providing both get and set methods
for all attributes. You do not have to write code for the constructor method.
[5]
10(a). Christoff is writing a program to simulate a city using object-oriented programming. He is
designing classes to store different types of buildings and their location on the road. He has
created the following plan for some of the buildings:
Part of the declaration for the class building is shown.
Complete the pseudocode declaration by filling in the missing statements.
class building
private numberFloors
private width
private ………………………………………………………………………
public procedure new(pFloors, pWidth, pHeight)
numberFloors = ………………………………………………………………………
width = pWidth
height = pHeight
endprocedure
public function getNumberFloors()
return ………………………………………………………………………
endfunction
public function setNumberFloors(pFloors)
/sets the value of numberFloors when the parameter is >= 1
/returns true if numberFloors is successfully changed,
/returns false otherwise
if pFloors >= 1 then
numberFloors = ………………………………………………………………………
return true
else
return ………………………………………………………………………
endif
endfunction
endclass
[5]
(b). Write program code or pseudocode to declare the class house.
Define the attributes and constructor method in your answer. You do not need to write the get or
set methods.
[6]
(c). Christoff develops a new class to store the houses in one road. His class design is shown:
class : houseRoad
attributes:
private buildings(100) /array of class
house
private numberBuildings /records the
number
/of houses currently stored in the array
/buildings
methods:
new(building)
function getBuilding(buildingNum)
procedure newbuilding(pBuilding)
The method newbuilding() takes a new building as a parameter, and stores this in the next free
space in the array buildings.
Write pseudocode or program code for the method newbuilding().
[4]
11(a). A supermarket uses an object-oriented approach to organise items that it offers for sale.
Part of the class definition for the ItemForSale class is shown below.
class ItemForSale
public itemName
public price
public discount
endclass
The discount attribute represents a percentage discount on the price. The discount can be
between 0 and 50 (inclusive). All new items for sale initially have a discount value of 0.
i. Write the constructor method for the ItemForSale class.
[4]
ii. Write a line of code to create an object of type ItemForSale called mushypeas that has a
name of “mushy peas” and a price of £0.89
[3]
iii. Write the calculatePrice() method, which applies the percentage discount to the price
and returns the new value.
[3]
(b). The supermarket has previously had issues with discounts being set as values above 50.
Explain how encapsulation could be applied to the ItemForSale class to stop this problem from
occurring.
You are not expected to write any code in your answer to this question.
[3]
END OF QUESTION PAPER