From 9a10e332790bb993b69697ef34f1a5620c22204b Mon Sep 17 00:00:00 2001 From: MassiveAtoms Date: Mon, 24 Jun 2019 21:09:33 -0300 Subject: [PATCH] initialize db --- Customer.cpp | 26 ++++++++++++++++++++- db.cpp | 21 +++++++++++++++++ headers/Customer.h | 4 +++- headers/Park_time.h | 1 - headers/db.h | 56 +++++++++++++++++++++++++++++++++++++++++++++ main.cpp | 9 ++++---- 6 files changed, 110 insertions(+), 7 deletions(-) create mode 100644 db.cpp create mode 100644 headers/db.h diff --git a/Customer.cpp b/Customer.cpp index a77d2c3..c850386 100644 --- a/Customer.cpp +++ b/Customer.cpp @@ -1,13 +1,37 @@ #include "headers/Customer.h" #include +#include +#include + + // moet aangepast worden om een verhicle_type toe te voegen -Customer::Customer(int id_, string name_) +Customer::Customer(int id_, string name_, Verhicle_type verhicle_) : id { id_ } , name { name_ } + , card_code{gen_cardcode()} + , verhicle{verhicle_} { } + +/* +generates a cardcode that can be stored on a card that can be used to authenticate. +Before that, some random generator starter settings. + */ + std::mt19937 mt(time(0)); + std::uniform_int_distribution dist(48, 90); // anything between and including ascii 48(0) and 90(z) + +string Customer::gen_cardcode (){ + string code; + for (int i = 0; i < 20; i++){ + code += char(dist(mt)); + } + return code; + +} + + /* creert een park_time object met start time= nu, en voegt t toe aan een vector. */ diff --git a/db.cpp b/db.cpp new file mode 100644 index 0000000..fc8dbbf --- /dev/null +++ b/db.cpp @@ -0,0 +1,21 @@ +#include "headers/db.h" + +namespace db +{ + + + static int callback(void *NotUsed, int argc, char **argv, char **azColName){ + int i; + for(i=0; i park_instances; + string gen_cardcode(); + }; diff --git a/headers/Park_time.h b/headers/Park_time.h index 435234a..31c3db1 100644 --- a/headers/Park_time.h +++ b/headers/Park_time.h @@ -20,7 +20,6 @@ datetime end Dit is gewoon een record van hoe lang, wie en waar iemand parkeert. Basically, een component van de internal state van customer. */ - class Park_time { public: int id; diff --git a/headers/db.h b/headers/db.h new file mode 100644 index 0000000..ff0806d --- /dev/null +++ b/headers/db.h @@ -0,0 +1,56 @@ +#include +#include +#include + +namespace db +{ + + static int callback(void *NotUsed, int argc, char **argv, char **azColName); + + sqlite3* db; + char* error_message; + + + + void open_db(sqlite3* db_){ + int success = sqlite3_open("sqlite.db", &db); + if (!success) { + std::cout << "Can't open database: "< + /* Code strucure like this: class declarations zijn in /headers/class_naam.h, en definitions van de member functs in /class_naam.cpp @@ -35,10 +36,10 @@ int main() 1, 2, 3, 4, 5 }; std::vector customers { - { 1, "Sagar Ram" }, - { 2, "Shaq" }, - { 3, "Josh" }, - { 4, "Stefano" } + { 1, "Sagar Ram", Verhicle_type::small }, + { 2, "Shaq", Verhicle_type::medium }, + { 3, "Josh", Verhicle_type::large }, + { 4, "Stefano", Verhicle_type::small } }; spots[1].clock(&customers[3]); // stefano parks at spot 2