← Back to Inheritance
Question 139
Derived Class With New Members
Derived Class With New Members
You are given a base class Shape with a protected string color and a constructor. Create a derived class Rectangle that: - Publicly inherits from Shape - Has private members: double width and double height - Has a constructor that takes color, width, and height (use initialization list to call base constructor and set both members) - Has a functiongetArea()that returns width * height - Has a functiondescribe()that prints: "[color] Rectangle: [area]" For example, a red rectangle with width 5 and height 3 should print the output shown in Expected Output. Do NOT include a main function. Your code will be tested automatically.
Expected Output:
red Rectangle: 15= newline. The output ends with a newline — print one after the last line.
Hints4 available
Sign in to use hintsTopics:
ClassesInheritance
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.