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/Customer.cpp b/Customer.cpp new file mode 100644 index 0000000..3f54a89 --- /dev/null +++ b/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) { + // TODO: 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/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 diff --git a/Park_spot.cpp b/Park_spot.cpp new file mode 100644 index 0000000..95d1928 --- /dev/null +++ b/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/Park_time.cpp b/Park_time.cpp new file mode 100644 index 0000000..267e0c0 --- /dev/null +++ b/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/headers/Customer.h b/headers/Customer.h new file mode 100644 index 0000000..9567bbe --- /dev/null +++ b/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(); TODO: this + 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/headers/Park_spot.h b/headers/Park_spot.h new file mode 100644 index 0000000..83239ee --- /dev/null +++ b/headers/Park_spot.h @@ -0,0 +1,19 @@ +#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; //TODO: think about memory management + Park_spot(int id_); + void clock(Customer* c_customer); + private: +}; \ No newline at end of file diff --git a/headers/Park_time.h b/headers/Park_time.h new file mode 100644 index 0000000..a35067f --- /dev/null +++ b/headers/Park_time.h @@ -0,0 +1,40 @@ +#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; + //TODO: discuss pros cons of using chrono, ctime, or 3th party lib +}; + + + + +#endif // Park_time \ No newline at end of file diff --git a/main.cpp b/main.cpp new file mode 100644 index 0000000..dc08007 --- /dev/null +++ b/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 diff --git a/readme.md b/readme.md new file mode 100644 index 0000000..a6772f4 --- /dev/null +++ b/readme.md @@ -0,0 +1,6 @@ + +use +``` +g++ main.cpp Park_time.cpp Customer.cpp Park_spot.cpp -o test.exe +``` +to build the project \ No newline at end of file