From 951f8f6c154aa11f34cea4e2b8c026f49dd8f413 Mon Sep 17 00:00:00 2001 From: TinyAtoms Date: Tue, 28 May 2019 13:46:55 -0300 Subject: [PATCH 1/7] quick sketch of components --- src/Customer.cpp | 30 ++++++++++++++++++++++ src/Park_spot.cpp | 20 +++++++++++++++ src/Park_time.cpp | 45 +++++++++++++++++++++++++++++++++ src/headers/Customer.h | 37 +++++++++++++++++++++++++++ src/headers/Park_spot.h | 21 ++++++++++++++++ src/headers/Park_time.h | 39 +++++++++++++++++++++++++++++ src/main.cpp | 55 +++++++++++++++++++++++++++++++++++++++++ 7 files changed, 247 insertions(+) create mode 100644 src/Customer.cpp create mode 100644 src/Park_spot.cpp create mode 100644 src/Park_time.cpp create mode 100644 src/headers/Customer.h create mode 100644 src/headers/Park_spot.h create mode 100644 src/headers/Park_time.h create mode 100644 src/main.cpp diff --git a/src/Customer.cpp b/src/Customer.cpp new file mode 100644 index 0000000..9b5f2a8 --- /dev/null +++ b/src/Customer.cpp @@ -0,0 +1,30 @@ +#include "headers/Customer.h" +#include + +Customer::Customer(int id_, string name_, string card_code_) + : id { id_ } + , name { name_ } + , card_code { card_code_ } +{ +} + +void Customer::clock_in( int s_id) +{ + Park_time pt{id, s_id}; + park_instances.push_back(pt); +} +void Customer::clock_out(int s_id){ + park_instances[park_instances.size()-1].clock_out(id, s_id); +} + + + +void Customer::gen_monthly(){ + std::cout << "NAME: " << name << " card code: " << card_code << "\n"; + std::cout << "-------------------------------------------------\n"; + for (auto& i : park_instances) { + // need some logic to only include from this month + std::cout << i; + } + std::cout << "-------------------------------------------------\n\n"; +} \ No newline at end of file diff --git a/src/Park_spot.cpp b/src/Park_spot.cpp new file mode 100644 index 0000000..95d1928 --- /dev/null +++ b/src/Park_spot.cpp @@ -0,0 +1,20 @@ +#include "headers/Park_spot.h" + +Park_spot::Park_spot(int id_){ + parked = nullptr; + id = id_; + taken = false; +} + +void Park_spot::clock(Customer* c_customer){ + if (!taken){ + parked = c_customer; + taken = true; + parked->clock_in(id); + } + else{ + taken = false; + parked->clock_out(id); + parked = nullptr; + } +} \ No newline at end of file diff --git a/src/Park_time.cpp b/src/Park_time.cpp new file mode 100644 index 0000000..267e0c0 --- /dev/null +++ b/src/Park_time.cpp @@ -0,0 +1,45 @@ +#include"headers/Park_time.h" +#include +#include + + +Park_time::Park_time(int c_id, int s_id) + : customer_id { c_id } + , spot_id { s_id } + , duration { 0 } + , start { high_resolution_clock::now() } +{ +} + +void Park_time::clock_out(int c_id, int s_id) +{ + + if (c_id != customer_id) { + std::cout << "wrong customer id, you are at the wrong location"; + return; + } + if (s_id != spot_id) { + std::cout << "Wrong spot id, you're at the wrong location"; + return; + } + + if (!duration) { + end = high_resolution_clock::now(); + duration = duration_cast(end - start).count(); // use mins later + + } else { + std::cout << "Already clocked out. Something is wrong \n"; + } +} + + +std::ostream& operator<<(std::ostream& os, const Park_time & pt){ + std::time_t start_ = system_clock::to_time_t(pt.start); + std::time_t end_ = system_clock::to_time_t(pt.end); + os << "- - - - - - - - - - - - - - - - - - - -\n"; + os << "Clocked in :" << std::ctime(&start_); + os << "clocked out : " << std::ctime(&end_); + os << "duration : " << pt.duration << "\n"; + os << "- - - - - - - - - - - - - - - - - - - -\n"; + return os; +} \ No newline at end of file diff --git a/src/headers/Customer.h b/src/headers/Customer.h new file mode 100644 index 0000000..58589e0 --- /dev/null +++ b/src/headers/Customer.h @@ -0,0 +1,37 @@ +#ifndef CUSTOMER_H +#define CUSTOMER_H +#pragma once + +#include +#include +#include "Park_time.h" + +using std::vector; +using std::string; + +/* +db repr of Customer +int id (not null, auto increment) +string name (not nulll) +string card_code (not null) + +*/ + +class Customer { +public: + int id; + string name; + string card_code; + void clock_in(int s_id); + void clock_out(int s_id); + // void gen_weekly(); + void gen_monthly(); + Customer(int id_, string name_, string card_code_); + +private: + vector park_instances; +}; + + + +#endif // CUSTOMER_H \ No newline at end of file diff --git a/src/headers/Park_spot.h b/src/headers/Park_spot.h new file mode 100644 index 0000000..e3984cf --- /dev/null +++ b/src/headers/Park_spot.h @@ -0,0 +1,21 @@ +#include "Customer.h" + + +/* +db representation: +int id not null +bool taken not null +int customer_id (null) (many to one, foreign key, whatever) +*/ + +class Park_spot { + public: + int id; + bool taken; + Customer* parked; + Park_spot(int id_); + void clock(Customer* c_customer); + private: +}; + + diff --git a/src/headers/Park_time.h b/src/headers/Park_time.h new file mode 100644 index 0000000..5778d31 --- /dev/null +++ b/src/headers/Park_time.h @@ -0,0 +1,39 @@ +#ifndef PARK_TIME_H +#define PARK_TIME_H +#pragma once + +#include +#include + + +using namespace std::chrono; + +/* +db repr of Park_time +int id (not null, auto increment) +int customer_id (not null) (many to one or something like that) +int spot_id (not null, many to one or something like that) +int duration +datetime start (not null) +datetime end +*/ + +class Park_time { +public: + int id; + int customer_id; + int spot_id; + int duration; + Park_time(int c_id, int s_id); + void clock_out(int c_id, int s_id); + friend std::ostream& operator<<(std::ostream& os, const Park_time & pt); + +private: + high_resolution_clock::time_point start; + high_resolution_clock::time_point end; +}; + + + + +#endif // Park_time \ No newline at end of file diff --git a/src/main.cpp b/src/main.cpp new file mode 100644 index 0000000..dc08007 --- /dev/null +++ b/src/main.cpp @@ -0,0 +1,55 @@ +#include "headers/Park_spot.h" +#include +#include // to make pausing work, not sure if i need chrono, or this, or both +#include + +void Wait(int sec) +{ + std::this_thread::sleep_for(seconds { sec }); +} + +using std::cout; + +int main() +{ + std::vector spots { + 1, 2, 3, 4, 5 + }; + std::vector customers { + { 1, "Sagar Ram", "eddgh" }, + { 2, "Shaq", "wsdfwefgv" }, + { 3, "Josh", "WDFGWEF" }, + { 4, "Stefano", "EDGGERG" } + }; + + spots[1].clock(&customers[3]); // stefano parks at spot 2 + Wait(2); + spots[3].clock(&customers[2]); // josh parks at spot 4 + Wait(1); + spots[1].clock(&customers[3]); // stefano clocks out of spot 1 + Wait(5); + spots[1].clock(&customers[1]); // shaq clocks in at spot 1 + Wait(6); + spots[2].clock(&customers[0]); // sagar clocks in at spot 3. what the fuck is he doing here? + Wait(2); + spots[2].clock(&customers[0]); // sagar clocks out from spot 2 + Wait(3); + spots[3].clock(&customers[2]); // josh clocks out from spot 4 + spots[1].clock(&customers[1]); // shaq clocks out at spot 1 + + spots[2].clock(&customers[1]); // shaq clocks out at spot 3 + Wait(4); + spots[2].clock(&customers[1]); // shaq clocks out at spot 2 + + /* + so: + stefan parked for 3 secs + josh parked for 17 secs + shaq parked 2 times, once for 4 and another for 11 secs + sagar parked for 2 secs + */ + customers[0].gen_monthly(); + customers[1].gen_monthly(); + customers[2].gen_monthly(); + customers[3].gen_monthly(); +} \ No newline at end of file From 72f72fa08d596b215d7df865d2298a0768434345 Mon Sep 17 00:00:00 2001 From: TinyAtoms Date: Tue, 28 May 2019 13:50:11 -0300 Subject: [PATCH 2/7] Add readme --- src/readme.md | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 src/readme.md diff --git a/src/readme.md b/src/readme.md new file mode 100644 index 0000000..b87cbbc --- /dev/null +++ b/src/readme.md @@ -0,0 +1,6 @@ + +use +``` +g++ ./src/main.cpp ./src/Park_time.cpp ./src/Customer.cpp ./src/Park_spot.cpp -o test.exe +``` +to build the project \ No newline at end of file From 9312ed335f59901dbee8b05ec441427091796a57 Mon Sep 17 00:00:00 2001 From: TinyAtoms Date: Tue, 28 May 2019 13:51:06 -0300 Subject: [PATCH 3/7] move readme --- src/readme.md => readme.md | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename src/readme.md => readme.md (100%) diff --git a/src/readme.md b/readme.md similarity index 100% rename from src/readme.md rename to readme.md From 843aa421593cd491570561fbc55a28a8345b2670 Mon Sep 17 00:00:00 2001 From: TinyAtoms Date: Tue, 28 May 2019 13:57:33 -0300 Subject: [PATCH 4/7] Add TODOs --- src/Customer.cpp | 2 +- src/headers/Customer.h | 2 +- src/headers/Park_spot.h | 6 ++---- src/headers/Park_time.h | 1 + 4 files changed, 5 insertions(+), 6 deletions(-) diff --git a/src/Customer.cpp b/src/Customer.cpp index 9b5f2a8..3f54a89 100644 --- a/src/Customer.cpp +++ b/src/Customer.cpp @@ -23,7 +23,7 @@ void Customer::gen_monthly(){ std::cout << "NAME: " << name << " card code: " << card_code << "\n"; std::cout << "-------------------------------------------------\n"; for (auto& i : park_instances) { - // need some logic to only include from this month + // TODO: need some logic to only include from this month std::cout << i; } std::cout << "-------------------------------------------------\n\n"; diff --git a/src/headers/Customer.h b/src/headers/Customer.h index 58589e0..9567bbe 100644 --- a/src/headers/Customer.h +++ b/src/headers/Customer.h @@ -24,7 +24,7 @@ public: string card_code; void clock_in(int s_id); void clock_out(int s_id); - // void gen_weekly(); + // void gen_weekly(); TODO: this void gen_monthly(); Customer(int id_, string name_, string card_code_); diff --git a/src/headers/Park_spot.h b/src/headers/Park_spot.h index e3984cf..83239ee 100644 --- a/src/headers/Park_spot.h +++ b/src/headers/Park_spot.h @@ -12,10 +12,8 @@ class Park_spot { public: int id; bool taken; - Customer* parked; + Customer* parked; //TODO: think about memory management Park_spot(int id_); void clock(Customer* c_customer); private: -}; - - +}; \ No newline at end of file diff --git a/src/headers/Park_time.h b/src/headers/Park_time.h index 5778d31..a35067f 100644 --- a/src/headers/Park_time.h +++ b/src/headers/Park_time.h @@ -31,6 +31,7 @@ public: private: high_resolution_clock::time_point start; high_resolution_clock::time_point end; + //TODO: discuss pros cons of using chrono, ctime, or 3th party lib }; From 2450e1009b8baa0fa6daed46d44f96bfb8f8bf1d Mon Sep 17 00:00:00 2001 From: TinyAtoms Date: Tue, 28 May 2019 18:02:52 -0300 Subject: [PATCH 5/7] Structure change --- src/Customer.cpp => Customer.cpp | 0 src/Park_spot.cpp => Park_spot.cpp | 0 src/Park_time.cpp => Park_time.cpp | 0 {src/headers => headers}/Customer.h | 0 {src/headers => headers}/Park_spot.h | 0 {src/headers => headers}/Park_time.h | 0 src/main.cpp => main.cpp | 0 7 files changed, 0 insertions(+), 0 deletions(-) rename src/Customer.cpp => Customer.cpp (100%) rename src/Park_spot.cpp => Park_spot.cpp (100%) rename src/Park_time.cpp => Park_time.cpp (100%) rename {src/headers => headers}/Customer.h (100%) rename {src/headers => headers}/Park_spot.h (100%) rename {src/headers => headers}/Park_time.h (100%) rename src/main.cpp => main.cpp (100%) diff --git a/src/Customer.cpp b/Customer.cpp similarity index 100% rename from src/Customer.cpp rename to Customer.cpp diff --git a/src/Park_spot.cpp b/Park_spot.cpp similarity index 100% rename from src/Park_spot.cpp rename to Park_spot.cpp diff --git a/src/Park_time.cpp b/Park_time.cpp similarity index 100% rename from src/Park_time.cpp rename to Park_time.cpp diff --git a/src/headers/Customer.h b/headers/Customer.h similarity index 100% rename from src/headers/Customer.h rename to headers/Customer.h diff --git a/src/headers/Park_spot.h b/headers/Park_spot.h similarity index 100% rename from src/headers/Park_spot.h rename to headers/Park_spot.h diff --git a/src/headers/Park_time.h b/headers/Park_time.h similarity index 100% rename from src/headers/Park_time.h rename to headers/Park_time.h diff --git a/src/main.cpp b/main.cpp similarity index 100% rename from src/main.cpp rename to main.cpp From 48b2d2042d691626feb714dee4782d5a0e4d7974 Mon Sep 17 00:00:00 2001 From: TinyAtoms Date: Tue, 28 May 2019 18:17:26 -0300 Subject: [PATCH 6/7] Change readme --- readme.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/readme.md b/readme.md index b87cbbc..a6772f4 100644 --- a/readme.md +++ b/readme.md @@ -1,6 +1,6 @@ use ``` -g++ ./src/main.cpp ./src/Park_time.cpp ./src/Customer.cpp ./src/Park_spot.cpp -o test.exe +g++ main.cpp Park_time.cpp Customer.cpp Park_spot.cpp -o test.exe ``` to build the project \ No newline at end of file From 57e4b9535e8b1a4f5cfa0d6075e9b2a079fafb42 Mon Sep 17 00:00:00 2001 From: Shaquille Soekhlal Date: Tue, 28 May 2019 18:28:20 -0300 Subject: [PATCH 7/7] Added gitignore and Devguide --- .gitignore | 150 ++++++++++++++++++++++++++++++++++++++ Development Guidelines.md | 30 ++++++++ 2 files changed, 180 insertions(+) create mode 100644 .gitignore create mode 100644 Development Guidelines.md diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..9b0b612 --- /dev/null +++ b/.gitignore @@ -0,0 +1,150 @@ +# An example global gitignore file +# +# Place a copy if this at ~/.gitignore_global +# Run `git config --global core.excludesfile ~/.gitignore_global` + +# Compiled source # +################### +*.com +*.class +*.dll +*.exe +*.o +*.so +*.pyc +*.pyo + +# Packages # +############ +# it's better to unpack these files and commit the raw source +# git has its own built in compression methods +*.7z +*.dmg +*.gz +*.iso +*.jar +*.rar +*.tar +*.zip +*.msi + +# Logs and databases # +###################### +*.log +*.sql +*.sqlite + +# OS generated files # +###################### +.DS_Store +.DS_Store? +._* +.Spotlight-V100 +.Trashes +ehthumbs.db +Thumbs.db +desktop.ini + +# Temporary files # +################### +*.bak +*.swp +*.swo +*~ +*# + +# IDE files # +########################################################################### +.vscode +.idea +.iml +*.sublime-workspace +.vscode/* +!.vscode/settings.json +!.vscode/tasks.json +!.vscode/launch.json +!.vscode/extensions.json +# User-specific stuff +.idea/**/workspace.xml +.idea/**/tasks.xml +.idea/**/usage.statistics.xml +.idea/**/dictionaries +.idea/**/shelf +# Generated files +.idea/**/contentModel.xml +# Sensitive or high-churn files +.idea/**/dataSources/ +.idea/**/dataSources.ids +.idea/**/dataSources.local.xml +.idea/**/sqlDataSources.xml +.idea/**/dynamic.xml +.idea/**/uiDesigner.xml +.idea/**/dbnavigator.xml +# Gradle +.idea/**/gradle.xml +.idea/**/libraries +# Gradle and Maven with auto-import +# When using Gradle or Maven with auto-import, you should exclude module files, +# since they will be recreated, and may cause churn. Uncomment if using +# auto-import. +# .idea/modules.xml +# .idea/*.iml +# .idea/modules +# CMake +cmake-build-*/ +# Mongo Explorer plugin +.idea/**/mongoSettings.xml +# File-based project format +*.iws +# IntelliJ +out/ +# mpeltonen/sbt-idea plugin +.idea_modules/ +# JIRA plugin +atlassian-ide-plugin.xml +# Cursive Clojure plugin +.idea/replstate.xml +# Crashlytics plugin (for Android Studio and IntelliJ) +com_crashlytics_export_strings.xml +crashlytics.properties +crashlytics-build.properties +fabric.properties +# Editor-based Rest Client +.idea/httpRequests +# Android studio 3.1+ serialized cache file +.idea/caches/build_file_checksums.ser +############################################################################################### + +####### c++ +# Prerequisites +*.d +# Compiled Object files +*.slo +*.lo +*.o +*.obj +# Precompiled Headers +*.gch +*.pch +# Compiled Dynamic libraries +*.so +*.dylib +*.dll +# Fortran module files +*.mod +*.smod +# Compiled Static libraries +*.lai +*.la +*.a +*.lib +# Executables +*.exe +*.out +*.app +############################## + + +#################### BUILD FILES +build/* +!build/build.xml \ No newline at end of file diff --git a/Development Guidelines.md b/Development Guidelines.md new file mode 100644 index 0000000..31dcdc0 --- /dev/null +++ b/Development Guidelines.md @@ -0,0 +1,30 @@ +1.No "using namespace std;" + +2.Clearly declare "private" inside of class. For example: + +use +```c++ +class item{ + private: + int price; + public: + getPrice(); +} +``` + +instead of class + +```c++ +class item{ + int price; + public: + getPrice(); +} +``` + + +3.Declare inheritance type(public, private, protected) when using inheritance. + +4.If not finished with code, add a TODO as comments. + +5.Add comments to explain what you want to do. \ No newline at end of file