August 1999
OP216 : OBJECT ORIENTED PROGRAMMING

QUESTION 4

Total Marks: 20 Marks

Click here to access other questions

Click to access
SUGGESTED SOLUTIONS
for Question 4

(a) Define the term inheritance with respect to object oriented programming.

 

[2]
(b) The government requires a program to keep records of all the buildings in the city. Each building has a number of floors (an integer), and address (a string) and a rental cost (an integer).

Implement the class building that contains :

  • These protected data items;
  • An accessor method for the rent;
  • A method Advertise, which prints out the address of the building and its rental cost.

 

[5]
(c) A House is a building that has a number of residents, and rent of 200 dollars per resident. Use inheritance to implement a class House, with a constructor that takes the parameters the number of residents, the address, and the length of the address, and initializes all of its members appropriately. All members which are not passed as parameters to the constructor should be initialized to 0.

 

[5]
(d) An estate is a collection of buildings. Consider the following definition of a class Estate :

class Estate {
private :
   ...
public :
   Estate();                //The constructor
   Building current();  // Returns the current building in the estate.
   void next();           // Move to the next building in the estate.
   int finished();        // Return 1 if all the buildings have been examined
                             // 0 otherwise
}

Give an implementation of a function total_rental_value that takes a reference to an estate, and returns the total rental value of all the buildings on the estate.

 

[6]
(e) In the Estate class, there is a problem that relates to calculating the rental cost of houses. Identify, and explain the nature of this problem.

 

[2]