added a park interface
This commit is contained in:
parent
d3ac836657
commit
3e594b946d
25
Customer.cpp
25
Customer.cpp
@ -9,13 +9,12 @@ Customer::Customer(string name_, string password_, Vehicle_type vehicle_)
|
|||||||
|
|
||||||
Customer::Customer(int id_, string name_, string password_,
|
Customer::Customer(int id_, string name_, string password_,
|
||||||
Vehicle_type vehicle_, vector<Park_time> instances)
|
Vehicle_type vehicle_, vector<Park_time> instances)
|
||||||
:id{id_},
|
: id{id_},
|
||||||
name{name_},
|
name{name_},
|
||||||
password{password_},
|
password{password_},
|
||||||
vehicle{vehicle_},
|
vehicle{vehicle_},
|
||||||
park_instances{instances} {}
|
park_instances{instances} {}
|
||||||
|
|
||||||
|
|
||||||
// clock in/out methods
|
// clock in/out methods
|
||||||
// ====================================================================================
|
// ====================================================================================
|
||||||
/*
|
/*
|
||||||
@ -31,6 +30,24 @@ void Customer::clock_out(int s_id) {
|
|||||||
park_instances[park_instances.size() - 1].clock_out(id, s_id);
|
park_instances[park_instances.size() - 1].clock_out(id, s_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool Customer::parked() {
|
||||||
|
if (!park_instances.size()){
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if ((park_instances[park_instances.size() - 1].duration)) {
|
||||||
|
// if duration of the last parktime == 0, meaning
|
||||||
|
// that the customer has not clocked out
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int Customer::parked_at(){
|
||||||
|
return park_instances[park_instances.size() - 1].spot_id;
|
||||||
|
}
|
||||||
|
|
||||||
// report gen
|
// report gen
|
||||||
void Customer::gen_monthly() {
|
void Customer::gen_monthly() {
|
||||||
cout << "NAME: " << name << "\n";
|
cout << "NAME: " << name << "\n";
|
||||||
@ -83,5 +100,3 @@ int Customer::auto_increment_db() {
|
|||||||
max_id.reset();
|
max_id.reset();
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
103
Interface.cpp
103
Interface.cpp
@ -1,30 +1,9 @@
|
|||||||
#include "headers/Interface.h"
|
#include "headers/Interface.h"
|
||||||
|
|
||||||
void interface_member() {
|
// I added it to pass spots, because the parking options need it to check where
|
||||||
int id;
|
// is free parking_spots is declared in main, and if i declare it
|
||||||
string password;
|
|
||||||
cout << "\nPlease input id:";
|
|
||||||
cin >> id;
|
|
||||||
Customer c = query_customer_with_id(id);
|
|
||||||
cout << "\nPlease input password:";
|
|
||||||
cin >> password;
|
|
||||||
while (!(verify_password(c.password, password))){
|
|
||||||
cout << "ERROR: wrong password. Please retype your password \n";
|
|
||||||
cin >> password;
|
|
||||||
}
|
|
||||||
cout << "Logged in succesfully\n";
|
|
||||||
|
|
||||||
// if (verify_password(c.password, password)) {
|
void interface(vector<Park_spot>& spots) {
|
||||||
// cout << "\nLogged in successfully.";
|
|
||||||
// } else {
|
|
||||||
// cout
|
|
||||||
// << "Error, id and password combination not found, please try again.";
|
|
||||||
// }
|
|
||||||
}
|
|
||||||
|
|
||||||
void interface_admin() {}
|
|
||||||
|
|
||||||
void interface() {
|
|
||||||
int selector;
|
int selector;
|
||||||
cout << "\nHello and welcome to the parking spot! Please select a suitable "
|
cout << "\nHello and welcome to the parking spot! Please select a suitable "
|
||||||
"option:";
|
"option:";
|
||||||
@ -33,8 +12,80 @@ void interface() {
|
|||||||
cin >> selector;
|
cin >> selector;
|
||||||
switch (selector) {
|
switch (selector) {
|
||||||
case 1:
|
case 1:
|
||||||
interface_member();
|
interface_member(spots);
|
||||||
case 2:
|
case 2:
|
||||||
interface_admin();
|
interface_admin(spots);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void interface_member(vector<Park_spot>& spots) {
|
||||||
|
int id;
|
||||||
|
string password;
|
||||||
|
cout << "\nPlease input id:";
|
||||||
|
cin >> id;
|
||||||
|
Customer c = query_customer_with_id(id);
|
||||||
|
cout << "\nPlease input password:";
|
||||||
|
cin >> password;
|
||||||
|
|
||||||
|
while (!(verify_password(c.password, password))) {
|
||||||
|
cout << "ERROR: wrong password. Please retype your password \n";
|
||||||
|
cin >> password;
|
||||||
|
}
|
||||||
|
|
||||||
|
cout << "Logged in succesfully\n";
|
||||||
|
cout << "select an option\n [1] Parking options\n[2]other";
|
||||||
|
int option;
|
||||||
|
cin >> option;
|
||||||
|
switch (option) {
|
||||||
|
case 1: {
|
||||||
|
park(c, spots);
|
||||||
|
}
|
||||||
|
case 2: {
|
||||||
|
// other thing you want to add
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void interface_admin(vector<Park_spot>& spots) {}
|
||||||
|
|
||||||
|
// --------- individual things.
|
||||||
|
|
||||||
|
void park(Customer& c, vector<Park_spot>& spots) {
|
||||||
|
cout << "You have selected parking option";
|
||||||
|
if (!(c.parked())) {
|
||||||
|
cout << "The following spots[which can fit your vehicle] are "
|
||||||
|
"available: ";
|
||||||
|
for (Park_spot i : spots) {
|
||||||
|
if (i.v_type == c.vehicle) {
|
||||||
|
cout << i.id << ", ";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
cout << "where do you want to park?";
|
||||||
|
int parkid;
|
||||||
|
cin >> parkid;
|
||||||
|
for (Park_spot& i : spots) {
|
||||||
|
if (i.id == parkid) {
|
||||||
|
i.clock(c);
|
||||||
|
cout << "You have parked sucessfully";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
} else {
|
||||||
|
cout
|
||||||
|
<< "You are parked at spot " << c.parked_at()
|
||||||
|
<< ", do you want to clock out?\n enter [1] for yes and [0] for no";
|
||||||
|
int answer = 0;
|
||||||
|
cin >> answer;
|
||||||
|
if (answer) {
|
||||||
|
query_parkspot_with_id(c.parked_at(), spots).clock(c);
|
||||||
|
cout << "You have sucessfully clocked out.";
|
||||||
|
} else {
|
||||||
|
cout << "OK, have a nice day";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -112,4 +112,18 @@ int Park_time::auto_increment_db() {
|
|||||||
id = max_id.getColumn(0);
|
id = max_id.getColumn(0);
|
||||||
max_id.reset();
|
max_id.reset();
|
||||||
return id;
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//------------------ test function to help test this
|
||||||
|
|
||||||
|
void Wait(int sec)
|
||||||
|
|
||||||
|
{
|
||||||
|
/*
|
||||||
|
a wait function where 1 sec represents 1 hour irl. It has been used for testing
|
||||||
|
purposes mostly. TODO: Needs to be removed at completion of project, or seperated in a test
|
||||||
|
cpp/header
|
||||||
|
*/
|
||||||
|
std::this_thread::sleep_for(seconds{sec});
|
||||||
}
|
}
|
10
Query.cpp
10
Query.cpp
@ -75,6 +75,16 @@ Customer query_customer_with_id(int id) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//-------------------------------
|
||||||
|
|
||||||
|
Park_spot query_parkspot_with_id(int id, vector<Park_spot>& parkspots){
|
||||||
|
for (Park_spot& i : parkspots){
|
||||||
|
if (i.id == id){
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// -------------- paroking spots
|
// -------------- paroking spots
|
||||||
|
|
||||||
|
@ -43,6 +43,8 @@ class Customer {
|
|||||||
vector<Park_time> instances);
|
vector<Park_time> instances);
|
||||||
void clock_in(int s_id);
|
void clock_in(int s_id);
|
||||||
void clock_out(int s_id);
|
void clock_out(int s_id);
|
||||||
|
bool parked();
|
||||||
|
int parked_at();
|
||||||
|
|
||||||
void update_db();
|
void update_db();
|
||||||
void delete_db();
|
void delete_db();
|
||||||
|
@ -4,6 +4,9 @@
|
|||||||
|
|
||||||
using std::cin;
|
using std::cin;
|
||||||
|
|
||||||
void interface();
|
|
||||||
void interface_member();
|
|
||||||
void interface_admin();
|
void interface(vector<Park_spot>& spots);
|
||||||
|
void interface_member(vector<Park_spot>& spots);
|
||||||
|
void interface_admin(vector<Park_spot>& spots);
|
||||||
|
void park(Customer& c, vector<Park_spot>& spots);
|
@ -5,6 +5,7 @@
|
|||||||
#include "data.h"
|
#include "data.h"
|
||||||
|
|
||||||
#include <chrono>
|
#include <chrono>
|
||||||
|
#include <thread>
|
||||||
#include <ctime>
|
#include <ctime>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <string>
|
#include <string>
|
||||||
@ -63,4 +64,8 @@ class Park_time {
|
|||||||
int start_to_int(); // helper
|
int start_to_int(); // helper
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
//test funciton
|
||||||
|
void Wait(int sec);
|
||||||
|
|
||||||
#endif // Park_time
|
#endif // Park_time
|
@ -57,4 +57,7 @@ Customer query_customer_with_id(int id);
|
|||||||
|
|
||||||
vector<Park_spot> populate_spots();
|
vector<Park_spot> populate_spots();
|
||||||
|
|
||||||
|
Park_spot query_parkspot_with_id(int id, vector<Park_spot>& parkspots);
|
||||||
|
|
||||||
|
|
||||||
#endif // CUSTOMER_H
|
#endif // CUSTOMER_H
|
27
main.cpp
27
main.cpp
@ -1,9 +1,7 @@
|
|||||||
#include "headers/Interface.h"
|
#include "headers/Interface.h"
|
||||||
|
|
||||||
#include <thread>
|
|
||||||
|
|
||||||
|
|
||||||
using namespace std::chrono;
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Code structure is like this:
|
Code structure is like this:
|
||||||
@ -44,37 +42,16 @@ headers. Explanations of how the member functions work(Or how I intended for
|
|||||||
them to work) are in the respective .cpp files. void Wait(int sec)
|
them to work) are in the respective .cpp files. void Wait(int sec)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
void Wait(int sec)
|
|
||||||
|
|
||||||
{
|
|
||||||
/*
|
|
||||||
a wait function where 1 sec represents 1 hour irl. It has been used for testing
|
|
||||||
purposes mostly.
|
|
||||||
TODO: Needs to be removed at completion of project, or seperated in a test
|
|
||||||
cpp/header
|
|
||||||
*/
|
|
||||||
std::this_thread::sleep_for(seconds{sec});
|
|
||||||
}
|
|
||||||
|
|
||||||
static vector<Park_spot> parking_spots = populate_spots();
|
static vector<Park_spot> parking_spots = populate_spots();
|
||||||
// this queries the db for all the saved parking_spots and initializes them
|
// this queries the db for all the saved parking_spots and initializes them
|
||||||
|
|
||||||
static vector<Customer> park_customers;
|
static vector<Customer> park_customers;
|
||||||
/*
|
|
||||||
This was meant for an older implementation. park_time objects used to store
|
|
||||||
pointers to customers and in order to not get dangling pointers(dangerous!) I
|
|
||||||
had to have a way to store the customers the pointer pointed to so they didn't
|
|
||||||
get destroyed prematurely(I could've used the lower-level, more dangerous new,
|
|
||||||
or worse, malloc, but that's ugly).
|
|
||||||
For now, it's just here in case you want an easy way to store customers.
|
|
||||||
*/
|
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
// state of db:
|
// state of db:
|
||||||
// er zijn 10 parkspots, 5 met biketype en 5 met pickup type
|
// er zijn 10 parkspots, 5 met biketype en 5 met pickup type
|
||||||
// er is een customer met id 1(testcustomer) met password "password"
|
// er is een customer met id 1(testcustomer) met password "password"
|
||||||
|
|
||||||
interface();
|
interface(parking_spots);
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user