Question
Hi I need help with the below program. --------------------------------------------------------------------------------------------------- #include #include using namespace std; class Humanoid { public: double height(); double weight(); protected: double _speciesHeight;
Hi I need help with the below program.
---------------------------------------------------------------------------------------------------
#include
#include
using namespace std;
class Humanoid
{
public:
double height();
double weight();
protected:
double _speciesHeight;
double _speciesWeight;
};
double Humanoid::height()
{
return _speciesHeight;
}
double Humanoid::weight()
{
return _speciesWeight;
}
class Moclan : public Humanoid
{
public:
Moclan(double moclanHeight, double moclanWeight);
bool isEgg();
Moclan layEgg();
void hatch();
private:
bool _isEgg;
bool _theEgg;
};
Moclan::Moclan(double moclanHeight, double moclanWeight)
{
_speciesHeight = moclanHeight;
_speciesWeight = moclanWeight;
_isEgg = false;
_theEgg = false;
}
bool Moclan::isEgg()
{
return _isEgg;
}
Moclan Moclan::layEgg()
{
_theEgg = true;
_isEgg = true;
return *this;
}
void Moclan::hatch()
{
_isEgg = false;
}
int main() {
Moclan moclan(6.9, 320);
cout << "Moclan height: " << moclan.height() << endl;
cout << "Moclan weight: " << moclan.weight() << endl;
cout << "moclan.isEgg(), (need false): " << moclan.isEgg() << endl;
Moclan moclanEgg = moclan.layEgg();
cout << "moclan.isEgg(), (need false): " << moclan.isEgg() << endl;
cout << "moclanEgg.isEgg(), (need true): " << moclanEgg.isEgg() << endl;
moclanEgg.hatch();
cout << "moclanEgg.isEgg(), (need false): " << moclanEgg.isEgg() << endl;
return 0;
}
return 0;
}
---------------------------------------------------------------------------------------------------
This is the output so far:
Moclan height: 6.9 Moclan weight: 320 moclan.isEgg(), (need false): 0 moclan.isEgg(), (need false): 1 // need to return false moclanEgg.isEgg(), (need true): 1 moclanEgg.isEgg(), (need false): 0
However, after calling Moclan moclanEgg = moclan.layEgg(),
moclan.isEgg() is supposed to still return a false while moclanEgg.is() returns true.
Please help me with it. thanks
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started