CJCoding With Joseph
15free / daySign inCreate account

Rectangle and Triangle Shapes

An 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 — print one after the last line.

Hints4 available
Topics:
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.