Question 1
5 marks
1 5 marks
OCR DogCare look after dogs while their owners are at work. They use a program developed in an object- oriented paradigm to store details about each dog.
Each dog is declared by using an instance of the class Dog. This has these private attributes:
• name
• breed
• height
• weight
The constructor method sets all the attributes to the values passed in as parameters.
Write pseudocode or program code to define the class Dog. You should include the attributes and constructor method.
You do not need to write the set or get methods.
Mark scheme 1
Tick each point your answer makes. Your mark is worked out from your ticks, and you can change it.
1 mark per bullet to max 5:
-
Suitable logic for class dog declaration
-
Suitable logic to define the 4 (private) attributes:
name,
breed, height, weight
-
Suitable logic to declare a public method for constructor (e.g. new or class name)...
-
....taking only 4 different parameters in any order.
-
Suitable logic to set the values of each attribute
MP4 - if it is obvious the candidate has used Pythonic syntax: allow the additional 5th parameter representing the object e.g. self, turtle but this must be the first parameter listed.
MP2 - If they have done the above BP2 can be considered implicitly met (Python doesn’t require attributes to be declared outside the constructor)
Guidance
Mark in a vertical line against each MP.
Ignore data types in attribute names
Allow colon/empty brackets at the end of class def
Example Solutions
Pseudocode style
class Dog
private name
private breed
private height
private weight
public procedure new
(nameIn,
breedIn, heightIn, weightIn)
name = nameIn
breed = breedIn
height = heightIn
weight = weightIn
endclass
Java / C# Style
Class Dog
{
private String name
private String breed
private float height
private float weight
public void Dog(String name,
String
breed, float height, float
weight)
{
this.name = name
this.breed = breed
this.height = height
this.weight = weight
}
}
Python Style
class Dog:
def __init__(self, name,
breed, height, weight):
self.name = name
self.breed = breed
self.height = height
self.weight = weight
Examiner’s Comments
There were a range of responses to this question with the most common responses being written in
pseudocode or python. There was a clear division between candidates who were comfortable writing Object Oriented Programming (OOP) code and class constructors and those that were not.
Less successful candidates with little OOP experience often confused the class declaration with the constructor declaration. A few input the values rather than setting the attributes to the values passed in the parameters.