Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * File: applianceList.cpp
- * Author: andrew
- *
- * Created on October 11, 2010, 3:38 PM
- */
- #include "applianceList.h"
- applianceList::applianceList()
- {
- appliance washer; //0
- washer.name = "Washer";
- washer.on = false;
- appliance tv; //1
- tv.name = "TV";
- tv.on = false;
- appliance light1; //2
- light1.name = "Hall Light";
- light1.on = false;
- appliance light2; //3
- light2.name = "Bedroom Light";
- light2.on = false;
- appliances.push_back(washer);
- appliances.push_back(tv);
- appliances.push_back(light1);
- appliances.push_back(light2);
- }
- applianceList::~applianceList()
- {
- }
- string applianceList::list_all()
- {
- string returnString;
- for(int i = 0; i < appliances.size(); i++)
- {
- appliance currApp = appliances.at(i);
- returnString += currApp.name;
- returnString += ": ";
- if(currApp.on)
- {
- returnString += "ON\n";
- }
- else
- {
- returnString += "OFF\n";
- }
- }//end for
- return returnString;
- }
- string applianceList::status_of(int app)
- {
- if (app < 0 || app >= appliances.size())
- {
- return "Oh no's, there are no appliance here\n";
- }
- appliance temp = appliances.at(app);
- string returnString;
- returnString += temp.name;
- returnString += ": ";
- if(temp.on)
- {
- returnString += "ON\n";
- }
- else
- {
- returnString += "OFF\n";
- }
- return returnString;
- }
- bool applianceList::turn_onoff(int app)
- {
- if (app < 0 || app >= appliances.size())
- {
- return false;
- }
- appliance *temp = &appliances.at(app);
- if (temp->on)
- {
- temp->on = false;
- }
- else
- {
- temp->on = true;
- }
- return true;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement