Skip to content

Commit

Permalink
Merge pull request #31 from Apolo151/map_update_functionalities
Browse files Browse the repository at this point in the history
Added map update functionalities
  • Loading branch information
Apolo151 authored May 5, 2024
2 parents 5aaeaf2 + 86bb127 commit 1444e4f
Show file tree
Hide file tree
Showing 7 changed files with 309 additions and 219 deletions.
5 changes: 5 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,9 @@ cmake_minimum_required(VERSION 3.5)
project(guide_me)
file(GLOB HEADERS "include/*.h")
file(GLOB SOURCES "src/*.cpp")

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)

add_executable(main ${SOURCES} ${HEADERS})
10 changes: 5 additions & 5 deletions data/data.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
5
Giza - Cairo Metro 30 Bus 60 Uber 230
Giza - Dahab Bus 500 Microbus 345
Cairo - BeniSuef Microbus 20 Bus 15
Cairo - Asyut Train 250 Bus 450
Dahab - BeniSuef Microbus 200 Bus 315
Asyut - Cairo Train 250 Bus 450
BeniSuef - Cairo Microbus 20 Bus 15
BeniSuef - Dahab Microbus 200 Bus 315
Dahab - Giza Bus 500 Microbus 345
Giza - Cairo Metro 30 Bus 60 Uber 230
27 changes: 16 additions & 11 deletions include/account.h
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
#pragma once

#include "map_helpers.h"
#include <string>


using namespace std;

class Account {
private:
private:
string userName;
string password;

bool validatePassword(string);

public:
public:
Account();
Account(string, string); // signup
Account(string, string); // signup
bool greetUser();
bool signup();
bool login();
Expand All @@ -24,18 +26,21 @@ class Account {
};

class User : Account {
public:
public:
void traverseMap();
void checkState();
};

class Admin : Account {
public:
void addRoad();
void updateRoad();
void deleteRoad();
public:
void addRoad(string &city1, string &city2, int cost,
transportations transportation);
void updateRoad(string &city1, string &city2, int cost,
transportations transportation, int new_cost,
transportations new_transportation);
void deleteRoad(Road road);
//
void addCity();
void updateCity();
void deleteCity();
void addCity(string &name);
void updateCity(string &name, string &new_name);
void deleteCity(string &name);
};
6 changes: 5 additions & 1 deletion include/map_helpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ class RoadProperties {
//
RoadProperties(int, transportations);
RoadProperties(const RoadProperties&);

bool operator==(const RoadProperties &other) const {
return other.cost == cost && other.transport == transport;
}
};

class Road : Edge {
Expand All @@ -50,4 +54,4 @@ class Route {
Route(const Route&);
//
void addRoad(RoadProperties);
};
};
189 changes: 123 additions & 66 deletions src/account.cpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
#include "../include/account.h"
#include "../include/map.h"
#include <cassert>
#include <iostream>


Account::Account() {
userName = "";
password = "";
userName = "";
password = "";
}

Account::Account(string userName, string password) {
Expand All @@ -13,68 +14,66 @@ Account::Account(string userName, string password) {
}

bool Account::validatePassword(string pass) {
if (pass.size() < 6)
return false;
// TOOD: Add more validation
return true;
if (pass.size() < 6)
return false;
// TOOD: Add more validation
return true;
}

bool Account::greetUser() {
int x = 9;
cout << "Hello, There...\n";
cout << "What do you want to do?\n";
while (x != 1 && x != 2) {
cout << "1.Login 2.signup\n";
cin >> x;
if (x == 1) {
login();
}
else if (x == 2) {
signup();
}
else
cout << "Invalid option, Try again...\n";
}
return true;
int x = 9;
cout << "Hello, There...\n";
cout << "What do you want to do?\n";
while (x != 1 && x != 2) {
cout << "1.Login 2.signup\n";
cin >> x;
if (x == 1) {
login();
} else if (x == 2) {
signup();
} else
cout << "Invalid option, Try again...\n";
}
return true;
}

bool Account::signup() {
string userName, password = "77";
cout << "Enter your wanted username:\n";
cin >> userName;
cout << '\n';
cout << "Enter your wanted password:\n";
cin >> password;
while (!validatePassword(password)) {
cout << "Please enter a valid password, your password must be at least 6 characters long\n";
cin >> password;
}
cout << "Signup Successful!!\n";
this->setName(userName);
this->setPassword(password);
login();
return true;
string userName, password = "77";
cout << "Enter your wanted username:\n";
cin >> userName;
cout << '\n';
cout << "Enter your wanted password:\n";
cin >> password;
while (!validatePassword(password)) {
cout << "Please enter a valid password, your password must be at least "
"6 characters long\n";
cin >> password;
}
cout << "Signup Successful!!\n";
this->setName(userName);
this->setPassword(password);
login();
return true;
}

bool Account::login() {
string userName, password;
bool done = false;
while (!done) {
cout << "Enter your username:\n";
cin >> userName;
cout << "Enter your password:\n";
cin >> password;
// TODO: add searching in users data
cout << this->getName() << " " << this->getPassword() << '\n';
if (userName == this->getName() && password == this->getPassword()) {
cout << "Login Successful!!\n";
done = true;
}
else {
cout << "Invalid data, Try again...\n";
}
}
return true;
string userName, password;
bool done = false;
while (!done) {
cout << "Enter your username:\n";
cin >> userName;
cout << "Enter your password:\n";
cin >> password;
// TODO: add searching in users data
cout << this->getName() << " " << this->getPassword() << '\n';
if (userName == this->getName() && password == this->getPassword()) {
cout << "Login Successful!!\n";
done = true;
} else {
cout << "Invalid data, Try again...\n";
}
}
return true;
}

string Account::getName() { return userName; }
Expand All @@ -84,22 +83,80 @@ void Account::setName(string name) { userName = name; }
void Account::setPassword(string password) { this->password = password; }

void User::traverseMap() {
int option = -1;
cout << "How do you want to traverse?\n";
cout << "1.BFS 2.DFS";
cin >> option;
int option = -1;
cout << "How do you want to traverse?\n";
cout << "1.BFS 2.DFS";
cin >> option;
}

void User::checkState() {}

void Admin::addCity() {}
void Admin::addCity(string &name) {
// add it as a key
auto &adjList = Map::adjList;
adjList[name] = {};
}

void Admin::updateCity(string &name, string &new_name) { // NOTE: if city doesn't exist, the new city will just be added

// find it, update name, and update name in all connections
auto &adjList = Map::adjList;

void Admin::updateCity() {}
for (auto [city, connections] : adjList[name]) { // erase all connections
auto it = adjList[city].find(name);
assert(it != adjList[city].end());
adjList[city].erase(it);

adjList[city].emplace(new_name, connections);
}

auto temp = adjList[name];
adjList.erase(adjList.find(name)); // erase key
adjList.emplace(new_name, temp);
}

void Admin::deleteCity() {}
void Admin::deleteCity(string &name) { // WARNING: city doesn't exist -> runtime error!
// delete key, delete connections

void Admin::addRoad() {}
auto &adjList = Map::adjList;

void Admin::updateRoad() {}
for (auto [city, connections] : adjList[name]) { // erase all connections
auto it = adjList[city].find(name);
assert(it != adjList[city].end());
adjList[city].erase(it);
}

adjList.erase(adjList.find(name)); // erase key
}

void Admin::addRoad(string &city1, string &city2, int cost,
transportations transportation) {
// add it to connections
auto &adjList = Map::adjList;

adjList[city1][city2].addRoad(RoadProperties(cost, transportation));
adjList[city2][city1].addRoad(RoadProperties(cost, transportation));
}

void Admin::updateRoad(string &city1, string &city2, int cost, transportations transportation, int new_cost,
transportations new_transportation) {
// change props
deleteRoad(Road(city1, city2, RoadProperties(cost, transportation)));
addRoad(city1, city2, new_cost, new_transportation);
}

void Admin::deleteRoad() {}
void Admin::deleteRoad(Road road) { // WARNING: road doesn't exist -> runtimer error!

// delete connection
auto &adjList = Map::adjList;
auto city1 = road.city1Name;
auto city2 = road.city2Name;

adjList[city1][city2].roads.remove(road.props);
adjList[city2][city1].roads.remove(road.props);

if (adjList[city1][city2].roads.empty()) {
adjList[city1].erase(city2);
adjList[city2].erase(city1);
}
}
Loading

0 comments on commit 1444e4f

Please sign in to comment.