Merge branch 'master' of https://git.tau.aperturect.com/AP-CT/Parkmanne
This commit is contained in:
commit
174b41d507
150
.gitignore
vendored
Normal file
150
.gitignore
vendored
Normal file
@ -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
|
30
Customer.cpp
Normal file
30
Customer.cpp
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
#include "headers/Customer.h"
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
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";
|
||||||
|
}
|
30
Development Guidelines.md
Normal file
30
Development Guidelines.md
Normal file
@ -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.
|
20
Park_spot.cpp
Normal file
20
Park_spot.cpp
Normal file
@ -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;
|
||||||
|
}
|
||||||
|
}
|
45
Park_time.cpp
Normal file
45
Park_time.cpp
Normal file
@ -0,0 +1,45 @@
|
|||||||
|
#include"headers/Park_time.h"
|
||||||
|
#include <iostream>
|
||||||
|
#include <ctime>
|
||||||
|
|
||||||
|
|
||||||
|
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<seconds>(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;
|
||||||
|
}
|
37
headers/Customer.h
Normal file
37
headers/Customer.h
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
#ifndef CUSTOMER_H
|
||||||
|
#define CUSTOMER_H
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <vector>
|
||||||
|
#include <string>
|
||||||
|
#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_time> park_instances;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#endif // CUSTOMER_H
|
19
headers/Park_spot.h
Normal file
19
headers/Park_spot.h
Normal file
@ -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:
|
||||||
|
};
|
40
headers/Park_time.h
Normal file
40
headers/Park_time.h
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
#ifndef PARK_TIME_H
|
||||||
|
#define PARK_TIME_H
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <chrono>
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
|
||||||
|
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
|
55
main.cpp
Normal file
55
main.cpp
Normal file
@ -0,0 +1,55 @@
|
|||||||
|
#include "headers/Park_spot.h"
|
||||||
|
#include <iostream>
|
||||||
|
#include <thread> // to make pausing work, not sure if i need chrono, or this, or both
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
void Wait(int sec)
|
||||||
|
{
|
||||||
|
std::this_thread::sleep_for(seconds { sec });
|
||||||
|
}
|
||||||
|
|
||||||
|
using std::cout;
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
std::vector<Park_spot> spots {
|
||||||
|
1, 2, 3, 4, 5
|
||||||
|
};
|
||||||
|
std::vector<Customer> 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();
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user