Important change to Parkspot #5
@@ -25,6 +25,8 @@ add_executable(park
 | 
			
		||||
        headers/Park_time.h
 | 
			
		||||
        Query.cpp
 | 
			
		||||
        headers/Query.h
 | 
			
		||||
        Interface.cpp
 | 
			
		||||
        headers/Interface.h
 | 
			
		||||
 )
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										10
									
								
								Customer.cpp
									
									
									
									
									
								
							
							
						
						
									
										10
									
								
								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<Park_time> instances)
 | 
			
		||||
                   Vehicle_type vehicle_, vector<Park_time> 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));
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										40
									
								
								Interface.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										40
									
								
								Interface.cpp
									
									
									
									
									
										Normal file
									
								
							@@ -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();
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										12
									
								
								Query.cpp
									
									
									
									
									
								
							
							
						
						
									
										12
									
								
								Query.cpp
									
									
									
									
									
								
							@@ -38,16 +38,16 @@ vector<Customer> query_customer_with_name(string name) {
 | 
			
		||||
    vector<Customer> 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_time> 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_time> 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 << "," <<result.password <<"," << int(verhicle) << "}\n";
 | 
			
		||||
        // cout << "{" << result.id << "," <<result.password <<"," << int(vehicle) << "}\n";
 | 
			
		||||
        return result;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										2
									
								
								data.cpp
									
									
									
									
									
								
							
							
						
						
									
										2
									
								
								data.cpp
									
									
									
									
									
								
							@@ -20,7 +20,7 @@ SQLite::Database start_db() {
 | 
			
		||||
    //sql syntax is surprisingly readable.
 | 
			
		||||
    db.exec(
 | 
			
		||||
        "create table if not exists Customer (id integer primary key, name "
 | 
			
		||||
        "text, password text, verhicle int)");
 | 
			
		||||
        "text, password text, vehicle int)");
 | 
			
		||||
        // 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 "
 | 
			
		||||
 
 | 
			
		||||
@@ -11,12 +11,12 @@ using std::vector;
 | 
			
		||||
 | 
			
		||||
/*
 | 
			
		||||
enum classes make it easy to represent categories.
 | 
			
		||||
So you can use something like Verhicle_type::car instead of 2. but under the
 | 
			
		||||
So you can use something like Vehicle_type::car instead of 2. but under the
 | 
			
		||||
hood, it's still an int. This is here so you won't have to have global variables
 | 
			
		||||
for these categories, or worse, use magic numbers in the code.
 | 
			
		||||
 | 
			
		||||
 */
 | 
			
		||||
enum class Verhicle_type { bike = 1, small_car = 2, suv = 3, pickup = 4 };
 | 
			
		||||
enum class Vehicle_type { bike = 1, small_car = 2, suv = 3, pickup = 4 };
 | 
			
		||||
 | 
			
		||||
/*
 | 
			
		||||
Customer constructors do the same stuff as all the other constructors.
 | 
			
		||||
@@ -38,8 +38,8 @@ class Customer {
 | 
			
		||||
    int id;
 | 
			
		||||
    string name;
 | 
			
		||||
    string password;
 | 
			
		||||
    Customer(string name_, string password_, Verhicle_type verhicle_);
 | 
			
		||||
    Customer(int id_, string name_, string password_, Verhicle_type verhicle_,
 | 
			
		||||
    Customer(string name_, string password_, Vehicle_type vehicle_);
 | 
			
		||||
    Customer(int id_, string name_, string password_, Vehicle_type vehicle_,
 | 
			
		||||
             vector<Park_time> 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_time> park_instances;
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										9
									
								
								headers/Interface.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										9
									
								
								headers/Interface.h
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,9 @@
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
#include "Query.h"
 | 
			
		||||
 | 
			
		||||
using std::cin;
 | 
			
		||||
 | 
			
		||||
void interface();
 | 
			
		||||
void interface_member();
 | 
			
		||||
void interface_admin();
 | 
			
		||||
@@ -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);
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										18
									
								
								main.cpp
									
									
									
									
									
								
							
							
						
						
									
										18
									
								
								main.cpp
									
									
									
									
									
								
							@@ -1,4 +1,4 @@
 | 
			
		||||
#include "headers/Query.h"
 | 
			
		||||
#include "headers/Interface.h"
 | 
			
		||||
 | 
			
		||||
#include <thread>
 | 
			
		||||
 | 
			
		||||
@@ -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();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/*
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										
											BIN
										
									
								
								old_test.db3
									
									
									
									
									
								
							
							
						
						
									
										
											BIN
										
									
								
								old_test.db3
									
									
									
									
									
								
							
										
											Binary file not shown.
										
									
								
							
		Reference in New Issue
	
	Block a user