Question
Using the following code, complete the missing code in the main function to do the following Prompt the user for which class to create and
Using the following code, complete the missing code in the main function to do the following
Prompt the user for which class to create and values to set the attributes for that class. Include the option to create a fish or horse as an animal. This may look like:
Press 1 for an instance of animal. Press 2 for an instance of fish. Press 3 for an instance of horse. Press 4 for an instance of a fish declared as an animal Press 5 for an instance of a horse declared as an animal |
Call the move and eat functions from the instance created in step a.
Create a function outside of classes that accepts an animal as a parameter. This function should call the move and eat function of the input parameter.
Call the function from step c.
Ask the user if they wish to continue. If so, loop to step a.
Use your test program to test all member functions and ensure the class is working correctly.
-----------------------------------------------------------------------
#include
#include
using namespace std;
class Animals { private: string movement,eats; //private variables
public: Animals()//Empty Constrctor { this->movement =""; this->eats=""; } Animals(string m,string e)//Constructer Declare { setMovement(m); setEats(e); }
virtual void move() { cout<<"This is generic"; } void eat() { cout<<"Yummy!"<< this->eats<
string getEats() { return this->eats; }
};
class fish:public Animals { private: int num_fin;
public: fish(){}//Empty Constrctor
fish(string m,string e,int n):Animals(m,e)//Constructer Declare { this->num_fin=n;//assign value } void move () //move function here { cout<<"Just keep swimming. "; }
void eat() { cout<<"Yummy fish food "; }
void set_Num_fin(int n) { this->num_fin=n;//set value of number leg here } int get_Num_fin() { return this->num_fin;//return value number of fin here }
};
class horse:public Animals { private: int num_leg;
public: horse(){}//Empty Constrctor
horse(string m,string e,int n):Animals(m,e)//Constructer Declare { this->num_leg=n; }
void move() { cout<<"Walk, Trot, Canter, Gallop "; } void eat() { cout<<"Yummy Grass "; }
void set_Num_leg(int n) { this->num_leg=n;//set value number of leg } int get_num_leg() { return this->num_leg;//return value number of leg here }
};
int main() {
// ADD CODE HERE
return 0;
}
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