a 2. Suppose we have the following C++ classes: Class Plant is the parent class for different kinds of living plants. It

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899604
Joined: Mon Aug 02, 2021 8:13 am

a 2. Suppose we have the following C++ classes: Class Plant is the parent class for different kinds of living plants. It

Post by answerhappygod »

A 2 Suppose We Have The Following C Classes Class Plant Is The Parent Class For Different Kinds Of Living Plants It 1
A 2 Suppose We Have The Following C Classes Class Plant Is The Parent Class For Different Kinds Of Living Plants It 1 (648.89 KiB) Viewed 42 times
(g) How can we have PeachTree inherit exactly
one energyCapacity data field instead of two? Explain
specifically what needs to be done to accomplish this and in which
classes.
(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().
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply