CJCoding With Joseph
15per day

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 function getArea() that returns width * height
- Has a function describe() that prints: "[color] Rectangle: [area]"

For example, a red rectangle with width 5 and height 3 should print:
red Rectangle: 15

Do NOT include a main function. Your code will be tested automatically.

Expected output:
red Rectangle: 15

Expected Output:

red Rectangle: 15
Topics:
ClassesInheritance
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.