Added labels and are u sure? msg
This commit is contained in:
		@@ -6,13 +6,15 @@
 | 
				
			|||||||
// cin.ignore(10000, '\n');
 | 
					// cin.ignore(10000, '\n');
 | 
				
			||||||
// so it skips to the next newline, in essence clearing the cin buffer
 | 
					// so it skips to the next newline, in essence clearing the cin buffer
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					bool verify(void);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void interface(vector<Park_spot>& spots) {
 | 
					void interface(vector<Park_spot>& spots) {
 | 
				
			||||||
    /*
 | 
					    /*
 | 
				
			||||||
    string introduction = "P A R K M A N N E"; //logo animation, disable during testing
 | 
					    string introduction = "P A R K M A N N E"; //logo animation, disable during testing
 | 
				
			||||||
    text_animation(introduction, 50);
 | 
					    text_animation(introduction, 50);
 | 
				
			||||||
    */
 | 
					    */
 | 
				
			||||||
 | 
					   __label__ exit;
 | 
				
			||||||
    cout << "\nWelcome to the parking system. Please login..";
 | 
					    cout << "\nWelcome to the parking system. Please login...";
 | 
				
			||||||
    int id;
 | 
					    int id;
 | 
				
			||||||
    string password;
 | 
					    string password;
 | 
				
			||||||
    cout << "\nEnter your id: ";
 | 
					    cout << "\nEnter your id: ";
 | 
				
			||||||
@@ -21,9 +23,11 @@ void interface(vector<Park_spot>& spots) {
 | 
				
			|||||||
    Customer c = query_customer_with_id(id);
 | 
					    Customer c = query_customer_with_id(id);
 | 
				
			||||||
    cout << "\nEnter your password: ";
 | 
					    cout << "\nEnter your password: ";
 | 
				
			||||||
    std::getline(cin, password);
 | 
					    std::getline(cin, password);
 | 
				
			||||||
 | 
					    
 | 
				
			||||||
    while (!(verify_password(c.password, password))) {
 | 
					    while (!(verify_password(c.password, password))) {
 | 
				
			||||||
        cout << "ERROR: wrong password. Please retype your password:\n";
 | 
					        cout << "ERROR: wrong password. Please retype your password or type [x] to exit:\n";
 | 
				
			||||||
        std::getline(cin, password);
 | 
					        std::getline(cin, password);
 | 
				
			||||||
 | 
					        if(password=="x")goto exit;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    if (query_role_customer(id) == 1) {
 | 
					    if (query_role_customer(id) == 1) {
 | 
				
			||||||
        interface_admin(spots);
 | 
					        interface_admin(spots);
 | 
				
			||||||
@@ -32,11 +36,16 @@ void interface(vector<Park_spot>& spots) {
 | 
				
			|||||||
    } else {
 | 
					    } else {
 | 
				
			||||||
        cout << "ERROR ROLE_INVALID!";
 | 
					        cout << "ERROR ROLE_INVALID!";
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					    exit:;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void interface_member(vector<Park_spot>& spots, Customer& c) {
 | 
					void interface_member(vector<Park_spot>& spots, Customer& c) {
 | 
				
			||||||
 | 
					    __label__ begin, exit;
 | 
				
			||||||
    cout << "\nLogged in succesfully!\n";
 | 
					    cout << "\nLogged in succesfully!\n";
 | 
				
			||||||
    cout << "select an option:\n [1] Parking\n[2]Monthly report\n";
 | 
					    
 | 
				
			||||||
 | 
					    begin:
 | 
				
			||||||
 | 
					    cout <<"Hello! "<<c.name<< ", please select an option:\n[1]Parking\n[2]Monthly report\n"
 | 
				
			||||||
 | 
					    "[3]Edit information\n[4]Exit\n";
 | 
				
			||||||
    int option;
 | 
					    int option;
 | 
				
			||||||
    cin >> option;
 | 
					    cin >> option;
 | 
				
			||||||
    cin.ignore(10000, '\n');
 | 
					    cin.ignore(10000, '\n');
 | 
				
			||||||
@@ -50,16 +59,32 @@ void interface_member(vector<Park_spot>& spots, Customer& c) {
 | 
				
			|||||||
        break;
 | 
					        break;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    case 3: {
 | 
				
			||||||
 | 
					        cout << "Has not been implemented yet\n";
 | 
				
			||||||
 | 
					        break;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    case 4: {
 | 
				
			||||||
 | 
					        cout << "Exiting...\n";
 | 
				
			||||||
 | 
					        goto exit;
 | 
				
			||||||
 | 
					        break;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    default:
 | 
					    default:
 | 
				
			||||||
        break;
 | 
					        break;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					    goto begin;
 | 
				
			||||||
 | 
					    exit:;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void interface_admin(vector<Park_spot>& spots) {
 | 
					void interface_admin(vector<Park_spot>& spots) {
 | 
				
			||||||
    cout << "\nWelcome to the admin interface.\n";
 | 
					    __label__ begin,exit;
 | 
				
			||||||
 | 
					    begin:
 | 
				
			||||||
 | 
					    cout << "\nWelcome to the admin interface\n";
 | 
				
			||||||
    cout << "\n[1] Reports & analytics";
 | 
					    cout << "\n[1] Reports & analytics";
 | 
				
			||||||
    cout << "\n[2] Parking spots";
 | 
					    cout << "\n[2] Parking spots";
 | 
				
			||||||
    cout << "\n[3] Make new user";
 | 
					    cout << "\n[3] Make new user";
 | 
				
			||||||
 | 
					    cout << "\n[4] Exit";
 | 
				
			||||||
    cout << "\nEnter option number: ";
 | 
					    cout << "\nEnter option number: ";
 | 
				
			||||||
    int option;
 | 
					    int option;
 | 
				
			||||||
    cin >> option;
 | 
					    cin >> option;
 | 
				
			||||||
@@ -70,6 +95,7 @@ void interface_admin(vector<Park_spot>& spots) {
 | 
				
			|||||||
        cout << "[2] See weekly report of ALL parking spots\n";
 | 
					        cout << "[2] See weekly report of ALL parking spots\n";
 | 
				
			||||||
        cout << "[3] See monthly report of a specific parking spot\n";
 | 
					        cout << "[3] See monthly report of a specific parking spot\n";
 | 
				
			||||||
        cout << "[4] See weekly report of a specific parking spot\n";
 | 
					        cout << "[4] See weekly report of a specific parking spot\n";
 | 
				
			||||||
 | 
					        cout << "[5] Return\n";
 | 
				
			||||||
        cout << "Enter option number: ";
 | 
					        cout << "Enter option number: ";
 | 
				
			||||||
        int option_1;
 | 
					        int option_1;
 | 
				
			||||||
        cin >> option_1;
 | 
					        cin >> option_1;
 | 
				
			||||||
@@ -91,13 +117,17 @@ void interface_admin(vector<Park_spot>& spots) {
 | 
				
			|||||||
            report_single_spot(true);
 | 
					            report_single_spot(true);
 | 
				
			||||||
            break;
 | 
					            break;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        default:
 | 
					        case 5:{
 | 
				
			||||||
 | 
					            goto begin;
 | 
				
			||||||
            break;
 | 
					            break;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					        break;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    case 2: {
 | 
					    case 2: {
 | 
				
			||||||
        cout << "[1] See current status of parking spots\n";
 | 
					        cout << "[1] See current status of parking spots\n";
 | 
				
			||||||
        cout << "[2] Make new parking spot\n";
 | 
					        cout << "[2] Make new parking spot\n";
 | 
				
			||||||
 | 
					        cout << "[3] Return\n";
 | 
				
			||||||
        cout << "Enter option number: ";
 | 
					        cout << "Enter option number: ";
 | 
				
			||||||
        int option_2;
 | 
					        int option_2;
 | 
				
			||||||
        cin >> option_2;
 | 
					        cin >> option_2;
 | 
				
			||||||
@@ -109,14 +139,21 @@ void interface_admin(vector<Park_spot>& spots) {
 | 
				
			|||||||
        }
 | 
					        }
 | 
				
			||||||
        case 2: {
 | 
					        case 2: {
 | 
				
			||||||
            new_parkspot(spots);
 | 
					            new_parkspot(spots);
 | 
				
			||||||
 | 
					            break;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        case 3:{
 | 
				
			||||||
 | 
					            goto begin;
 | 
				
			||||||
 | 
					            break;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        default:
 | 
					        default:
 | 
				
			||||||
            break;
 | 
					            break;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					        break;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    case 3: {
 | 
					    case 3: {
 | 
				
			||||||
        cout << "[1] Make new customer\n";
 | 
					        cout << "[1] Make new customer\n";
 | 
				
			||||||
        cout << "[2] Make new admin\n";
 | 
					        cout << "[2] Make new admin\n";
 | 
				
			||||||
 | 
					        cout << "[3] Return\n";
 | 
				
			||||||
        cout << "Enter option number: ";
 | 
					        cout << "Enter option number: ";
 | 
				
			||||||
        int option_3;
 | 
					        int option_3;
 | 
				
			||||||
        cin >> option_3;
 | 
					        cin >> option_3;
 | 
				
			||||||
@@ -130,41 +167,55 @@ void interface_admin(vector<Park_spot>& spots) {
 | 
				
			|||||||
            new_admin();
 | 
					            new_admin();
 | 
				
			||||||
            break;
 | 
					            break;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					        case 3:{
 | 
				
			||||||
 | 
					            goto begin;
 | 
				
			||||||
 | 
					            break;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
        default:
 | 
					        default:
 | 
				
			||||||
            break;
 | 
					            break;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					        case 4: {goto exit;break;}
 | 
				
			||||||
 | 
					        break;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    default:
 | 
					    default:
 | 
				
			||||||
        break;
 | 
					        break;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					    goto begin;
 | 
				
			||||||
 | 
					    exit:;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// --------- individual things.
 | 
					// --------- individual things.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void park(Customer& c, vector<Park_spot>& spots) {
 | 
					void park(Customer& c, vector<Park_spot>& spots) {
 | 
				
			||||||
 | 
					    __label__ exit;
 | 
				
			||||||
    cout << "You have selected parking option.\n";
 | 
					    cout << "You have selected parking option.\n";
 | 
				
			||||||
    if (!(c.parked())) {
 | 
					    if (!(c.parked())) {
 | 
				
			||||||
        cout << "The following spots fit your vehicle and are available: ";
 | 
					        cout << "The following spots fit your vehicle and are available: \n";
 | 
				
			||||||
        for (Park_spot i : spots) {
 | 
					        for (Park_spot i : spots) {
 | 
				
			||||||
            if (i.v_type == c.vehicle) {
 | 
					            if ((i.v_type == c.vehicle)&(i.taken==false)) {
 | 
				
			||||||
                cout << i.id << ", ";
 | 
					                cout << i.id << ", ";
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        cout << "\nWhere do you want to park?";
 | 
					        cout << "\nWhere do you want to park? Or type [0] to exit.";
 | 
				
			||||||
        int parkID;
 | 
					        int parkID;
 | 
				
			||||||
        cin >> parkID;
 | 
					        cin >> parkID;
 | 
				
			||||||
 | 
					        if (!parkID)goto exit;
 | 
				
			||||||
        cin.ignore(10000, '\n');
 | 
					        cin.ignore(10000, '\n');
 | 
				
			||||||
        for (Park_spot& i : spots) {
 | 
					        for (Park_spot& i : spots) {
 | 
				
			||||||
            if (i.id == parkID) {
 | 
					            if (i.id == parkID) {
 | 
				
			||||||
 | 
					                if (verify())
 | 
				
			||||||
 | 
					                {
 | 
				
			||||||
                i.clock(c);
 | 
					                i.clock(c);
 | 
				
			||||||
                cout << "You have parked sucessfully!";
 | 
					                cout << "You have parked sucessfully!";
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    } else {
 | 
					    } else {
 | 
				
			||||||
        cout << "You are parked at spot " << c.parked_at()
 | 
					        cout << "You are parked at spot " << c.parked_at()
 | 
				
			||||||
             << ", do you want to clock out?\n[1] yes\n[2] no";
 | 
					             << ", do you want to clock out?\n[1] Yes\n[2] No";
 | 
				
			||||||
        int answer = 0;
 | 
					        int answer = 0;
 | 
				
			||||||
        cin >> answer;
 | 
					        cin >> answer;
 | 
				
			||||||
        cin.ignore(10000, '\n');
 | 
					        cin.ignore(10000, '\n');
 | 
				
			||||||
@@ -175,6 +226,7 @@ void park(Customer& c, vector<Park_spot>& spots) {
 | 
				
			|||||||
            cout << "OK, have a nice day."; // exit to customer login
 | 
					            cout << "OK, have a nice day."; // exit to customer login
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					    exit:;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void new_customer() {
 | 
					void new_customer() {
 | 
				
			||||||
@@ -185,7 +237,7 @@ void new_customer() {
 | 
				
			|||||||
    int role = 0;
 | 
					    int role = 0;
 | 
				
			||||||
    cout << "\nWhat's the name of the customer? ";
 | 
					    cout << "\nWhat's the name of the customer? ";
 | 
				
			||||||
    std::getline(cin, name);
 | 
					    std::getline(cin, name);
 | 
				
			||||||
    cout << "\nWhat's the vehicle type? \n[1]twoweeler\n[2] fourweeler\n";
 | 
					    cout << "\nWhat's the vehicle type? \n[1]Twowheeler\n[2] Fourwheeler\n";
 | 
				
			||||||
    cin >> vtype;
 | 
					    cin >> vtype;
 | 
				
			||||||
    cin.ignore(10000, '\n');
 | 
					    cin.ignore(10000, '\n');
 | 
				
			||||||
    cout << "What's the telephone number? +";
 | 
					    cout << "What's the telephone number? +";
 | 
				
			||||||
@@ -194,7 +246,7 @@ void new_customer() {
 | 
				
			|||||||
    std::getline(cin, password);
 | 
					    std::getline(cin, password);
 | 
				
			||||||
    Customer newcustomer{name, password, Vehicle_type(vtype), telephone, role};
 | 
					    Customer newcustomer{name, password, Vehicle_type(vtype), telephone, role};
 | 
				
			||||||
    cout << "\nNew customer sucessfully created\n";
 | 
					    cout << "\nNew customer sucessfully created\n";
 | 
				
			||||||
    newcustomer.update_db();
 | 
					    if (verify())newcustomer.update_db();
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void new_admin() {
 | 
					void new_admin() {
 | 
				
			||||||
@@ -211,17 +263,17 @@ void new_admin() {
 | 
				
			|||||||
    std::getline(cin, password);
 | 
					    std::getline(cin, password);
 | 
				
			||||||
    Customer newcustomer{name, password, Vehicle_type(vtype), telephone, role};
 | 
					    Customer newcustomer{name, password, Vehicle_type(vtype), telephone, role};
 | 
				
			||||||
    cout << "\nNew customer sucessfully created\n";
 | 
					    cout << "\nNew customer sucessfully created\n";
 | 
				
			||||||
    newcustomer.update_db();
 | 
					    if(verify())newcustomer.update_db();
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void new_parkspot(vector<Park_spot>& spots) {
 | 
					void new_parkspot(vector<Park_spot>& spots) {
 | 
				
			||||||
    cout << "What type of parking spot? \n[1] twoweeler\n[2] fourweeler\n";
 | 
					    cout << "What type of parking spot? \n[1] Twowheeler\n[2] Fourwheeler\n";
 | 
				
			||||||
    int vtype;
 | 
					    int vtype;
 | 
				
			||||||
    cin >> vtype;
 | 
					    cin >> vtype;
 | 
				
			||||||
    cin.ignore(10000, '\n');
 | 
					    cin.ignore(10000, '\n');
 | 
				
			||||||
    Park_spot newspot{Vehicle_type(vtype)};
 | 
					    Park_spot newspot{Vehicle_type(vtype)};
 | 
				
			||||||
    spots.push_back(newspot);
 | 
					    if(verify()){spots.push_back(newspot);
 | 
				
			||||||
    cout << "New parking spot sucessfully created.\n";
 | 
					    cout << "New parking spot sucessfully created.\n";}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// time stuff-----------------------------------------------------
 | 
					// time stuff-----------------------------------------------------
 | 
				
			||||||
@@ -304,4 +356,16 @@ void report_customer(int customerID, bool weekly) {
 | 
				
			|||||||
        pair<int, int> period = create_month_period();
 | 
					        pair<int, int> period = create_month_period();
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    reports_from_customer(customerID, period);
 | 
					    reports_from_customer(customerID, period);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					bool verify(void)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					string ver;
 | 
				
			||||||
 | 
					std::cout<<"\nAre you sure you want to commit these actions?"
 | 
				
			||||||
 | 
						"\n[No] Revert."
 | 
				
			||||||
 | 
						"\n[Yes] Commit.";
 | 
				
			||||||
 | 
					std::cin>>ver;
 | 
				
			||||||
 | 
					if (ver=="YES"|ver=="Yes"|ver=="yes") return true;
 | 
				
			||||||
 | 
					else return false;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
							
								
								
									
										18
									
								
								main.cpp
									
									
									
									
									
								
							
							
						
						
									
										18
									
								
								main.cpp
									
									
									
									
									
								
							@@ -45,21 +45,11 @@ static vector<Park_spot> parking_spots = populate_spots();
 | 
				
			|||||||
static vector<Customer> park_customers;
 | 
					static vector<Customer> park_customers;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
int main() {
 | 
					int main() {
 | 
				
			||||||
    // state of db:
 | 
					    
 | 
				
			||||||
    // er zijn 10 parkspots, 5 met biketype en 5 met pickup type
 | 
					    while (true) {interface(parking_spots); }         
 | 
				
			||||||
    // er is een customer met id 1(testcustomer) met password "password"
 | 
					        
 | 
				
			||||||
    while (true) {
 | 
					 | 
				
			||||||
        cin.clear();
 | 
					 | 
				
			||||||
        interface(parking_spots);
 | 
					 | 
				
			||||||
        cout << "\nexit? Input 'y' or 'n'..";
 | 
					 | 
				
			||||||
        char n;
 | 
					 | 
				
			||||||
        cin >> n;
 | 
					 | 
				
			||||||
        cin.clear();
 | 
					 | 
				
			||||||
        if (n == 'y') {
 | 
					 | 
				
			||||||
            break;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/*
 | 
					/*
 | 
				
			||||||
Why is this not in query.cpp? Because somehow, it errors out when it's there.
 | 
					Why is this not in query.cpp? Because somehow, it errors out when it's there.
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										
											BIN
										
									
								
								oldtest.db3
									
									
									
									
									
								
							
							
						
						
									
										
											BIN
										
									
								
								oldtest.db3
									
									
									
									
									
								
							
										
											Binary file not shown.
										
									
								
							
		Reference in New Issue
	
	Block a user