← Back to Inheritance
Question 291
Polymorphic Array of Shapes
Polymorphic Array of Shapes
The abstract base classShapedeclares a pure virtualarea(). Complete BOTH derived classes: -Squarestores a side and its area() returns side times side -Rectanglestores 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
Topics:
Inheritance
Code Editor
1
Tab to indent · Ctrl+Enter to run · 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.