← Back to Abstract Classes
Question 172
Rectangle and Triangle Shapes
Rectangle and Triangle Shapes
An abstract base classShapeis provided with pure virtual methodsgetArea()andgetPerimeter(). Create two classes that inherit fromShape: Rectangle:Rectangle(double width, double height): -getArea()returnswidth * height-getPerimeter()returns2 * (width + height)Triangle (right triangle):Triangle(double base, double height, double hypotenuse): -getArea()returns0.5 * base * height-getPerimeter()returnsbase + height + hypotenuseDo 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
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.