Bonus Lab, Due 11:59 pm Sunday, May 7. Place in a folder titled Bonus together with other bonus assignments
Define classes that satisfy the conditions below and the hierarchy in this diagram Also, write a good test program.
- A declaration of an object, for a class in the bottom of the hierarchy, should produce a message consisting of the names of all the classes that directly or indirectly are related to the object.
- A declaration of an object for a class not in the bottom of the hierarchy should prompt the compiler to issue an error message (think about how to satisfy this condition.)
- Each defined object should be able to respond to the following functions:
talk-- A parameter-free function that produces a message from the object.
xivore-- A parameter-free function that produces one of "carnivore" or "herbivore" that reflects the kind of object in discourse.
- Each of the classes is allowed to explicitly declare at most two member functions, with at most one of the two not being a constructor.
- The body of each member function should be a single command of the form cout<<" ....";
- A string containing the name of a class may appear only within members of the class. (That is, if A is the name of a class and x is a string "A" referring to A, then x may only be included within members of A)
Example: The program
#include ...
//missing definitions
int main( )
{
leopard l;
l.talk( );
l.xivore( );
system(“pause”);
return 0;
}
should produce an output of the following form
animals carnivore cats leopard
leooo
carnivore