Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Imagine you are working for an in-house software team for a company that wants
- to monitor network access points in a building. Each building has a specified
- number of floors, a certain number of rooms per floor, and some number of network
- access points in a room. Each network access point is labeled with its state as
- being on or off and if it is on it has the month it was turned on. Design,
- implement, and test classes that represent buildings, floors, and network access
- points. Your classes should provide suitable observer methods that allow you to
- determine how many floors are in a building, how many rooms are on a floor, how
- many access points are in a room, and if an access point is on or off and which
- month it was turned on. You should also provide mutator methods that allow you
- to turn a network access point on or off and to set the month if it is turned on.
- You should use composition as a key strategy in designing these classes—thus, a
- building should contain floors, floors should contain rooms, and rooms should
- contain network access points. Your program should allow a user to add additional
- floors, rooms, and access points as well as turn access points on and off. Your
- program should also report errors using exceptions if a room, floor, or access
- point is chosen that does not exist.
- */
- #include <iostream>
- #include <string>
- #include <vector>
- #include <ctype.h>
- using namespace std;
- enum MONTH {
- Null = 0, January, February, March, April, May, June, July, August, September, October, November, December
- };
- class AccessPoint {
- public:
- AccessPoint() {
- isPoweredOn = false;
- monthTurnedOn = 0;
- };
- AccessPoint(bool power, MONTH month) {
- isPoweredOn = power;
- monthTurnedOn = month;
- };
- AccessPoint(bool power, int month) {
- isPoweredOn = power;
- monthTurnedOn = month;
- };
- virtual ~AccessPoint() {
- };
- void PowerOn() {
- isPoweredOn = true;
- };
- void PowerOff() {
- isPoweredOn = false;
- };
- void setMonthTurnedOn(MONTH month) {
- monthTurnedOn = month;
- };
- string getPowerStatus() {
- return isPoweredOn ? "On" : "Off";
- };
- int getMonthTurnedOn() {
- return monthTurnedOn;
- };
- private:
- bool isPoweredOn;
- int monthTurnedOn;
- friend ostream& operator<<(ostream&, const AccessPoint&);
- };
- class Room {
- public:
- vector<AccessPoint> accessPoints;
- Room() {
- };
- Room(int numberOfAccessPoints) {
- for (int i = 0; i < numberOfAccessPoints; i++) {
- AccessPoint *ap1;
- ap1 = new AccessPoint;
- accessPoints.push_back(*ap1);
- }
- };
- ~Room() {
- };
- void addAccessPoint() {
- AccessPoint *ap1;
- ap1 = new AccessPoint;
- accessPoints.push_back(*ap1);
- };
- int getNumberOfAccessPoints() {
- return accessPoints.size();
- };
- private:
- };
- class Floor {
- public:
- vector<Room> rooms;
- Floor() {
- };
- Floor(int numberOfRooms) {
- for (int i = 0; i < numberOfRooms; i++) {
- Room *room1;
- room1 = new Room;
- rooms.push_back(*room1);
- }
- };
- ~Floor() {
- };
- void addRoom() {
- Room *room1;
- room1 = new Room;
- rooms.push_back(*room1);
- };
- int getNumberOfRooms() {
- return rooms.size();
- };
- private:
- };
- class Building {
- public:
- vector<Floor> floors;
- Building() {
- };
- Building(int numberOfFloors) {
- for (int i = 0; i < numberOfFloors; i++) {
- Floor *floor1;
- floor1 = new Floor;
- floors.push_back(*floor1);
- }
- };
- ~Building() {
- };
- void addFloor() {
- Floor *floor1;
- floor1 = new Floor;
- floors.push_back(*floor1);
- }
- int getNumberOfFloors() {
- return floors.size();
- };
- private:
- };
- class BuildingFactory {
- public:
- BuildingFactory() {
- };
- void build() {
- cout << "##############################################################" << endl;
- cout << "# This program will create a building to your specifications #" << endl;
- cout << "##############################################################" << endl;
- cout << "How many floors will be in your building?" << endl;
- cin >> numberOfFloors;
- for (int x = 0; x < numberOfFloors; ++x) {
- building.addFloor();
- cout << "How many rooms on floor number " << x + 1 << "?" << endl;
- cin >> numberOfRooms;
- for (int y = 0; y < numberOfRooms; ++y) {
- building.floors.at(x).addRoom();
- cout << "How many access points are in room " << y + 1 << " on floor " << x + 1 << "?" << endl;
- cin >> numberOfAccessPoints;
- for (int z = 0; z < numberOfAccessPoints; ++z) {
- building.floors.at(x).rooms.at(y).addAccessPoint();
- }
- }
- }
- cout << "##################" << endl;
- cout << "# Done Building #" << endl;
- cout << "##################" << endl;
- }
- Building deliver() {
- return building;
- }
- private:
- int numberOfFloors;
- int numberOfRooms;
- int numberOfAccessPoints;
- int ans2;
- char ans;
- Building building;
- };
- class BuildingManager {
- public:
- BuildingManager(Building building) {
- bldg = building;
- };
- void getStatus() {
- cout << "[-] Status of the building is: " << endl;
- cout << "[-] The building has " << bldg.getNumberOfFloors() << " floors" << endl;
- for (int x = 0; x < bldg.getNumberOfFloors(); x++) {
- cout << "[-] Floor " << x + 1 << " has " << bldg.floors.at(x).getNumberOfRooms() << " rooms" << endl;
- for (int y = 0; y < bldg.floors.at(x).getNumberOfRooms(); y++) {
- cout << "[-] Room number " << y + 1 << " on floor " << x + 1 << " has " << bldg.floors.at(x).rooms.at(y).getNumberOfAccessPoints() << " access points" << endl;
- cout << "[-] Of those access points here are their statuses: " << endl;
- for (int z = 0; z < bldg.floors.at(x).rooms.at(y).getNumberOfAccessPoints(); z++){
- cout << bldg.floors.at(x).rooms.at(y).accessPoints.at(z) << endl;
- }
- }
- }
- };
- void powerOnAP(int floor, int room, int ap, MONTH month) {
- if (ap < bldg.floors.at(floor).rooms.at(room).getNumberOfAccessPoints()) {
- bldg.floors.at(floor).rooms.at(room).accessPoints.at(ap).PowerOn();
- bldg.floors.at(floor).rooms.at(room).accessPoints.at(ap).setMonthTurnedOn(month);
- }
- };
- void powerOffAP(int floor, int room, int ap) {
- if (ap < bldg.floors.at(floor).rooms.at(room).getNumberOfAccessPoints()) {
- bldg.floors.at(floor).rooms.at(room).accessPoints.at(ap).PowerOff();
- bldg.floors.at(floor).rooms.at(room).accessPoints.at(ap).setMonthTurnedOn(Null);
- }
- };
- private:
- Building bldg;
- };
- ostream& operator<<(ostream &strm, const AccessPoint &ap) {
- return strm << "[-] AccessPoint (Power: " << ap.isPoweredOn << "/ Month Powered On: " << ap.monthTurnedOn << ")";
- };
- int main() {
- BuildingFactory bf;
- bf.build();
- BuildingManager bm(bf.deliver());
- bm.powerOnAP(1, 1, 1, December);
- bm.powerOnAP(0, 0, 0, January);
- bm.powerOnAP(0, 1, 1, February);
- bm.powerOnAP(1, 0, 0, March);
- bm.getStatus();
- cout << endl;
- bm.powerOffAP(1, 0, 0);
- cout << "#####################" << endl;
- bm.getStatus();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement