From b567f31ead33d1313e848917dbabdb11853356f1 Mon Sep 17 00:00:00 2001 From: BinHong Lee Date: Tue, 3 Jan 2017 10:26:14 -0700 Subject: [PATCH] Added Vehicle class - No compilation error - Actual functionaility not tested yet --- Person.cpp | 4 +- Person.hpp | 2 +- Vehicle.cpp | 125 ++++++++++++++++++++++++++++++++++++++++++++++++++++ Vehicle.hpp | 37 ++++++++++++++++ 4 files changed, 165 insertions(+), 3 deletions(-) create mode 100644 Vehicle.cpp create mode 100644 Vehicle.hpp diff --git a/Person.cpp b/Person.cpp index cf380a0..62f16d6 100644 --- a/Person.cpp +++ b/Person.cpp @@ -8,9 +8,9 @@ using namespace std; //Empty constructor -Person::Person() +Person::Person(int id) { - + this->id = id; } //Complete comstructor diff --git a/Person.hpp b/Person.hpp index b6c34d3..e7cca25 100644 --- a/Person.hpp +++ b/Person.hpp @@ -12,7 +12,7 @@ class Person int id; public : - Person(); + Person(int id); Person(string, string, string, string, int); void setName(string); string getName(); diff --git a/Vehicle.cpp b/Vehicle.cpp new file mode 100644 index 0000000..0af65c4 --- /dev/null +++ b/Vehicle.cpp @@ -0,0 +1,125 @@ +#include +#include "Vehicle.hpp" +using namespace std; + +Vehicle::Vehicle(int length, int width, int id) +{ + this->length = length; + this->width = width; + this->id = id; + initialize(); +} + +Vehicle::Vehicle(string type, int length, int width, string origin, string destination, string dateNtime, int id) +{ + this->type = type; + this->length = length; + this->width = width; + this->origin = origin; + this->destination = destination; + this->dateNtime = dateNtime; + this->id = id; + initialize(); +} + +void Vehicle::setType(string type) +{ + this->type = type; +} + +void Vehicle::setOrigin(string origin) +{ + this->origin = origin; +} + +void Vehicle::setDestination(string destination) +{ + this->destination = destination; +} + +string Vehicle::getType() +{ + return type; +} + +int Vehicle::getLength() +{ + return length; +} + +int Vehicle::getWidth() +{ + return width; +} + +string Vehicle::getOrigin() +{ + return origin; +} + +string Vehicle::getDestination() +{ + return destination; +} + +string Vehicle::getDateNTime() +{ + return dateNtime; +} + +int Vehicle::getId() +{ + return id; +} + +void Vehicle::initialize() +{ + for (int i = 0; i < length; i++) + { + vector row; + for (int j = 0; j < width; j++) + { + row.push_back(-1); + } + seatMap.push_back(row); + } +} + +bool Vehicle::bookSeat(int x, int y, int guestId) +{ + if (seatMap[x][y] == -1) + { + seatMap[x][y] = guestId; + return true; + } + + return false; +} + +bool Vehicle::checkAvailabilty(int x, int y) +{ + return seatMap[x][y] == -1; +} + +void Vehicle::printMap(int guestId) +{ + for (int i = 0; i < length; i++) + { + for (int j = 0; j < width; j++) + { + if (seatMap[i][j] == -1) + { + cout << "A "; + } + else if (seatMap[i][j] == guestId) + { + cout << "U "; + } + else + { + cout << "X "; + } + } + cout << endl; + } +} diff --git a/Vehicle.hpp b/Vehicle.hpp new file mode 100644 index 0000000..ddadcaa --- /dev/null +++ b/Vehicle.hpp @@ -0,0 +1,37 @@ +#include +#include +#include +using namespace std; + +class Vehicle +{ +private: + string type; + int length; + int width; + string origin; + string destination; + string dateNtime; + int id; + vector< vector > seatMap; + +public: + Vehicle(int length, int width, int id); + Vehicle(string type, int length, int width, string origin, string destination, string dateNtime, int id); + void setType(string type); + void setLength(int length); + void setWidth(int width); + void setOrigin(string origin); + void setDestination(string origin); + string getType(); + int getLength(); + int getWidth(); + string getOrigin(); + string getDestination(); + string getDateNTime(); + int getId(); + void initialize(); + bool bookSeat(int x, int y, int guestId); + bool checkAvailabilty(int x, int y); + void printMap(int guestId); +};