← 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 itsarea()returns side times side -Rectanglestores width and height and itsarea()returns width times height The provided main stores both kinds in an array of Shape pointers and prints the total area — the correctarea()is chosen for each object at runtime.
Expected Output:
29= newline. The output ends with a newline — 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.