← Back to Exceptions
Question 149
Throw in Constructor
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= newline. The output ends with a newline — print one after the last line.
Hints4 available
Sign in to use hintsTopics:
ClassesExceptions
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.