CJCoding With Joseph

Polymorphic Array of Shapes

The 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
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.