A Thermostat That Refuses Bad Settings
A Thermostat That Refuses Bad Settings
Complete the class Thermostat. Its constructor Thermostat(int celsius) checks the value first: when it is below 5 or above 30 it throws a std::out_of_range with the message Target must be between 5 and 30; otherwise it stores the value and prints Thermostat set to followed by it. Add int getTarget() const returning the stored value. A constructor that throws never finishes, so the object does not exist afterwards: no destructor runs for it and the code after the failed declaration is skipped straight to the catch.
The tests create a few thermostats inside one try, printing Target: and the value after each successful one, print Not created: and the message when one fails, and print End after the handler.
Do NOT write a main function.
Expected Output:
Thermostat set to 21 Target: 21 Not created: Target must be between 5 and 30 End
= newline. The output ends with a newline — print one after the last line.
Your Output
Run your code to see the output here...