Polymorphic Array of Shapes
hardQuestion 291The abstract base class Shape declares a pure virtual area(). Complete BOTH derived classes:
- Square stores a side and its area() returns side times side
- Rectangle stores width and height and its area() returns width times height
The provided main stores both kinds in an array of Shape pointers and prints the total area — the correct area() is chosen for each object at runtime.
Expected output
29= newline. The output ends with a newline, so print one after the last line.
Hints2 available
Sign in to use hintsTopics
Inheritance
1
Tab to indent (Esc then Tab to move on) · Ctrl+Enter to run · Shift+Alt+F to format · Ctrl+Space to expand shortcuts (cout, fori)
Your output
Run your code to see the output here...
Test cases
Run your code to see test case results.