You are on page 1of 23

1(a) Identify an attribute in the Lizard class.

[1]
(b) 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:

Lizard is a class. Describe what is meant by a class.

[2]

© OCR 2024. You may photocopy this page. 1 of 23 Created in ExamBuilder


(c)

(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]

(d) The game uses a 2D graphics library. Explain why a linker would need to be used after compilation.

[3]

© OCR 2024. You may photocopy this page. 2 of 23 Created in ExamBuilder


2 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]

© OCR 2024. You may photocopy this page. 3 of 23 Created in ExamBuilder


3 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.

Below is part of the code from Mobile Treasure Hunt.

Identify all attributes and methods in the TreasureChest class.

Methods: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

© OCR 2024. You may photocopy this page. 4 of 23 Created in ExamBuilder


Attributes: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

[2]

4 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.

© OCR 2024. You may photocopy this page. 5 of 23 Created in ExamBuilder


[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]

5 A computer uses a stack data structure, implemented using an array, to store numbers entered by the user.

The array is zero based and has 100 locations.

The stack is programmed as an object using object-oriented programming. The design for the class, its attributes
and methods are shown:

class: stack

attributes:
private stackArray : Array of integer
private pointerValue : integer

methods:
new()
function pop()
function push(value)

(i) The method pop() returns the next value in the stack, or –1 if the stack is empty.

© OCR 2024. You may photocopy this page. 6 of 23 Created in ExamBuilder


Complete the pseudocode method pop().

public function pop()


if pointerValue == .............................................. then
return ...............................................
else
pointerValue = pointerValue ...........................................
returnValue = stackArray[...............................................]
return ..................................................
endif
endfunction
[5]

(ii) The method push() accepts an integer as a parameter and adds it to the top of the stack unless the stack is
already full.

If the push is successful the method returns true.

If the push is unsuccessful due to the stack being full the method returns false.

Write the method push() using either pseudocode or program code.

© OCR 2024. You may photocopy this page. 7 of 23 Created in ExamBuilder


[6]

(iii) The main program initialises a new object of type stack with the identifier mathsStack.

Write pseudocode or program code to declare the object.

[2]

(iv) The main program needs to:

• take numbers as input from the user


• push them onto the stack mathsStack until the stack is full
• output an appropriate message if the stack is full.

Complete the pseudocode algorithm to meet these requirements.

returnValue = true
while returnValue == ..................................................
returnValue = mathsStack.
...........................................(input("Enter Number"))
if returnValue == .................................................. then
.................................................. ("Stack full")
endif
endwhile
[4]

(v) The main program also needs to:

• remove one item from the stack at a time and add this to a total
• output the total every time an item is removed
• stop removing items when either the stack is empty, or 20 items have been removed.
Write pseudocode or program code to meet these requirements.

© OCR 2024. You may photocopy this page. 8 of 23 Created in ExamBuilder


[8]

6 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:

© OCR 2024. You may photocopy this page. 9 of 23 Created in ExamBuilder


The classes office and house inherit from building.

Describe what is meant by inheritance with reference to these classes.

[2]

© OCR 2024. You may photocopy this page. 10 of 23 Created in ExamBuilder


7(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

© OCR 2024. You may photocopy this page. 11 of 23 Created in ExamBuilder


[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]

© OCR 2024. You may photocopy this page. 12 of 23 Created in ExamBuilder


(c) Some items in the 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]

END OF QUESTION PAPER

© OCR 2024. You may photocopy this page. 13 of 23 Created in ExamBuilder


Question Answer/Indicative content Marks Guidance

1 a Speed (1) / mass (1) / size (1). 1 For 1 mark.

b A template (1) defining methods and 2 Up to 2 marks for a valid description.


attributes (1) used to make objects (1).

c i Inheritance is when a class takes on 3 Up to 3 marks for a valid description.


the methods (1) and attributes (1) of a
parent class (1).
The inheriting class may override some
of these methods / attributes (1) and
may have additional extra methods and
attributes of its own (1).

ii The company may wish to use 3 Up to 3 marks for a valid explanation.


inheritance to create different types of
lizards (1 – AO1.2) using the lizard Maximum 1 mark for demonstrating
class as the base class (1 – AO2.1) understanding (AO1.2).
and different types of lizard inheriting
from it (1 – AO2.1). Up to 2 marks for applying knowledge and
understanding (AO2.1).

d The user running the program will not 3 Up to 3 marks for a valid explanation.
necessarily have the library installed on
their machine (1) therefore the relevant
code needs to be included within the
final executable (1) – it is the job of the
linker to combine this code (1).

Total 12

© OCR 2024. You may photocopy this page. 14 of 23 Created in ExamBuilder


Question Answer/Indicative content Marks Guidance

2 Mark Band 3–High Level (7–9 marks) 9 AO1 Knowledge and Understanding

The candidate demonstrates a thorough The following is indicative of possible


knowledge and understanding of Object factors / evidence that candidates may
Oriented Programming and has discussed refer to but is not prescriptive or
inheritance, polymorphism and exhaustive:
encapsulation; the material is generally
accurate and detailed. OOP involve solutions being constructed
by means of objects that interact with each
The candidate is able to apply their other. OOP uses classes as templates to
knowledge and understanding directly and construct objects. An object has attributes
consistently to the context provided. (variables associated with it) and methods
Evidence / examples will be explicitly (subroutines that form the actions an object
relevant to the explanation. can carry out).

The candidate provides a thorough Inheritance is where a class retains the


discussion which is well balanced. methods and attributes of its parent class
Evaluative comments are consistently as well as having its own.
relevant and well-considered.
Encapsulation is the process of keeping an
There is a well-developed line of reasoning object's attributes private so they can only
which is clear and logically structured. The be accessed and changed via public
information presented is relevant and methods.
substantiated.
Polymorphism means that objects of
Mark Band 2–Mid Level (4–6 marks) different types can be treated in the same
way.
The candidate demonstrates reasonable
knowledge and understanding of a range Procedural programming breaks a solution
of Object Oriented Programming and has down into subroutines. These subroutines
discussed at least two of: inheritance, are re built and combined to form a
polymorphism and encapsulation; the program.
material is generally accurate but at times
underdeveloped.
AO2.1: Application
The candidate is able to apply their
knowledge and understanding directly to The selected knowledge / examples should
the context provided although one or two be directly related to the specific question.
opportunities are missed. Examples may include but are not limited
Evidence / examples are for the most part to:
implicitly relevant to the explanation.
Breaking a problem down into objects
The candidate provides a sound naturally lends itself to teams as different
discussion, the majority of which is team members can work on different
focused. Evaluative comments are for the objects.
most part appropriate, although one or two
opportunities for development are missed. Inheritance means that one class can be
coded and that code used as the base for
There is a line of reasoning presented with similar objects. This will save the team time

© OCR 2024. You may photocopy this page. 15 of 23 Created in ExamBuilder


Question Answer/Indicative content Marks Guidance

some structure. The information presented as they are able to build on work already
is in the most part relevant and supported done.
by some evidence.
Encapsulation means that objects only
Mark Band 1–Low Level (1–3 marks) interact in the way intended and prevents
unexpected changed to attributes having
The candidate demonstrates a basic unforeseen consequences. This means
knowledge of Object Oriented there are likely to be fewer issues as the
Programming with limited understanding team combines their code.
shown; the material is basic and contains
some inaccuracies. For 3 marks they have Polymorphism means that code can be
described at least one of inheritance, written that is able to handle different
polymorphism or encapsulation. The objects in the same way. This reduces the
candidate makes a limited attempt to apply volume of code the team need to produce.
acquired knowledge and understanding to
the context provided. Procedural programming can be divided
between a team with different team
The candidate provides a limited members tackling different subroutines.
discussion which is narrow in focus.
Judgments if made are weak and There are a number of similarities between
unsubstantiated. The information is basic the two paradigms.
and communicated in an unstructured way.
The information is supported by limited Certain problems lend themselves more to
evidence and the relationship to the one than the other.
evidence may not be clear.

AO3.3: Evaluation
0 marks
No attempt to answer the question or Having considered the different sides to
response is not worthy of credit. the argument candidates will need to reach
a supported judgment based on the
evidence included in their response.

Total 9

3 Methods: (constructor/new), changeName, 2 Do not penalise for not including


pickLock (1) constructor.
Attributes: value, weight, name, locked (1) Only give method mark if both other
methods are listed
Only give attributes mark if all four
attributes are listed.

Total 2

© OCR 2024. You may photocopy this page. 16 of 23 Created in ExamBuilder


Question Answer/Indicative content Marks Guidance

4 i Class definition with identifier video 7 Accept implementations in high-level


name, number of views and star rating languages (e.g. __ for private, class name
attributes defined… used for constructor, no need for end of
…As private class definition in Python)
Constructor method definition inside
class definition… BP1 - allow empty brackets. Do not allow
…that accepts only one parameter anything in the brackets
…Name attribute set to parameter BP5 - ignore self if included as parameter
passed in
Views set to 0 and rating set to 3 either class video

when initialised or in constructor. private name

private views

private starrating

public procedure new(newname)

name = NewName

views = 0

starrating = 3

end procedure

end class

Examiner’s Comments
This question was well answered by some
candidates. The question asks for
pseudocode or program code and
candidates should be encouraged to do
one or the other if given a choice, rather
than a combination of the two. Many
candidates did not use the information in
the question stem to help them structure
their answer and gave more than one
parameter in the constructor.

Exemplar 3

This was a good clear example of an

© OCR 2024. You may photocopy this page. 17 of 23 Created in ExamBuilder


Question Answer/Indicative content Marks Guidance

answer given in pseudocode. The


candidate has declared the 3 given
attributes as private, shown a constructor
with one parameter and set name to the
parameter and views and rating to 0 and 3.
The candidate gained 7 marks.

ii Method definition that is public 2 public procedure updateviews()


View attribute incremented by one views = views + 1
end procedure

View attribute must have the same name


as part i

Examiner’s Comments
Most candidates were able to gain at least
1 mark for this question. Those who were
not given marks used pseudocode but did
not state that the procedure was public, or
they did not use the same attribute they
had declared in Question 2 (g) (i).

Total 9

© OCR 2024. You may photocopy this page. 18 of 23 Created in ExamBuilder


Question Answer/Indicative content Marks Guidance

5 i 1 mark per correctly completed statement 5 Examiner’s Comments

e.g. Most candidates gained some marks with


pubic function pop() many gaining full marks. The most
if pointerValue == 0 then common errors were writing identifiers for
return -1 pointerValue and returnValue with
else spaces in, returning values as strings, or
pointerValue = pointerValue returning True/False instead of -1 as
-1 required in the question.
returnValue =
stackArray[pointerValue]
return returnValue
endif
endfunction

ii 1 mark per bullet to max 6 6 Ignore additional parameters in function


definition
function header
..taking parameter (ignore byval/byref) Do not accept the return of string values
checking if stack is full (pointerValue at
100)… FT following a reasonable attempt to check
…and returning false if the stack is full
(otherwise) adding value to top of stack
…incrementing top of stack pointer Examiner’s Comments
return true
Candidates produced a higher standard of
e.g. pseudocode this session and many scored
function push(value) most if not full marks for a standard stack
if pointerValue < 100 then push routine.
stackArray[pointerValue] =
value Common errors included omitting a
pointerValue = pointerValue parameter and/or getting a user input as
+ 1 the value to place into the stack, returning
return true strings or printing the return values, and off-
else by-one errors when testing to see if the
return false stackPointer was at the top of the stack
endif to determine if the stack was full.
endfunction
It was noticeable that a number of students
who were only familiar with Python gave
list append type solutions rather than using
the array and pointers as per the
implementation given.

Another common error was incrementing


the value of the stackPointer before the
parameter was assigned to stackArray
at the stackPointer index, which was
frequently seen when candidates did not

© OCR 2024. You may photocopy this page. 19 of 23 Created in ExamBuilder


Question Answer/Indicative content Marks Guidance

know that the stackPointer actually


pointed to the index of the next free space
in the stack.

Exemplar 3

Candidates are encouraged to present


pseudocode solutions with clear
indentation to aid readability. No specific
language/syntax is expected, but the logic
of the solution must be clear.

iii 1 mark per bullet 2 Accept


mathsStack = stack()
instantiation of new object of type stack
assigned to variable mathsStack allow missing brackets this time only e.g.
mathsStack = stack
mathsStack = new stack()
Examiner’s Comments

Many candidates struggled to answer this


question because they lacked practical
experience of OOP that showed a lack of
familiarity in terms of creating instances of
a class. Some candidates tried to declare
mathsStack as a procedure or class, and
many got it the wrong way round and
actually declared a new identifier called
stack as an instance of the class
mathStack.

© OCR 2024. You may photocopy this page. 20 of 23 Created in ExamBuilder


Question Answer/Indicative content Marks Guidance

iv 1 mark for each completed statement 4 Accept equivalent for print e.g. output

returnValue = true Examiner’s Comments


while returnValue == true
returnValue = The majority of candidates scored some
mathsStack.push(input("Enter marks but relatively few gained full marks.
Number")) Return was seen instead of print/output
if returnValue == false then when the question did, on this occasion
print("Stack full") ask for the message to be output (as the
endif code was specified as being in the main
program rather than a subroutine).

v mark per bullet to max 8 8 Examiner’s Comments

initialise a total to 0 outside of loop The standard of pseudocode /


looping programming code was better than in
removing an item from the stack using previous sessions and most candidates
the method pop made a reasonable attempt to pop 20
check if stack is empty values from the stack. Many candidates
(if not) add value returned to total found it difficult to reference the class
…outputting total methods correctly or made assumptions
counting how many values are about the existence of other methods that
returned were not provided within the scenario (e.g.
stopping loop when either 20 items .full(), .empty(), .length(),
removed or no items left .remove()) that should not be presumed
to exist.
total = 0
quantity = 0 Those who had little understanding of
returnValue = 0 encapsulation often tried to access class
attributes such as stackPointer directly
while quantity<20 and to manipulate mathsStack, rather than
retunValue!=-1 using methods to interact with the instance
returnValue = of the stack.
mathsStack.pop()
if(returnValue != -1) then When candidates did use the .pop()
quantity = quantity + 1 method to retrieve a value from
total = total + returnValue mathsStack they frequently did not store
print(total) the result for later use to check whether
endif then stack was empty.
endwhile

Total 25

© OCR 2024. You may photocopy this page. 21 of 23 Created in ExamBuilder


Question Answer/Indicative content Marks Guidance

6 1 mark per bullet up to a maximum of 2 9 AO1.1


marks, e.g: (2) AO1.2
(2) AO2.1
When the child/derived/subclass class (2) AO3.3
office/house takes on (3)
attributes/methods…
… from building /
parent/base/superclass/ class

Total 2

© OCR 2024. You may photocopy this page. 22 of 23 Created in ExamBuilder


Question Answer/Indicative content Marks Guidance

7 a i Constructor method definition (.e.g 4 Example answer


new) AO3.2 public procedure new(nItemName,
itemname, price passed in as nPrice)
parameters (must use different itemname = nItemname
identifier names to the ones in the price = nPrice
question) discount = 0
…and assigned to attributes endprocedure
discount attribute assigned to 0.
Look out for alternative notation
e.g.

this.itemname = itemName

ii 1 mark for creating object with identifier 3 Example answers


mushypeas = AO3.2 mushypeas=new
1 mark for creating object as type ItemForSale("mushy peas", 0.89)
ItemForSale
mark for parameters passed in as ItemForSale mushypeas =
needed ItemForSale(“mushy peas”,0.89);

mushypeas=ItemForSale((“mushy
peas”,0.89);
Do not penalise for use of self parameter
as used by languages such as Python.
Must be correct case and spelling

iii method definition for 3 Percentage discount must be applied


calculatePrice() AO3.2 correctly.
applies percentage discount
…returns calculated value Example answer
function calculatePrice()
newPrice = price – (price *
discount/100)
return newPrice
end function

b discount attribute made private 3


Set method created AO2.2
…that restricts value to maximum 50%

c Create new class 4


…inheriting from / subclass of AO2.2
ItemsForSale
new attribute for stock location
calculatePrice() method
overridden // new version of
calculatePrice() implemented in
subclass.

Total 17

© OCR 2024. You may photocopy this page. 23 of 23 Created in ExamBuilder

Powered by TCPDF (www.tcpdf.org)

You might also like