Browse Source

Added Vehicle class

- Fixed minor error in LogInSystem
- Added VehicleManager.cpp
- Added main.cpp where main() will be migrated to
Fixing-travis-yml
BinHong Lee 7 years ago
parent
commit
2d6ebffc72
7 changed files with 123 additions and 5 deletions
  1. +43
    -5
      LogInSystem.cpp
  2. +16
    -0
      Vehicle.cpp
  3. +1
    -0
      Vehicle.hpp
  4. +28
    -0
      VehicleManager.cpp
  5. +18
    -0
      VehicleManager.hpp
  6. +17
    -0
      main.cpp
  7. +0
    -0
      vehiclesData.txt

+ 43
- 5
LogInSystem.cpp View File

@@ -6,9 +6,11 @@

#include <iostream>
#include <fstream>
#include <json/json.h>
#include <string>
#include <vector>
#include "Person.cpp"
#include "Vehicle.cpp"
using namespace std;

//Declaration of functions
@@ -24,9 +26,10 @@ string chgPassword(Person);
string chgEmail();
string chgPhoneNo();

vector<Vehicle> vehicles;
vector<Person> users;
static int wrongPass = 0;
static int globalId;
static int globalUserId;

int main()
{
@@ -46,8 +49,43 @@ int main()
}

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;

while (userOption != 0)
@@ -114,7 +152,7 @@ Person getUser(int toSearchId)

bool login()
{
Person currentUser;
Person currentUser(-1);
string username;
string password;
//If the user already has 3 fail attempt to login
@@ -213,10 +251,10 @@ Person registration()
cin >> phoneNo;

//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);

globalId++;
globalUserId++;

//Print success message
cout << "Account is successfully registered." << endl;


+ 16
- 0
Vehicle.cpp View File

@@ -4,6 +4,10 @@ using namespace std;

Vehicle::Vehicle(int length, int width, int id)
{
type = "TBA";
origin = "TBA";
destination = "TBA";
dateNtime = "TBA";
this->length = length;
this->width = width;
this->id = id;
@@ -22,6 +26,18 @@ Vehicle::Vehicle(string type, int length, int width, string origin, string desti
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)
{
this->type = type;


+ 1
- 0
Vehicle.hpp View File

@@ -18,6 +18,7 @@ private:
public:
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, vector< vector<int> > seatMap);
void setType(string type);
void setLength(int length);
void setWidth(int width);


+ 28
- 0
VehicleManager.cpp View File

@@ -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)
{

}
}

+ 18
- 0
VehicleManager.hpp View File

@@ -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);
}

+ 17
- 0
main.cpp View File

@@ -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);
}

+ 0
- 0
vehiclesData.txt View File


Loading…
Cancel
Save