Answer to Question #204423 in C++ for Ahmad

Question #204423

First make a Animal class as parent class it contain

-name and gender as data members

-eating as member function

Make 5 classes of Animal type and inherit from Animal class

A. Sheep

B. Goat

C. Cow

D. Buffalo

E. Zebra

-This class can override its parent class method and implements on its own way

-call its eating method in the base of polymorphism


1
Expert's answer
2021-06-08T03:39:28-0400
#include<iostream>
using namespace std;
class Animal{
	private:
		string gender;
		string name;
	public:
		Animal(string g, string n){
			gender = g;
			name = n;
		}	
			void eating(){
				cout<<"Must eat to live"<<
			
		}
};
class Sheep: public Animal{
	eating(){
		cout<<"Eating "<<endl;
	}
};
class Goat: public Animal{
		void eating(){
			cout<<"Eating thorns"<<endl;
		}
};
class Cow: public Animal{
		void eating(){
			cout<<"Eating reads"<<endl;
		}
};
class Buffalo: public Animal{
	void eating(){
			cout<<"Eating baobab"<<endl;
	}
};
class Zebra: public Animal{
		void eating(){
				cout<<"Eating baobab"<<endl;
		}
};
int main(){
	
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog