From 70fcbc274bb75708e16d8cdd77a6dddf42eb6357 Mon Sep 17 00:00:00 2001 From: MassiveAtoms Date: Sat, 6 Jul 2019 11:52:01 -0300 Subject: [PATCH 1/3] Fixing some stuff --- CMakeLists.txt | 2 ++ Customer.cpp | 10 +++++----- Interface.cpp | 40 ++++++++++++++++++++++++++++++++++++++++ Query.cpp | 12 ++++++------ data.cpp | 2 +- headers/Customer.h | 10 +++++----- headers/Interface.h | 9 +++++++++ headers/Park_spot.h | 1 + main.cpp | 18 ++++++++---------- old_test.db3 | Bin 16384 -> 0 bytes test.db3 | Bin 16384 -> 16384 bytes 11 files changed, 77 insertions(+), 27 deletions(-) create mode 100644 Interface.cpp create mode 100644 headers/Interface.h delete mode 100644 old_test.db3 diff --git a/CMakeLists.txt b/CMakeLists.txt index f965e73..97671bf 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -25,6 +25,8 @@ add_executable(park headers/Park_time.h Query.cpp headers/Query.h + Interface.cpp + headers/Interface.h ) diff --git a/Customer.cpp b/Customer.cpp index ea435a0..f74c23f 100644 --- a/Customer.cpp +++ b/Customer.cpp @@ -1,18 +1,18 @@ #include "headers/Customer.h" // constructors -Customer::Customer(string name_, string password_, Verhicle_type verhicle_) - : name{name_}, verhicle{verhicle_}, password{hash_password(password_)} { +Customer::Customer(string name_, string password_, Vehicle_type vehicle_) + : name{name_}, vehicle{vehicle_}, password{hash_password(password_)} { id = auto_increment_db() + 1; save_db(); } Customer::Customer(int id_, string name_, string password_, - Verhicle_type verhicle_, vector instances) + Vehicle_type vehicle_, vector instances) :id{id_}, name{name_}, password{password_}, - verhicle{verhicle_}, + vehicle{vehicle_}, park_instances{instances} {} @@ -49,7 +49,7 @@ void Customer::gen_monthly() { void Customer::save_db() { string statement{"insert into Customer values (, '', '', );"}; // after ( = 28) - statement.insert(38, to_string(int(verhicle))); + statement.insert(38, to_string(int(vehicle))); statement.insert(36, password); statement.insert(32, name); statement.insert(29, to_string(id)); diff --git a/Interface.cpp b/Interface.cpp new file mode 100644 index 0000000..7829c04 --- /dev/null +++ b/Interface.cpp @@ -0,0 +1,40 @@ +#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"; + + // 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() { + int selector; + cout << "\nHello and welcome to the parking spot! Please select a suitable " + "option:"; + cout << "\n[1]Log in as member"; + cout << "\n[2]Log in as administrator"; + cin >> selector; + switch (selector) { + case 1: + interface_member(); + case 2: + interface_admin(); + } +} diff --git a/Query.cpp b/Query.cpp index 9e84a65..dbe898b 100644 --- a/Query.cpp +++ b/Query.cpp @@ -38,16 +38,16 @@ vector query_customer_with_name(string name) { vector result; SQLite::Statement query( data::db, - "SELECT id, name, password, verhicle FROM Customer WHERE name = ?;"); + "SELECT id, name, password, vehicle FROM Customer WHERE name = ?;"); query.bind(1, name); while (query.executeStep()) { int id = query.getColumn(0); string name_ = query.getColumn(1); string password = query.getColumn(2); - int verhicle = query.getColumn(3); // cast to verhicle + int vehicle = query.getColumn(3); // cast to vehicle vector park_instances = query_parktimes_for_customer(id); result.push_back(Customer{ - id, name_, password, Verhicle_type(verhicle), park_instances}); + id, name_, password, Vehicle_type(vehicle), park_instances}); } return result; } @@ -65,12 +65,12 @@ Customer query_customer_with_id(int id) { while (query.executeStep()) { string name = query.getColumn(1); string password = query.getColumn(2); - int verhicle = query.getColumn(3); // cast to verhicle + int vehicle = query.getColumn(3); // cast to vehicle vector park_instances = query_parktimes_for_customer(id); Customer result{ - id, name, password, Verhicle_type(verhicle), park_instances}; + id, name, password, Vehicle_type(vehicle), park_instances}; // DEBUG - // cout << "{" << result.id << "," < instances); void clock_in(int s_id); void clock_out(int s_id); @@ -48,7 +48,7 @@ class Customer { void delete_db(); void gen_monthly(); - Verhicle_type verhicle; + Vehicle_type vehicle; private: vector park_instances; diff --git a/headers/Interface.h b/headers/Interface.h new file mode 100644 index 0000000..104ba70 --- /dev/null +++ b/headers/Interface.h @@ -0,0 +1,9 @@ + + +#include "Query.h" + +using std::cin; + +void interface(); +void interface_member(); +void interface_admin(); \ No newline at end of file diff --git a/headers/Park_spot.h b/headers/Park_spot.h index 61a994c..e50dfdc 100644 --- a/headers/Park_spot.h +++ b/headers/Park_spot.h @@ -18,6 +18,7 @@ class Park_spot { int id; bool taken; int parked_customer; + Park_spot(); Park_spot(int id_, bool taken_, int parked); void clock(Customer& c_customer); diff --git a/main.cpp b/main.cpp index 65a5058..7d88f59 100644 --- a/main.cpp +++ b/main.cpp @@ -1,4 +1,4 @@ -#include "headers/Query.h" +#include "headers/Interface.h" #include @@ -70,17 +70,15 @@ For now, it's just here in case you want an easy way to store customers. */ int main() { - Customer sagar = query_customer_with_name("stefan udit")[0]; - Customer sagar1 = query_customer_with_id(2); - cout << sagar.id << "," << sagar.name << "," << sagar.password << "\n"; - cout << sagar1.id << "," << sagar1.name << "," << sagar1.password; - cout << parking_spots.size(); + // er is een customer met id 1(testcustomer) met password "password" + + // Customer test { + // "testcustomer", "password", Vehicle_type::bike + // }; + + interface(); - for (auto i : parking_spots) { - cout << "\n" << i.id << "," << i.parked_customer; - } - populate_spots(); } /* diff --git a/old_test.db3 b/old_test.db3 deleted file mode 100644 index 108a7ad5250f75413fabe333ec9836c9061be779..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 16384 zcmeI3d5jz9dB%5V4{}J(aA&laRuV-?t8-S;u2#FUWUnRO_kEK)B!}eizVDlrgP<{D zH%XHyZra2!T&D>F2Xz6vb?T%sYS&0FpegLscHLG@Q&bM()QRKNKw|WxJuHWC3H{xM z1Rn5xe((D&=X+*Aau&Nbi#}1N#nD_bLzTtbQwvkm(^EIZ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14>d0BJ^Ez@(T+}0}{jB3ISHQ~3idP<-19PV8F# zM9(n-c8oD{mKDJtSOV{`4(pR~@I1^u#@;AEX%o3VUaLE5KM=&3Q_|<>#p70v={3!+ zGR*LXj4g=*=w;( zb5q5tP0EE=vypk08x^g7X*kbl`n-fEFKND@cWQd4-}eMdopV*EAoIuhWkbo&mLq(q zi4{DJ{KsocmCljs7f^9fmsLi}j#;ORhnb`1*yI^zCTUt;EDP11U+z;KES)*3aS#U2 z))!ry>T~0>-VPB1_n#&w$kwLF^XAx9QviT1cmv>H_&fajPxu3VgJ0pz=biKy_<~H3 zU<;7(4PzUU8%8&btQjLnkR-xE*lewJ5qJyWA9x!ozQYH1hy);#BmmLVM<1gJkO;TJ F`UhMdw)X%4 -- 2.45.2 From d3ac836657afe8561974fb011e4cecc656414b1a Mon Sep 17 00:00:00 2001 From: MassiveAtoms Date: Sat, 6 Jul 2019 12:14:18 -0300 Subject: [PATCH 2/3] ammend parkspot to include vehicletype --- Park_spot.cpp | 10 ++++++---- data.cpp | 2 +- headers/Park_spot.h | 5 +++-- main.cpp | 11 ++++------- test.db3 | Bin 16384 -> 16384 bytes 5 files changed, 14 insertions(+), 14 deletions(-) diff --git a/Park_spot.cpp b/Park_spot.cpp index e64e8e1..7efc6cf 100644 --- a/Park_spot.cpp +++ b/Park_spot.cpp @@ -2,14 +2,15 @@ // constructors -Park_spot::Park_spot() - : parked_customer{0}, id{auto_increment_db() + 1}, taken{false} { +Park_spot::Park_spot(Vehicle_type v_type_) + : parked_customer{0}, id{auto_increment_db() + 1}, taken{false}, v_type{v_type_} { save_db(); } -Park_spot::Park_spot(int id_, bool taken_, int parked) +Park_spot::Park_spot(int id_, bool taken_, int parked,Vehicle_type v_type_) : parked_customer{parked}, id{id_}, + v_type{v_type_}, taken{taken_} // TODO: think about how init parked? {} @@ -48,8 +49,9 @@ void Park_spot::update_db() { void Park_spot::save_db() { //(int id, bool taken, int customer_id) - string statement{"insert into Park_spot values ( , , );"}; + string statement{"insert into Park_spot values ( , , , );"}; // after ( = 28) + statement.insert(36, to_string(int(v_type))); statement.insert(34, "NULL"); statement.insert(32, "0"); statement.insert(30, to_string(id)); diff --git a/data.cpp b/data.cpp index be27c0d..5c000b9 100644 --- a/data.cpp +++ b/data.cpp @@ -24,7 +24,7 @@ SQLite::Database start_db() { // getting errors when using bool, so i used an int instead. db.exec( "create table if not exists Park_spot (id integer primary key, taken " - "int, customer_id int)"); + "int, customer_id int, vehicle_type int)"); db.exec( "create table if not exists Park_time (id integer primary key, " "customer_id int, spot_id int, start int, end int, duration int)"); diff --git a/headers/Park_spot.h b/headers/Park_spot.h index e50dfdc..068fc55 100644 --- a/headers/Park_spot.h +++ b/headers/Park_spot.h @@ -18,9 +18,10 @@ class Park_spot { int id; bool taken; int parked_customer; + Vehicle_type v_type; - Park_spot(); - Park_spot(int id_, bool taken_, int parked); + Park_spot(Vehicle_type v_type_); + Park_spot(int id_, bool taken_, int parked, Vehicle_type v_type_); void clock(Customer& c_customer); private: diff --git a/main.cpp b/main.cpp index 7d88f59..dd7794f 100644 --- a/main.cpp +++ b/main.cpp @@ -70,12 +70,10 @@ 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" - // Customer test { - // "testcustomer", "password", Vehicle_type::bike - // }; - interface(); @@ -89,13 +87,12 @@ concurrency issue. Do not move this. vector populate_spots() { vector spots; SQLite::Statement query(data::db, "SELECT * FROM Park_spot WHERE id > 0;"); - // query.bind(1, 2); while (query.executeStep()) { int id = query.getColumn(0); int taken = query.getColumn(1); int cid = query.getColumn(2); - // park_customers.push_back(query_customer_with_id(cid)); - spots.push_back({id, taken, cid}); + Vehicle_type vtype = Vehicle_type(int(query.getColumn(3))); + spots.push_back({id, taken, cid, vtype}); } return spots; } \ No newline at end of file diff --git a/test.db3 b/test.db3 index 6e83b13452cc5fa52980122413fb0f25f2951302..fc57d5fe69782b8fce6ed43c9e47b7490999f602 100644 GIT binary patch delta 272 zcmZo@U~Fh$oFL7}H&Mn}n2$lvM1hxqfq|K?mVv*ApO3G0V*LG6v|RFGLv&s<4Y$rOHN9LCS$Swq zqGP0GT6$_E$T3{}TN(I&@_*!i#s7%^HveV*GyF&R_wsMuET}M(-aM8#bsp~8!abKxR$gF0NoqlazH3f?VL@p?Vwjs@ zpo(LKd!=KTVOU~*lv6;2rK?*?rglYywt-QUOHM{shO47bxp%&!Z<=Xl;35M7AOZj~ CyD9qs -- 2.45.2 From 3e594b946dbdbabaf7c6535d76272bd213b444ec Mon Sep 17 00:00:00 2001 From: MassiveAtoms Date: Sat, 6 Jul 2019 13:32:00 -0300 Subject: [PATCH 3/3] 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}#!} -- 2.45.2