Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

image text in transcribed

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 eat() method and/or a grow() method. Both have no return and no parameter. Inside any no argument constructor, any eat() method or any grow() method, there is only one output statement to print "constructor of xxx class", "eat() method of xxx class", or "grow() method of xxx class", respectively. Here "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 class. Without the virtual keyword, the program will do static binding instead.

In the main() function, create one object for each leaf classes, i.e. classes Sardine, Bass, Tiger, and Lion. Then call both eat() and grow() from each object.

Subject: Polymorphism Write a complete C+tprogram 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 eat) method or any growO Animal eat0 grow) Fish eat grow0BasseaCat eat0 Catmethod, there is only one output stat "constructor of xxx class", "eat method of xxx class", or "grow0 method of xxx class", respectively. Here Lion ct "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 Tiger Figure l 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 al.grow) In the main0 function, create one object for each leaf classes, i.e. classes Sardine, Bass, Tiger, and Lion. Then call both eat() and grow from each object. After successful debugging and running the project, carefully observe the printout and write your own explanation to a text file named "readme.txt". Note that the "readme.txt" accounts for 30 points. Place this file in the source file folder of clearly explain why the printout is as observed. In details, answer following questions your proj ect. The file should have at least 80 words. The file should 1) What is polymorphism? (5 points) 2) How to enable dynamic binding? (5 points) 3) What are rules of dynamic binding? (10 points) 4) How rules of dynamic binding affect the printout? (10 points)

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

Step: 3

blur-text-image

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

Concepts of Database Management

Authors: Philip J. Pratt, Mary Z. Last

8th edition

1285427106, 978-1285427102

More Books

Students also viewed these Databases questions

Question

How many Tables Will Base HCMSs typically have? Why?

Answered: 1 week ago

Question

What is the process of normalization?

Answered: 1 week ago