- Fixed minor error in LogInSystem - Added VehicleManager.cpp - Added main.cpp where main() will be migrated toFixing-travis-yml
@@ -6,9 +6,11 @@ | |||||
#include <iostream> | #include <iostream> | ||||
#include <fstream> | #include <fstream> | ||||
#include <json/json.h> | |||||
#include <string> | #include <string> | ||||
#include <vector> | #include <vector> | ||||
#include "Person.cpp" | #include "Person.cpp" | ||||
#include "Vehicle.cpp" | |||||
using namespace std; | using namespace std; | ||||
//Declaration of functions | //Declaration of functions | ||||
@@ -24,9 +26,10 @@ string chgPassword(Person); | |||||
string chgEmail(); | string chgEmail(); | ||||
string chgPhoneNo(); | string chgPhoneNo(); | ||||
vector<Vehicle> vehicles; | |||||
vector<Person> users; | vector<Person> users; | ||||
static int wrongPass = 0; | static int wrongPass = 0; | ||||
static int globalId; | |||||
static int globalUserId; | |||||
int main() | int main() | ||||
{ | { | ||||
@@ -46,8 +49,43 @@ int main() | |||||
} | } | ||||
users.pop_back(); | users.pop_back(); | ||||
globalUserId = users.back().getId() + 1; | |||||
/* | |||||
ifstream otherFin("vehiclesData.txt"); | |||||
while (!otherFin.eof()) | |||||
{ | |||||
string type; | |||||
int length; | |||||
int width; | |||||
string origin; | |||||
string destination; | |||||
string dateNtime; | |||||
int id; | |||||
otherFin >> type >> length >> width >> origin >> destination >> dateNtime >> id; | |||||
vector< vector<int> > seatMap; | |||||
for (int i = 0; i < length; i++) | |||||
{ | |||||
vector<int> row; | |||||
for (int j = 0; j < width; j++) | |||||
{ | |||||
int temp; | |||||
otherFin >> temp; | |||||
row.push_back(temp); | |||||
} | |||||
seatMap.push_back(row); | |||||
} | |||||
Vehicle newVehicle(type, length, width, origin, destination, dateNtime, id, seatMap); | |||||
vehicles.push_back(newVehicle); | |||||
} | |||||
vehicles.pop_back(); | |||||
*/ | |||||
globalId = users.back().getId() + 1; | |||||
int userOption = -1; | int userOption = -1; | ||||
while (userOption != 0) | while (userOption != 0) | ||||
@@ -114,7 +152,7 @@ Person getUser(int toSearchId) | |||||
bool login() | bool login() | ||||
{ | { | ||||
Person currentUser; | |||||
Person currentUser(-1); | |||||
string username; | string username; | ||||
string password; | string password; | ||||
//If the user already has 3 fail attempt to login | //If the user already has 3 fail attempt to login | ||||
@@ -213,10 +251,10 @@ Person registration() | |||||
cin >> phoneNo; | cin >> phoneNo; | ||||
//Create and push the new 'Person' into stack | //Create and push the new 'Person' into stack | ||||
Person newUser(username, password, email, phoneNo, globalId); | |||||
Person newUser(username, password, email, phoneNo, globalUserId); | |||||
users.push_back(newUser); | users.push_back(newUser); | ||||
globalId++; | |||||
globalUserId++; | |||||
//Print success message | //Print success message | ||||
cout << "Account is successfully registered." << endl; | cout << "Account is successfully registered." << endl; | ||||
@@ -4,6 +4,10 @@ using namespace std; | |||||
Vehicle::Vehicle(int length, int width, int id) | Vehicle::Vehicle(int length, int width, int id) | ||||
{ | { | ||||
type = "TBA"; | |||||
origin = "TBA"; | |||||
destination = "TBA"; | |||||
dateNtime = "TBA"; | |||||
this->length = length; | this->length = length; | ||||
this->width = width; | this->width = width; | ||||
this->id = id; | this->id = id; | ||||
@@ -22,6 +26,18 @@ Vehicle::Vehicle(string type, int length, int width, string origin, string desti | |||||
initialize(); | initialize(); | ||||
} | } | ||||
Vehicle::Vehicle(string type, int length, int width, string origin, string destination, string dateNtime, int id, vector< vector<int> > seatMap) | |||||
{ | |||||
this->type = type; | |||||
this->length = length; | |||||
this->width = width; | |||||
this->origin = origin; | |||||
this->destination = destination; | |||||
this->dateNtime = dateNtime; | |||||
this->id = id; | |||||
this->seatMap = seatMap; | |||||
} | |||||
void Vehicle::setType(string type) | void Vehicle::setType(string type) | ||||
{ | { | ||||
this->type = type; | this->type = type; | ||||
@@ -18,6 +18,7 @@ private: | |||||
public: | public: | ||||
Vehicle(int length, int width, int id); | Vehicle(int length, int width, int id); | ||||
Vehicle(string type, int length, int width, string origin, string destination, string dateNtime, int id); | Vehicle(string type, int length, int width, string origin, string destination, string dateNtime, int id); | ||||
Vehicle(string type, int length, int width, string origin, string destination, string dateNtime, int id, vector< vector<int> > seatMap); | |||||
void setType(string type); | void setType(string type); | ||||
void setLength(int length); | void setLength(int length); | ||||
void setWidth(int width); | void setWidth(int width); | ||||
@@ -0,0 +1,28 @@ | |||||
#include <string> | |||||
#include <vector> | |||||
#include <iostream> | |||||
#include <json/json.h> | |||||
#include "VehicleManager.hpp" | |||||
using namespace std; | |||||
VehicleManager::VehicleManager() | |||||
{ | |||||
} | |||||
VehicleManager::VehicleManager(string jsonFile) | |||||
{ | |||||
ifstream jsonFile(jsonFile.c_str()); | |||||
Json::Reader reader; | |||||
Json::Value vehicle; | |||||
ifstream json(jsonFile.c_str(), ifstream::binary); | |||||
bool parseSuccess = reader.parse(json, vehicle, false); | |||||
if(parseSuccess) | |||||
{ | |||||
} | |||||
} |
@@ -0,0 +1,18 @@ | |||||
#include <string> | |||||
#include <vector> | |||||
#include "Vehicle.hpp" | |||||
using namespace std; | |||||
class VehicleManager | |||||
{ | |||||
private: | |||||
vector<Vehicle> vehicles; | |||||
public: | |||||
VehicleManager(); | |||||
VehicleManager(string jsonFile); | |||||
bool add(Vehicle newVehicle); | |||||
bool remove(Vehicle toRemove); | |||||
Vehicle get(int id); | |||||
void toJson(string jsonFile); | |||||
} |
@@ -0,0 +1,17 @@ | |||||
#include <string> | |||||
#include <vector> | |||||
#include <iostream> | |||||
#include <json/json.h> | |||||
#include "VehicleManager.cpp" | |||||
using namespace std; | |||||
int main() | |||||
{ | |||||
Vehicle test = Vehicle(10, 5, 0); | |||||
if (test.bookSeat(3, 4, 10)) | |||||
{ | |||||
cout << "Booking success" << endl; | |||||
} | |||||
test.printMap(10); | |||||
} |