Question: Subject: Polymorphism Write a complete C++ program and create 8 classes that form a class tree as shown in Figure 1. Every class has only

 Subject: Polymorphism Write a complete C++ program and create 8 classes

Subject: Polymorphism Write a complete C++ program and create 8 classes that form a class tree as shown in Figure 1. Every class has only one no-argument constructor, no property. Each class may have an eat0 method and/or a grow) method Both have no return and no parameter. Inside any no- argument constructor, any eat0 method or any grow0 method, there is only one output statement to print "constructor of xxx class" "eat0 method of xxx class" or "grow) method of xxx class", respectively. Here Lion eatO "xxx" represents the current class. Add a line break at the end of the printout. There is no need to split the code due to the simplicity of all classes. Place all 8 classes, main function, and all other functions in a single source file. Hint: the virtual keyword should be applied to overridden methods at the highest tree level such that the dynamic binding could be activated. In this case, only apply the virtual keyword to regular methods in the root class, i.e. the Animal eat0 grow) Fish eat0 Sardine growO Bass Cat eat0 0 Tiger gure Animal class. Without the virtual keyword, the program will do static binding instead Add another function above main() with given code below. void display (const Animal& al) al.eat O al.grow); In the main0 function, create one object for each leaf classes, i.e. classes Sardine, Bass, Tiger, and Lion. Then call both eat0 and grow from each object

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!