August 1997
OP216: OBJECT ORIENTED PROGRAMMING

QUESTION 2

Total Marks: 20 Marks

Click here to access other questions

SUGGESTED SOLUTIONS
Solutions and allocated marks are indicated in green.
Return to Question 2

2. (a) Write a SimpleCircle class declaration with only one member variable (itsRadius); a default constructor and destructor; and accessor methods for the radius. [8]
deduct one mark for each syntax error or omission, minimum zero.
[8 marks]
(b) Using the class that you created for Part (a), write the implementation of the default constructor, initialising itsRadius with the value 5. [4]
deduct one mark for each syntax error or omission, minimum zero.
[4 marks]
(c) Using the same class, add a second constructor that takes a value as its parameter and assigns that value to itRadius. [4]
deduct one mark for each syntax error or omission, minimum zero.
[4 marks]
(d) Consider the following fragment of code:
int SimpleCircle : : GetRadius()
{
return *itsRadius;
}
and assume that Circle is an object of SimpleCircle, that is
SimpleCircle Circle;
Write an instruction that displays the radius for Circle on screen. [4]
deduct one mark for each syntax error or omission, minimum zero.
[4 marks]