Rectangle and Triangle Shapes
mediumQuestion 172An abstract base class Shape is provided with pure virtual methods getArea() and getPerimeter().
Create two classes that inherit from Shape:
Rectangle: Rectangle(double width, double height):
- getArea() returns width * height
- getPerimeter() returns 2 * (width + height)
Triangle (right triangle): Triangle(double base, double height, double hypotenuse):
- getArea() returns 0.5 * base * height
- getPerimeter() returns base + height + hypotenuse
Do NOT write a main function.
Expected output
20 18 6 12
= newline. The output ends with a newline, so print one after the last line.
Hints4 available
Sign in to use hintsTopics
Abstract Classes
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.