Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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 //header file input output

#include//header file for string operation

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<movement=m; } void setEats(string e) { this->eats=e; } string getMovement() { return this->movement; }

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Next Generation Databases NoSQLand Big Data

Authors: Guy Harrison

1st Edition

1484213300, 978-1484213308

More Books

Students also viewed these Databases questions

Question

Determine the roles of spatial layout and functionality.

Answered: 1 week ago

Question

What does Processing of an OLAP Cube accomplish?

Answered: 1 week ago