CJCoding With Joseph
15per day

Throw in Constructor

Create a class Rectangle with private double width and double height.

Requirements:
1. Constructor Rectangle(double w, double h): if either w or h is less than or equal to 0, throw a std::invalid_argument with the message "Dimensions must be positive". Otherwise assign them to the fields.
2. double area() const: returns width * height

Do NOT write a main function.

Expected Output:

50
Topics:
ClassesExceptions
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.