Advertisement
Guest User

applianceList.cpp

a guest
Oct 13th, 2010
223
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.83 KB | None | 0 0
  1. /*
  2.  * File:   applianceList.cpp
  3.  * Author: andrew
  4.  *
  5.  * Created on October 11, 2010, 3:38 PM
  6.  */
  7.  
  8. #include "applianceList.h"
  9.  
  10. applianceList::applianceList()
  11. {
  12.     appliance washer; //0
  13.     washer.name = "Washer";
  14.     washer.on = false;
  15.  
  16.     appliance tv; //1
  17.     tv.name = "TV";
  18.     tv.on = false;
  19.  
  20.     appliance light1; //2
  21.     light1.name = "Hall Light";
  22.     light1.on = false;
  23.  
  24.     appliance light2; //3
  25.     light2.name = "Bedroom Light";
  26.     light2.on = false;
  27.  
  28.     appliances.push_back(washer);
  29.     appliances.push_back(tv);
  30.     appliances.push_back(light1);
  31.     appliances.push_back(light2);
  32. }
  33. applianceList::~applianceList()
  34. {
  35. }
  36.  
  37. string applianceList::list_all()
  38. {
  39.     string returnString;
  40.     for(int i = 0; i < appliances.size(); i++)
  41.     {
  42.         appliance currApp = appliances.at(i);
  43.         returnString += currApp.name;
  44.         returnString += ": ";
  45.  
  46.         if(currApp.on)
  47.         {
  48.             returnString += "ON\n";
  49.         }
  50.         else
  51.         {
  52.             returnString += "OFF\n";
  53.         }
  54.     }//end for
  55.  
  56.     return returnString;
  57. }
  58.  
  59. string applianceList::status_of(int app)
  60. {
  61.     if (app < 0 || app >= appliances.size())
  62.     {
  63.         return "Oh no's, there are no appliance here\n";
  64.     }
  65.  
  66.     appliance temp = appliances.at(app);
  67.  
  68.     string returnString;
  69.     returnString += temp.name;
  70.     returnString += ": ";
  71.     if(temp.on)
  72.     {
  73.         returnString += "ON\n";
  74.     }
  75.     else
  76.     {
  77.         returnString += "OFF\n";
  78.     }
  79.  
  80.     return returnString;
  81. }
  82.  
  83. bool applianceList::turn_onoff(int app)
  84. {
  85.     if (app < 0 || app >= appliances.size())
  86.     {
  87.         return false;
  88.     }
  89.  
  90.     appliance *temp = &appliances.at(app);
  91.  
  92.     if (temp->on)
  93.     {
  94.         temp->on = false;
  95.     }
  96.     else
  97.     {
  98.         temp->on = true;
  99.     }
  100.  
  101.     return true;
  102. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement