Question
1. In this assignment, using C++ you will be using inheritance and polymorphism to implement a similar structure to the drawing/shape example in the lecture.
1. In this assignment, using C++ you will be using inheritance and polymorphism to implement a similar structure to the drawing/shape example in the lecture. For this, you will need to design and write a base class and three derived classes that inherit from the base (similar to the shape class and the derived shape classes). You will also need a manager object that will hold a (fixed) array of pointers to your base type (similar to the drawing class).
2. The base class may or may not have any member variables itself, depending on your design. The derived classes should have at least one member each to describe the structure of that class.
3. There should be at least one virtual function in the base class that each derived class will override. The base class virtual function should be pure virtual (a.k.a. abstract) unless the base does indeed have an implementation. Each derived types override of the virtual function should cause some output to std::cout to indicate that it was invoked.
4. Each class should include a full set of constructors to initialize their member(s) as well as the base class. Each derived class should call the base class constructor in their initialization lists if needed.
5. Your manager class will have an array of pointers to the base type that it manages and a method to add objects (by pointer-to-base) into the array and track how many items have been added.
6. Include a function in the manager class that will loop through all of the objects in the array and invoke the virtual function for each element (just like drawing::draw looped through all of its shapes).
7. In your main function, instantiate a manager object.
8. Add several objects of your types to the manager object. These objects will have to be created dynamically (with new) and passed into the function you made in (5) that will add the objects to the array.
9. Call the manager objects function from (6) that will loop through all objects you just added.
10. Make sure that the managers constructor cleans up all of its objects when the manager object goes out of scope.
11. Place all classes in their own headers (protecting against multiple inclusion) and in a namespace of your own choosing.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started