The assignment starts at \"Many homes\" and will end below the next solid line..
ID: 3752148 • Letter: T
Question
The assignment starts at "Many homes" and will end below the next solid line......................then you will see my code after you have read the assignment, my code starts at #include <iostream> ....... what I need help on is fixing my code, keep in mind while fixing my code it must match the assignments output exactly how you see in the assignment. i have made it easier on you because my teacher has set comments in my code so wherever you see a comment then there is where code needs to be added and the comment will tell you what to add. C++ CODE ONLY (NOT USING STUDIO) .
_______________________________________________________________________
Many homes nowadays are equipped with what is known as a dual zone Heating, Ventilation, and Air Conditioning (HVAC) system. There is usually one thermostat upstairs and one downstairs, so each floor can be heated or cooled separately. The thermostat is the little control panel on the wall where you can set the desired temperature. There is a controller in the attic that handles the logic of when to run the AC, when to run the furnace, and which floor to allow air flow into. The air flow is controlled by what is called a damper. The damper is a valve that either opens or closes the pipe where air flows into a floor. There is one damper on each floor.
You will write the code for a hyptothetical dual zone HVAC controller. Here are the requirements:
Initialize the zone 1 temperature and zone 1 thermostat to 75 degrees
Initialize the zone 2 temperature and zone 2 thermostat to 80 degrees
Initialize the controller status to HVAC OFF
Initialize both dampers to CLOSED
Run a loop that prints the status of the system and asks for user input with the following numerical menu:
Allow the user to set the thermostats for each floor to a desired temperature
Assume that waiting 1 turn will wait the amount of time for the house to change by 1 degree
If the damper is open for a floor, then add 1 degree per turn if the furnace is on and subtract 1 per turn if the AC is on
Waiting 10 turns will change the house by 10 degrees, or reach a stable temperature, whichever comes first
Note that in the initial setup above, since the thermostats match the zone temperatures, the HVAC system is stable and will not turn anything on.
If a thermostat setting is less than its zone temperature, set the status to AC ON and open the damper for that zone.
If a thermostat setting is greater than its zone temperature, set the status to FURNACE ON and open the damper for that zone.
AC ON takes priority over FURNACE ON. You can't have both at the same time.
If a thermostat setting is equal to its zone temperature, close the damper for that zone.
If both thermostats are equal to their zone temperatures, set the status to HVAC OFF
A sample run of the program where cooling is activated and then stabilized for both zones is as follows. Note: Your output must exactly match for full points.
A sample run where heating is activated for both zones and is stabilized is as follows:
A sample run where the wait 10 turns feature is utilized is as follows:
________________________________________________________________________
#include <iostream>
using namespace std;
enum HvacStatus {HVAC_OFF, AC_ON, FURNACE_ON};
void print(int, int, int, int, bool, bool, HvacStatus);
void wait_1_turn(int&, int&, int, int, bool&, bool&, HvacStatus&);
void updateState(int&, int&, int, int, bool&, bool&, HvacStatus&);
int main()
{
int zone1_temp = 75;
int zone2_temp = 80;
int temp1 = 75;
int temp2 = 80;
bool damp1_close = true;
bool damp2_close = true;
HvacStatus status = HVAC_OFF;
/* dont fix this part
bool hvac_off = true;
bool ac_off1 = true;
bool ac_off2 = true;
dont fix this line ^^*/
int choice;
print(zone1_temp, zone2_temp, temp1, temp2, damp1_close, damp2_close, status);
cin >> choice;
while (choice!=0)
{
if (choice == 1)
{
cout << "Set the thermostat for zone 1: ";
cin >> temp1;
cout << endl;
cout << "Set the thermostat for zone 2: ";
cin >> temp2;
cout << endl;
updateState(zone1_temp, zone2_temp, temp1, temp2, damp1_close, damp2_close, status);
}
else if (choice ==2)
{
wait_1_turn(zone1_temp, zone2_temp, temp1, temp2, damp1_close, damp2_close, status);
}
else if (choice == 3)
{
for (int i=0; i<10; i++)
{
wait_1_turn(zone1_temp, zone2_temp, temp1, temp2, damp1_close, damp2_close, status);
}
}
else
{
cout<< "Wrong choice entered."
<< endl;
}
print(zone1_temp, zone2_temp, temp1, temp2, damp1_close, damp2_close, status);
cin>>choice;
}
return 0;
}
void print(int zone1_temp, int zone2_temp, int temp1, int temp2, bool damp1_close, bool damp2_close, HvacStatus status)
{
if (status == HVAC_OFF)
{
cout << "HVAC OFF"< }
else
{
if (status == AC_ON)
{
cout << "AC ON" << endl;
}
//Else if the AC is on.
else
{
cout << "FURNACE ON" << endl ;
}
}
if (damp1_close)
{
cout << "Zone 1 damper is closed"< }
else
{
cout << "Zone 1 damper is open" << endl;
}
if (damp2_close)
{
cout << "Zone 2 damper is closed"< }
else
{
cout << "Zone 2 damper is open" < }
cout << "Zone 1 temperature: "< cout << "Zone 2 temperature: "< cout << "Enter a menu choice: "<
cout << "0) Quit" << endl;
cout << "1) Set thermostats" << endl;
cout << "2) Wait 1 turn" << endl;
cout << "3) Wait 10 turns" << endl;
}
void wait_1_turn(int &zone1_temp, int &zone2_temp, int temp1, int temp2, bool &damp1_close, bool &damp2_close, HvacStatus &status)
{
///if status is AC_ON, drop 1 degree for zones whose dampers are open
///otherwise, if status is FURNACE_ON, raise by 1 degree zones whose dampers are open
///otherwise do nothing because status is HVAC_OFF
updateState(zone1_temp, zone2_temp, temp1, temp2, damp1_close, damp2_close, status);
}
void updateState(int &zone1_temp, int &zone2_temp, int temp1, int temp2, bool &damp1_close, bool &damp2_close, HvacStatus &status)
{
//Check if AC is on for either of the zones.
if(temp1 < zone1_temp || temp2 < zone2_temp)
{
///set state to cooling
if (temp1 < zone1_temp)
{
///open zone1 damper
//zone1_temp--;
}
if (temp2 < zone2_temp)
{
///open zone2 damper
//zone2_temp--;
}
}
///**********FIX ME***********
else if(false) ///see if either floor wants to heat
{
///set status to heat
if(temp1 > zone1_temp)
{
///damper
//zone1_temp++;
}
if(temp2 > zone2_temp)
{
///damper
//zone2_temp++;
}
}
else
{
///close dampers, set status to off
}
Explanation / Answer
Hi,
I have explained my modifications in the code itself with the help of comments.
Please find the below the working code which passed all test cases :
<start of code>
----------------------------------------------------------------------------------------------------------
#include <iostream>
using namespace std;
enum HvacStatus {HVAC_OFF, AC_ON, FURNACE_ON};
void print(int, int, int, int, bool, bool, HvacStatus);
void wait_1_turn(int&, int&, int, int, bool&, bool&, HvacStatus&, bool);
void updateState(int&, int&, int, int, bool&, bool&, HvacStatus&, bool);
int main()
{
int zone1_temp = 75;
int zone2_temp = 80;
int temp1 = 75;
int temp2 = 80;
bool damp1_close = true;
bool damp2_close = true;
//To check whether to update the value of zone_temp or not
bool update_temp = false;
HvacStatus status = HVAC_OFF;
/* dont fix this part
bool hvac_off = true;
bool ac_off1 = true;
bool ac_off2 = true;
dont fix this line ^^*/
int choice;
print(zone1_temp, zone2_temp, temp1, temp2, damp1_close, damp2_close, status);
cin >> choice;
while (choice!=0)
{
if (choice == 1)
{
cout << "Set the thermostat for zone 1: ";
cin >> temp1;
cout << endl;
cout << "Set the thermostat for zone 2: ";
cin >> temp2;
cout << endl;
//print(zone1_temp, zone2_temp, temp1, temp2, damp1_close, damp2_close, status);
updateState(zone1_temp, zone2_temp, temp1, temp2, damp1_close, damp2_close, status,update_temp);
}
else if (choice ==2)
{
update_temp = true;
wait_1_turn(zone1_temp, zone2_temp, temp1, temp2, damp1_close, damp2_close, status,update_temp);
}
else if (choice == 3)
{
update_temp = true;
for (int i=0; i<10; i++)
{
wait_1_turn(zone1_temp, zone2_temp, temp1, temp2, damp1_close, damp2_close, status,update_temp);
}
}
else
{
cout<< "Wrong choice entered."
<< endl;
}
print(zone1_temp, zone2_temp, temp1, temp2, damp1_close, damp2_close, status);
cin>>choice;
}
return 0;
}
void print(int zone1_temp, int zone2_temp, int temp1, int temp2, bool damp1_close, bool damp2_close, HvacStatus status)
{
if (status == HVAC_OFF)
{
cout << "HVAC OFF"<< endl;
}
else
{
if (status == AC_ON)
{
cout << "AC ON" << endl;
}
//Else if the AC is on.
else
{
cout << "FURNACE ON" << endl ;
}
}
cout << "Zone 1 thermostat: "<<temp1<<endl;
cout << "Zone 2 thermostat: "<<temp2<<endl;
if (damp1_close)
{
cout << "Zone 1 damper is CLOSED"<< endl;
}
else
{
cout << "Zone 1 damper is OPEN" << endl;
}
if (damp2_close)
{
cout << "Zone 2 damper is CLOSED"<< endl;
}
else
{
cout << "Zone 2 damper is OPEN" << endl;
}
cout << "Zone 1 temperature: "<<zone1_temp<<endl;
cout << "Zone 2 temperature: "<<zone2_temp<<endl;
cout << "Enter a menu choice: "<<endl;
cout << "0) Quit" << endl;
cout << "1) Set thermostats" << endl;
cout << "2) Wait 1 turn" << endl;
cout << "3) Wait 10 turns" << endl;
}
void wait_1_turn(int &zone1_temp, int &zone2_temp, int temp1, int temp2, bool &damp1_close, bool &damp2_close, HvacStatus &status, bool update_temp)
{
///if status is AC_ON, drop 1 degree for zones whose dampers are open
///otherwise, if status is FURNACE_ON, raise by 1 degree zones whose dampers are open
///otherwise do nothing because status is HVAC_OFF
updateState(zone1_temp, zone2_temp, temp1, temp2, damp1_close, damp2_close, status,update_temp);
}
void updateState(int &zone1_temp, int &zone2_temp, int temp1, int temp2, bool &damp1_close, bool &damp2_close, HvacStatus &status, bool update_temp)
{
//Check if AC is on for either of the zones.
//Checking if zone_temp is greater than temp. If yes, then set status to AC_ON
if(temp1 < zone1_temp || temp2 < zone2_temp)
{
///set state to cooling
status = AC_ON;
//If temp1 is smaller than open the zone 1 damper
if (temp1 != zone1_temp && temp1 < zone1_temp)
{
///open zone1 damper
damp1_close = false;
//checking whether we have to update the value of zone_temp
if(update_temp)
{
zone1_temp--;
}
//If temp and zone_temp are equal then closing the damper
if(temp1 == zone1_temp)
{
damp1_close = true;
}
}
if (temp2 != zone2_temp && temp2 < zone2_temp)
{
///open zone2 damper
damp2_close = false;
//checking whether we have to update the value of zone_temp
if(update_temp)
{
zone2_temp--;
}
//If temp and zone_temp are equal then closing the damper
if(temp2 == zone2_temp)
{
damp2_close = true;
}
}
////If temp and zone_temp are equal then closing the damper and setting the status as HVAC_OFF
if(temp1 == zone1_temp && temp2 == zone2_temp)
{
status = HVAC_OFF;
damp1_close = true;
damp2_close = true;
}
}
///**********FIX ME***********
///see if either floor wants to heat
else if(temp1 > zone1_temp || temp2 > zone2_temp)
{
///set status to heat
status = FURNACE_ON;
if(temp1 != zone1_temp && temp1 > zone1_temp)
{
damp1_close = false;
//checking whether we have to update the value of zone_temp
if(update_temp)
{
zone1_temp++;
}
////If temp and zone_temp are equal then closing the damper
if(temp1 == zone1_temp)
{
damp1_close = true;
}
}
if(temp2 != zone2_temp && temp2 > zone2_temp)
{
///damper
damp2_close = false;
//checking whether we have to update the value of zone_temp
if(update_temp)
{
zone2_temp++;
}
//If temp and zone_temp are equal then closing the damper
if(temp2 == zone2_temp)
{
damp2_close = true;
}
}
////If temp and zone_temp are equal then closing the damper and setting the status as HVAC_OFF
if(temp1 == zone1_temp && temp2 == zone2_temp)
{
status = HVAC_OFF;
damp1_close = true;
damp2_close = true;
}
}
////If temp and zone_temp are equal then closing the damper and setting the status as HVAC_OFF
else
{
status = HVAC_OFF;
damp1_close = true;
damp2_close = true;
}
}
---------------------------------------------------------------------------------------------------------
<End of Code>
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.