Suppose a zoo wants a C++ program to keep track of its animals and to provide in
ID: 3693890 • Letter: S
Question
Suppose a zoo wants a C++ program to keep track of its animals and to provide information for visitors. Suppose the following class is the base class of an public inheritance hierarchy. class Animal { public: Animal( string &nme ); private: string name; // The particular animal’s name }; Animal::Animal( string &nme ) : name( nme ) {} Create a derived class that represents a specific group or family of animals, and derive from that another class that represents an even more specific family or an individual species. For example, your classes could be Bear and PolarBear, or Cat and Lion. Each of your classes should publicly inherit from the next larger class up the inheritance chain (e.g. PolarBear inherits from Bear and Bear inherits from Animal.) Each of your classes should contain a private staticdata member representing something that is true of all objects of that class. (e.g. for PolarBear, it might be a Boolean isWhite). Post the C++ declaration of your two classes and show the constructor code and the initialization of the static data members. Explain your solution
Explanation / Answer
Answer:
By Inheritance Concept C++ code :
class Animal
{
public:
int legs = 4;
};
class Cat : public Animal
{
public:
int tail = 1;
float weight=20.00;
float height_inches=20;
int age=10;
};
class Lion : public Animal
{
public:
int tail = 1;
float weight=50.00;
float height_inches=120;
int age=30;
};
int main()
{
Cat c;
cout << c.legs;
cout << c.tail;
cout<<c.weight;
cout<<c. height_inches;
cout<<c.age;
Lion l;
cout << l.legs;
cout << l.tail;
cout<<l.weight;
cout<<l. height_inches;
cout<<l.age;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.