a 2. Suppose we have the following C++ classes: Class Plant is the parent class for different kinds of living plants. It
Posted: Sat May 14, 2022 3:22 pm
(h) Write C++ code for class Plant (do not write code for the
other classes).
a 2. Suppose we have the following C++ classes: Class Plant is the parent class for different kinds of living plants. It has the following members (destructors (if any) are excluded from this list): - A private data field of type double called energyCapacity. A public constructor that takes as input argument a double and initializes energyCapacity to this data field. The default value for this argument is 100. This constructor does not allow automatic type conversion from a double to a Plant. • A public get function called getEnergyCapacity() that returns a Plant's energyCapacity This function does not do dynamic dispatching, • A public function called dailyEnergyConsumption() that takes no parameters and returns a double. Class Plant does not supply an implementation of this function; its implementations is to be supplied in subclasses. Class Flowering Plant is a subtype of Plant. It overrides function dailyEnergyConsumption(). FloweringPlant has a constructor that takes a double as its argument and calls Plant's constructor with this value. • Class FoodProducingPlant is a subtype of Plant. It overrides function dailyEnergyConsumption(). FoodProducingPlant has a constructor that takes a double as its argument and calls Plant's constructor with this value. • Class Peachtree is both a direct subtype of FloweringPlant and FoodProducingPlant. It has a constructor that takes a double and calls its appropriate parent class constructors to set its energyCapacity to this double. It also overrides function dailyEnergyConsumption().
other classes).
a 2. Suppose we have the following C++ classes: Class Plant is the parent class for different kinds of living plants. It has the following members (destructors (if any) are excluded from this list): - A private data field of type double called energyCapacity. A public constructor that takes as input argument a double and initializes energyCapacity to this data field. The default value for this argument is 100. This constructor does not allow automatic type conversion from a double to a Plant. • A public get function called getEnergyCapacity() that returns a Plant's energyCapacity This function does not do dynamic dispatching, • A public function called dailyEnergyConsumption() that takes no parameters and returns a double. Class Plant does not supply an implementation of this function; its implementations is to be supplied in subclasses. Class Flowering Plant is a subtype of Plant. It overrides function dailyEnergyConsumption(). FloweringPlant has a constructor that takes a double as its argument and calls Plant's constructor with this value. • Class FoodProducingPlant is a subtype of Plant. It overrides function dailyEnergyConsumption(). FoodProducingPlant has a constructor that takes a double as its argument and calls Plant's constructor with this value. • Class Peachtree is both a direct subtype of FloweringPlant and FoodProducingPlant. It has a constructor that takes a double and calls its appropriate parent class constructors to set its energyCapacity to this double. It also overrides function dailyEnergyConsumption().