Create a hierarchy of shapes using the following guidelines: 1. Create an abstract base class called shape,

Question:

Create a hierarchy of shapes using the following guidelines:

1. Create an abstract base class called shape, which defines an operation to compute the area of a shape. Do not include a method for the Area () operation. Hint: use a pure virtual function.

2. Derive classes Rectangle, Circle, and Triangle from shape using public inheritance. Optionally, derive class square from Rectangle. Redefine the operation Area () that shape has introduced, in each derived class. Be sure to provide the method to support the operation in each derived class so that you can later instantiate each type of shape.

3. Add data members and other member functions as necessary to complete the newly introduced class definitions. Remember, only common attributes and operations should be specified in Shape - all others belong in their respective derived classes. Don't forget to implement the copy constructor and access functions within each class definition.

4. Create an array of pointers of the abstract class type, shape. Assign elements in this array point to instances of type Rectangle, Square, Circle, and Triangle. Since you are now treating derived class objects as generalized shape objects, loop through the array of pointers and invoke the Area () function for each. Be sure to delete () any dynamically allocated memory you have allocated.
5. Is your abstract shape class also an interface class in conceptual OO terms? Why, or why not?

Fantastic news! We've Found the answer you've been seeking!

Step by Step Answer: