Question: Assignment: You'll model a simple thermostat that controls a heating and cooling system by implementing a Thermostat class. The thermostat will have a target temperature

Assignment: You'll model a simple thermostat that controls a heating and cooling system by implementing a Thermostat class. The thermostat will have a target temperature and a current temperature. It can heat or cool to reach the target temperature, and it can display the current state of the system. The class should contain:
a public double data field named currentTemperature;
a public double data field named targetTemperature;
a parameterized constructor that sets the values of the target and current temperature;
a setTargetTemperature that sets a new target temperature;
an increaseCurrentTemperature function that accepts a double input argument amount and increases the current temperature by amount degrees. If increasing the temperature goes beyond the target temperature, the current temperature should be set to the target temperature instead;
a decreaseCurrentTemperature function that accepts a double input argument amount and decreases the current temperature by amount degrees. If decreasing the temperature goes below the target temperature, the current temperature should be set to the target temperature instead;
a getCurrentTemperature function that returns the current temperature;
a getTargetTemperature function that returns the target temperature;
a getStatus function that returns a string indicating whether the system is "Heating", "Cooling", or "At Target Temperature" based on the relationship between the current and target temperatures. For example, if the current temperature is less than the target temperature this method should return "Heating".
All the class attributes and functions are summarised below:
#include
using namespace std;
class Thermostat
{
public:
double currentTemperature; // Current room temperature
double targetTemperature; // Desired target temperature
// Constructor to initialize the thermostat with initial and target temperatures
Thermostat(double initialTemperature, double target);
// Sets a new target temperature
void setTargetTemperature(double newTarget);
// Increases the current temperature, not exceeding the target temperature
void increaseCurrentTemperature(double amount);
// Decreases the current temperature, not falling below the target temperature
void decreaseCurrentTemperature(double amount);
// Returns the current temperature
double getCurrentTemperature();
// Returns the target temperature
double getTargetTemperature();
// Returns a string indicating the heating/cooling status
string getStatus();
};
IN C++

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!