(a) Briefly explain the difference between
multiple and single inheritance. [2 marks]
(b) State the scope of each of the public,
protected and private areas of a class in a derived class where the
derived class is declared to inherit protected from the base class.
[3 marks]
(c) The Rover Car company require a
new system to aid them in the design of new products. One of the products
they wish to design is a Tractor. A Tractor is both a Vehicle, and
a Tool. Consider the following definitions of the classes Vehicle
and Tool:
class Vehicle {
int NumberPassengers, EngineCapacity;
public:
Vehicle(int Passengers, int Capacity);
int GetPassengers();
}
class Tool {
char *Purpose, *PowerSource;
public:
Tool(char* p, char* s);
char* GetPurpose();
}
(i) Using inheritance, define the class Tractor such that it inherits
all the properties of both the Vehicle and the Tool class. Your class
should include the variable RoofType, which is a boolean variable
of type boolean, set to true if the Tractor
has a roof, and false otherwise. In addition to this, your class should
include a
constructor function, which takes all the parameters necessary to
initialise all the
member variables. [5 marks]
(ii) Define a class, called Component, which contains the attributes
ComponentName, which is a string, and ComponentPartNumber, which is
an integer. You should ensure that these attributes are accessible
to all other classes. [3 marks]
(iii) When a Tractor is built, it is not known how many components
will be required until it is finished. Add to your Tractor class an
array of type Component, the length of which is decided at allocation
time, such that this array is not accessible outside of any further
derived classes. [2 marks]
|