Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #ifndef COMMAND_H
- #define COMMAND_H
- class Command
- {
- public:
- Command() { }
- virtual void execute() { }
- };
- #endif // COMMAND_H
- #ifndef CEILINGFANOFFCOMMAND_H
- #define CEILINGFANOFFCOMMAND_H
- #include "command.h" // Base class: Command
- #include "ceiling_fan.h"
- class CeilingFanOffCommand : public Command
- {
- public:
- CeilingFanOffCommand(CeilingFan *ceilingFan) { m_ceilingFan = ceilingFan; }
- void execute() { m_ceilingFan->off(); }
- private:
- CeilingFan *m_ceilingFan = nullptr;
- };
- #endif // CEILINGFANOFFCOMMAND_H
- #ifndef CEILINGFANONCOMMAND_H
- #define CEILINGFANONCOMMAND_H
- #include "command.h"
- #include "ceiling_fan.h"
- class CeilingFanOnCommand : public Command
- {
- public:
- CeilingFanOnCommand(CeilingFan *ceilingFan) { m_ceilingFan = ceilingFan; }
- void execute() { m_ceilingFan->high(); }
- private:
- CeilingFan *m_ceilingFan = nullptr;
- };
- #endif // CEILINGFANONCOMMAND_H
- #ifndef GARAGEDOOR_H
- #define GARAGEDOOR_H
- #include <iostream>
- class GarageDoor
- {
- public:
- GarageDoor() { }
- void up() { std::cout << "Garage Door is Open" << std::endl; }
- void down() { std::cout << "Garage Door is Closed" << std::endl; }
- void stop() { std::cout << "Garage Door is Stopped" << std::endl; }
- void lightOn() { std::cout << "Garage light is on" << std::endl; }
- void lightOff() { std::cout << "Garage light is off" << std::endl; }
- };
- #endif // GARAGEDOOR_H
- #ifndef GARAGEDOOROPENCOMMAND_H
- #define GARAGEDOOROPENCOMMAND_H
- #include "command.h" // Base class: Command
- #include "garage_door.h"
- class GarageDoorOpenCommand : public Command
- {
- public:
- GarageDoorOpenCommand(GarageDoor garageDoor ) { m_garagedoor = garageDoor; }
- void execute() { m_garagedoor.up(); }
- private:
- GarageDoor m_garagedoor; //pointer??
- };
- #endif // GARAGEDOOROPENCOMMAND_H
- #ifndef HOTTUBOFFCOMMAND_h
- #define HOTTUBOFFCOMMAND_h
- #include "command.h" // Base class: Command
- #include "hottube.h"
- class HotTubOffCommand : public Command
- {
- public:
- HotTubOffCommand(Hottube *hottub) { m_hottub = hottub; }
- void execute() { m_hottub->cool(); m_hottub->off(); }
- private:
- Hottube *m_hottub = nullptr;
- };
- #endif // HOTTUBOFFCOMMAND_h
- #ifndef HOTTUBONCOMMAND_H
- #define HOTTUBONCOMMAND_H
- #include "command.h" // Base class: Command
- #include "hottube.h"
- class HotTubOnCommand : public Command
- {
- public:
- HotTubOnCommand(Hottube *hottub) { m_hottub = hottub; }
- void execute() { m_hottub->on(); m_hottub->heat(); m_hottub->bubblesOn(); }
- private:
- Hottube *m_hottub = nullptr;
- };
- #endif // HOTTUBONCOMMAND_H
- #ifndef HOTTUBE_H
- #define HOTTUBE_H
- #include <iostream>
- #include <string>
- class Hottube
- {
- public:
- Hottube( ) { }
- void on() { m_on = true; }
- void off() { m_on = false; }
- void bubblesOn() { if (m_on) { std::cout << "Hottub is bubbling!\n"; }}
- void bubblesOff() { if (m_on) { std::cout << "Hottub is not bubbling!\n"; }}
- void jetsOn() { if (m_on) { std::cout << "Hottub jets are on!\n"; }}
- void jetsOff() { if (m_on) { std::cout << "Hottub jets are off!\n"; }}
- void setTemperature(int temperature) { m_temperature = temperature; }
- void heat() { m_temperature = 105; std::cout << "Hottub is heating to a steaming 105 degrees\n"; }
- void cool() { m_temperature = 98; std::cout << "Hottub is cooling to 98 degrees\n"; }
- private:
- bool m_on;
- int m_temperature;
- };
- #endif //HOTTUBE_H
- #ifndef LIGHT_H
- #define LIGHT_H
- #include "stdio.h"
- class Light
- {
- public:
- Light() { }
- void on() { printf("%s\n", "Light is on!"); }
- void off() { printf("%s\n", "Light is off!"); }
- };
- #endif // LIGHT_H
- #ifndef LIGHTOFFCOMMAND_H
- #define LIGHTOFFCOMMAND_H
- #include "command.h" // Base class: Command
- #include "light.h"
- class LightOffCommand : public Command
- {
- public:
- LightOffCommand(Light light) { m_light = light; }
- void execute() { m_light.off(); }
- private:
- Light m_light; //pointer ??
- };
- #endif // LIGHTOFFCOMMAND_H
- #ifndef NOCOMMAND_H
- #define NOCOMMAND_H
- #include "command.h" // Base class: Command
- class NoCommand : public Command
- {
- public:
- NoCommand() { }
- void execute() { }
- };
- #endif // NOCOMMAND_H
- #ifndef STEREO_H
- #define STEREO_H
- #include <string>
- #include <iostream>
- class Stereo
- {
- public:
- Stereo(std::string location) { m_location = location; }
- void on() { std::cout << m_location << " stereo is on\n"; }
- void off() { std::cout << m_location << " stereo is off\n"; }
- void setCD() { std::cout << m_location << " stereo is set for CD input\n"; }
- void setDVD() { std::cout << m_location << " stereo is set for DVD input\n"; }
- void setRadio() { std::cout << m_location << " stereo is set for Radio\n"; }
- void setVolume(int volume) { std::cout << m_location << " Stereo volume set to " + volume; }
- private:
- std::string m_location;
- };
- #endif // STEREO_H
- #ifndef STEREOOFFCOMMAND_H
- #define STEREOOFFCOMMAND_H
- #include "command.h" // Base class: Command
- #include "stereo.h"
- class StereoOffCommand : public Command
- {
- public:
- StereoOffCommand(Stereo *stereo) { m_stereo = stereo; }
- virtual void execute() { m_stereo->off(); }
- private:
- Stereo *m_stereo = nullptr;
- };
- #endif // STEREOOFF
- #ifndef STEREOONWITHCDCOMMAND_H
- #define STEREOONWITHCDCOMMAND_H
- #include "command.h" // Base class: Command
- #include "stereo.h"
- class StereoOnWithCdCommand : public Command
- {
- public:
- StereoOnWithCdCommand(Stereo *stereo) { m_stereo = stereo; }
- void execute() { m_stereo->on(); m_stereo->setCD(); m_stereo->setVolume(11); }
- private:
- Stereo *m_stereo = nullptr;
- };
- #endif
- #ifndef TV_H
- #define TV_H
- #include <string>
- #include <iostream>
- class TV
- {
- public:
- TV(std::string location) { m_location = location; }
- void on() { std::cout << "TV is on\n"; }
- void off() { std::cout << "TV is off\n"; }
- void setInputChannel() { m_channel = 3; std::cout << "Channel is set for VCR\n"; }
- private:
- std::string m_location;
- int m_channel;
- };
- #endif // TV_H
- #ifndef REMOTECONTROL_H
- #define REMOTECONTROL_H
- #include "command.h"
- #include "constants.h"
- #include "no_command.h"
- class RemoteControl
- {
- public:
- RemoteControl() {
- for(int index =0; index < NUMBER_OF_COMMANDS; index++) {
- m_on_commands[index] = no_command;
- m_off_commands[index] = no_command;
- }
- }
- void set_command(int slot, Command *on_command, Command *off_command) {
- m_on_commands[slot] = on_command;
- m_off_commands[slot] = off_command;
- }
- void button_was_pressed(int slot) {
- m_on_commands[slot].execute();
- }
- private:
- Command no_command;
- Command m_on_commands[NUMBER_OF_COMMANDS];
- Command m_off_commands[NUMBER_OF_COMMANDS];
- };
- #endif // REMOTECONTROL_H
- #include "garage_door.h"
- #include "light.h"
- #include "garage_door_open_command.h"
- #include "light_off_command.h"
- #include "light_on_command.h"
- #include "remote_control.h"
- #include "ceiling_fan.h"
- #include "ceiling_fan_off_command.h"
- #include "ceiling_fan_on_command.h"
- #include "hottube.h"
- #include "hot_tub_on_command.h"
- #include "hot_tub_off_command.h"
- #include "living_room_light_off_command.h"
- #include "living_room_light_on_command.h"
- #include "stereo.h"
- #include "stereo_off_command.h"
- #include "stereo_on_with_cd_command.h"
- int main(int argc, char **argv)
- {
- RemoteControl remote_control;
- GarageDoor g_door;
- Light light_off;
- Light light_on;
- GarageDoorOpenCommand *g_door_cmd = new GarageDoorOpenCommand(g_door);
- LightOnCommand *l_on = new LightOnCommand(light_on);
- LightOffCommand *l_off = new LightOffCommand(light_off);
- CeilingFan *ceilingFan = new CeilingFan("Living Room");
- CeilingFanOffCommand *fan_off_cmd = new CeilingFanOffCommand(ceilingFan);
- CeilingFanOnCommand *fan_on_cmd = new CeilingFanOnCommand(ceilingFan);
- Hottube *hottub = new Hottube( );
- HotTubOnCommand *tub_on_cmd = new HotTubOnCommand(hottub);
- HotTubOffCommand *tub_off_cmd = new HotTubOffCommand(hottub);
- LivingRoomLightOffCommand *room_light_off_cmd = new LivingRoomLightOffCommand(light_off);
- LivingRoomLightOnCommand *room_on_cmd = new LivingRoomLightOnCommand(light_on);
- Stereo *stereo = new Stereo("Back bed Room");
- StereoOffCommand *stereo_off_cmd = new StereoOffCommand(stereo);
- StereoOnWithCdCommand *stereo_on_cd = new StereoOnWithCdCommand(stereo);
- remote_control.set_command(0, stereo_on_cd, stereo_off_cmd);
- remote_control.set_command(1, room_on_cmd, room_light_off_cmd);
- remote_control.set_command(2, tub_on_cmd, tub_off_cmd);
- remote_control.set_command(3, fan_on_cmd, fan_off_cmd);
- remote_control.button_was_pressed(0);
- remote_control.button_was_pressed(1);
- remote_control.button_was_pressed(2);
- remote_control.button_was_pressed(3);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement