Professional Documents
Culture Documents
Computer Science 5
Computer Science 5
Computer Science 5
[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:
[2]
[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]
* 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]
Methods: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
[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.
• 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.
(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 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.
(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 unsuccessful due to the stack being full the method returns false.
(iii) The main program initialises a new object of type stack with the identifier mathsStack.
[2]
returnValue = true
while returnValue == ..................................................
returnValue = mathsStack.
...........................................(input("Enter Number"))
if returnValue == .................................................. then
.................................................. ("Stack full")
endif
endwhile
[4]
• 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.
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:
[2]
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.
[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
(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]
[4]
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
2 Mark Band 3–High Level (7–9 marks) 9 AO1 Knowledge and Understanding
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
Total 2
private views
private starrating
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
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
Exemplar 3
iv 1 mark for each completed statement 4 Accept equivalent for print e.g. output
Total 25
Total 2
this.itemname = itemName
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
Total 17