From 3e594b946dbdbabaf7c6535d76272bd213b444ec Mon Sep 17 00:00:00 2001 From: MassiveAtoms Date: Sat, 6 Jul 2019 13:32:00 -0300 Subject: [PATCH] added a park interface --- Customer.cpp | 25 ++++++++--- Interface.cpp | 103 +++++++++++++++++++++++++++++++++----------- Park_time.cpp | 14 ++++++ Query.cpp | 10 +++++ headers/Customer.h | 2 + headers/Interface.h | 9 ++-- headers/Park_time.h | 5 +++ headers/Query.h | 3 ++ main.cpp | 27 +----------- test.db3 | Bin 16384 -> 16384 bytes 10 files changed, 139 insertions(+), 59 deletions(-) diff --git a/Customer.cpp b/Customer.cpp index f74c23f..3d7a8a3 100644 --- a/Customer.cpp +++ b/Customer.cpp @@ -9,13 +9,12 @@ Customer::Customer(string name_, string password_, Vehicle_type vehicle_) Customer::Customer(int id_, string name_, string password_, Vehicle_type vehicle_, vector instances) - :id{id_}, - name{name_}, + : id{id_}, + name{name_}, password{password_}, vehicle{vehicle_}, park_instances{instances} {} - // 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); } +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 void Customer::gen_monthly() { cout << "NAME: " << name << "\n"; @@ -83,5 +100,3 @@ int Customer::auto_increment_db() { max_id.reset(); return id; } - - diff --git a/Interface.cpp b/Interface.cpp index 7829c04..f0950b1 100644 --- a/Interface.cpp +++ b/Interface.cpp @@ -1,30 +1,9 @@ #include "headers/Interface.h" -void interface_member() { - 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"; +// I added it to pass spots, because the parking options need it to check where +// is free parking_spots is declared in main, and if i declare it - // if (verify_password(c.password, password)) { - // cout << "\nLogged in successfully."; - // } else { - // cout - // << "Error, id and password combination not found, please try again."; - // } -} - -void interface_admin() {} - -void interface() { +void interface(vector& spots) { int selector; cout << "\nHello and welcome to the parking spot! Please select a suitable " "option:"; @@ -33,8 +12,80 @@ void interface() { cin >> selector; switch (selector) { case 1: - interface_member(); + interface_member(spots); case 2: - interface_admin(); + interface_admin(spots); } } + +void interface_member(vector& 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& spots) {} + +// --------- individual things. + +void park(Customer& c, vector& 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"; + } + } +} \ No newline at end of file diff --git a/Park_time.cpp b/Park_time.cpp index cd06a55..e6556ec 100644 --- a/Park_time.cpp +++ b/Park_time.cpp @@ -112,4 +112,18 @@ int Park_time::auto_increment_db() { id = max_id.getColumn(0); max_id.reset(); 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}); } \ No newline at end of file diff --git a/Query.cpp b/Query.cpp index dbe898b..29fb841 100644 --- a/Query.cpp +++ b/Query.cpp @@ -75,6 +75,16 @@ Customer query_customer_with_id(int id) { } } +//------------------------------- + +Park_spot query_parkspot_with_id(int id, vector& parkspots){ + for (Park_spot& i : parkspots){ + if (i.id == id){ + return i; + } + } +} + // -------------- paroking spots diff --git a/headers/Customer.h b/headers/Customer.h index 03ad182..ce02737 100644 --- a/headers/Customer.h +++ b/headers/Customer.h @@ -43,6 +43,8 @@ class Customer { vector instances); void clock_in(int s_id); void clock_out(int s_id); + bool parked(); + int parked_at(); void update_db(); void delete_db(); diff --git a/headers/Interface.h b/headers/Interface.h index 104ba70..bb59a17 100644 --- a/headers/Interface.h +++ b/headers/Interface.h @@ -4,6 +4,9 @@ using std::cin; -void interface(); -void interface_member(); -void interface_admin(); \ No newline at end of file + + +void interface(vector& spots); +void interface_member(vector& spots); +void interface_admin(vector& spots); +void park(Customer& c, vector& spots); \ No newline at end of file diff --git a/headers/Park_time.h b/headers/Park_time.h index 0b5551b..550ad5c 100644 --- a/headers/Park_time.h +++ b/headers/Park_time.h @@ -5,6 +5,7 @@ #include "data.h" #include +#include #include #include #include @@ -63,4 +64,8 @@ class Park_time { int start_to_int(); // helper }; + +//test funciton +void Wait(int sec); + #endif // Park_time \ No newline at end of file diff --git a/headers/Query.h b/headers/Query.h index 6fb8a04..0e93231 100644 --- a/headers/Query.h +++ b/headers/Query.h @@ -57,4 +57,7 @@ Customer query_customer_with_id(int id); vector populate_spots(); +Park_spot query_parkspot_with_id(int id, vector& parkspots); + + #endif // CUSTOMER_H \ No newline at end of file diff --git a/main.cpp b/main.cpp index dd7794f..6f95bac 100644 --- a/main.cpp +++ b/main.cpp @@ -1,9 +1,7 @@ #include "headers/Interface.h" -#include -using namespace std::chrono; /* 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) */ -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 parking_spots = populate_spots(); // this queries the db for all the saved parking_spots and initializes them - static vector 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() { // state of db: // er zijn 10 parkspots, 5 met biketype en 5 met pickup type // er is een customer met id 1(testcustomer) met password "password" - - interface(); + + interface(parking_spots); } diff --git a/test.db3 b/test.db3 index fc57d5fe69782b8fce6ed43c9e47b7490999f602..fe4446128ac0fc9bf961cf37242dc13aea361c4b 100644 GIT binary patch delta 164 zcmZo@U~Fh$oFL68HBrWyQEFqtLU~^PR}5VI^BMT(^MB-DwV6+0BEJ|XBP#=kD5qbj zj}Ip^oH==`zNrfTPX=~QPEIx^pfCd?3j+g~%L}BL`A;zLzvaKhe`2$s!7hFa0cLgv qPEHmU##n_j?m!$ZBFF?3VFZdW$10qD0~As=7i2^dnhO+O$^igtP9mNF delta 82 zcmZo@U~Fh$oFL7}H&Mo!k#A$dLU~>W1_mzvtqlA>`9Jc%+RUdgk$>U@vB_KYO=Vb_ eSs6GOIN6v$6e9~OBbW=)z#y<$&|o`Ip)&wK9}#!}