Write a complete C++ code to simulate the thermostat function for summer and win
ID: 640534 • Letter: W
Question
Write a complete C++ code to simulate the thermostat function for summer and winter season.Explanation / Answer
#ifndef ROOM_H #define ROOM_H #include "thermostat.h" #include "ac.h" #include class Room { public: Room(char* desired_name); // constructor that takes a name ~Room(); // deconstructor char* get_name(); // returns the name of the room int get_temp(); // returns the temp of the room void change_temp(int value); // changes the temp of the room, by a number Thermostat* get_thermostat(); private: char name[20]; // name of the room int temperature; // current temp of the room Thermostat* thermostat_in_room; // pointer to the thermostat in room }; #endif #include "room.h" Room::Room(char* desired_name) { thermostat_in_room = new Thermostat(this); strcpy(name, desired_name); temperature = 65; } Room::~Room() { delete [] thermostat_in_room; } char* Room::get_name() { return name; } int Room::get_temp() { return temperature; } void Room::change_temp(int value) { temperature += value; thermostat_in_room->check_temp(temperature); } Thermostat* Room::get_thermostat() { return thermostat_in_room; } #ifndef AC_H #define AC_H #include "room.h" #include class AC { public: AC(Room* room); ~AC(); // deconstructor char* get_name(); // returns the name of the ac void turn_on(); // turns on AC, if off, lowers temp -1 void turn_off(); // turns off AC, if on private: char name[20]; // name of the ac Room* location; // pointer to the room the ac is in bool state; // on == true, off == false }; #endif #include "ac.h" AC::AC(Room* room) { strcpy(name, room->get_name()); location = room; state = false; } AC::~AC() { delete [] location; } char* AC::get_name() { return name; } void AC::turn_off() { if(state == true) { state = false; std::cout turn_off(); } #include "room.h" int main() { Room test("Room 400"); test.change_temp(5); test.get_thermostat()->change_setting(60); test.change_temp(-5); return 0; }Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.