← Back to Classes
Question 149
Throw in Constructor
Throw in Constructor
Create a classRectanglewith privatedouble widthanddouble height. Requirements: 1. ConstructorRectangle(double w, double h): if eitherworhis less than or equal to 0, throw astd::invalid_argumentwith the message"Dimensions must be positive". Otherwise assign them to the fields. 2.double area() const: returnswidth * heightDo 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.