diff --git a/include/Dataset.h b/include/Dataset.h index 7befe5f..81e30f2 100644 --- a/include/Dataset.h +++ b/include/Dataset.h @@ -41,6 +41,11 @@ class Dataset { std::vector getAirportsFromCity(const City& city); std::vector getCountriesAirportFliesTo(const Airport& airport); std::vector getCountriesCityFliesTo(const City& city); + std::vector searchFlightsFromAirport(std::string airPortCode); + float numberOfFlightsByCity(); + float numberOfFlightsByAirline(); + std::vector searchDestinationsFromAirport(std::string airPortCode); + std::vector searchTopNAirPortsWithGreatestTraffic(int n); private: CountrySet countrySet_; diff --git a/include/Flight.h b/include/Flight.h index 2754bad..2b7db2a 100644 --- a/include/Flight.h +++ b/include/Flight.h @@ -17,7 +17,6 @@ class AirportInfo; class FlightInfo { public: explicit FlightInfo(AirlineRef airline, const AirportInfo& src, const AirportInfo& dest); - const AirlineRef &getAirline() const; double getDistance() const; diff --git a/include/Program.h b/include/Program.h index 3094758..b1264f2 100644 --- a/include/Program.h +++ b/include/Program.h @@ -14,12 +14,21 @@ class Program { Program(); void launch(); + void displayAllCountries(); + void displayAllAirports(); + void displayAllAirlines(); + void displayAirlinesByCountry(); + void displayCitiesByCountry(); + void displayAirportsByCity(); + void displayFlightsFromAirport(); + void displayCountriesFlyingToAirport(); + void displayCountriesFlyingToCity(); private: Dataset dataset_; - void displayMainMenu(); - + void searchMenu(); + void statisticsMenu(); static int receiveOption(int max); CountryRef receiveCountry() const; CityRef receiveCity() const; diff --git a/src/Dataset.cpp b/src/Dataset.cpp index 09150e7..af49518 100644 --- a/src/Dataset.cpp +++ b/src/Dataset.cpp @@ -167,6 +167,61 @@ vector Dataset::getCountriesCityFliesTo(const City& city) { return countries1; } +vector Dataset::searchFlightsFromAirport(string airPortCode) { + AirportRef airport = getAirport(airPortCode); + vector flights; + if (airport.lock()) { + for (const auto& flight : airport.lock()->getAdj()){ + flights.push_back(flight); + } + } + return flights; +} + +float Dataset::numberOfFlightsByCity() { + int cities = getCities().size(); + int flights = 0; + for(const auto& city : getCities()){ + for(const auto& airport : city.lock()->getAirports()){ + flights += airport.lock()->getAdj().size(); + } + } + return flights/cities; +} + +float Dataset::numberOfFlightsByAirline() { + int airlines = getAirlines().size(); + int flights = 0; + for(const auto& airport : getAirports()){ + flights += airport->getAdj().size(); + } + return flights/airlines; +} + +vector Dataset::searchDestinationsFromAirport(string airPortCode) { + AirportRef airport = getAirport(airPortCode); + vector flights; + if (airport.lock()) { + for (const auto& flight : airport.lock()->getAdj()){ + const AirportInfo& targetAirport = flight.getDest().lock()->getInfo(); + flights.push_back(targetAirport); + } + } + return flights; +} + +vector Dataset::searchTopNAirPortsWithGreatestTraffic(int n) { + vector airportTrafficList; + vector airportsList; + sort(airportTrafficList.begin(), airportTrafficList.end(), [](const AirportRef& a, const AirportRef& b) { + return a.lock()->getAdj().size() > b.lock()->getAdj().size(); + }); + for(int i = 0; i < n; i++){ + airportsList.push_back(airportTrafficList[i]); + } + return airportsList; +} + const AirlineSet& Dataset::getAirlines() const { return airlineSet_; } diff --git a/src/Flight.cpp b/src/Flight.cpp index 6d85ad4..c522eac 100644 --- a/src/Flight.cpp +++ b/src/Flight.cpp @@ -9,6 +9,7 @@ const AirlineRef &FlightInfo::getAirline() const { return airline_; } + double FlightInfo::getDistance() const { return distance_; } diff --git a/src/Program.cpp b/src/Program.cpp index 4b8dd8d..4acc53d 100644 --- a/src/Program.cpp +++ b/src/Program.cpp @@ -1,5 +1,7 @@ #include #include +#include +#include #include "Program.h" using namespace std; @@ -46,10 +48,102 @@ void Program::displayMainMenu() { case Option::EXIT: leave(); return; + case Option::SEARCH: + searchMenu(); + break; + case Option::STATISTICS: + statisticsMenu(); + break; + case Option::BEST_FLIGHT: + break; } } } +void Program::searchMenu() { + static const int NUM_OPTIONS = 14; + enum Option { + SEARCH_ALL_COUNTRIES = 1, + SEARCH_ALL_AIRPORTS = 2, + SEARCH_ALL_AIRLINES = 3, + SEARCH_AIRLINES_BY_COUNTRY = 4, + SEARCH_CITIES_IN_COUNTRY = 5, + SEARCH_AIRPORTS_IN_CITY = 6, + SEARCH_FLIGHTS_FROM_AIRPORT = 7, + SEARCH_COUNTRIES_FLYING_TO_AIRPORT = 8, + SEARCH_COUNTRIES_FLYING_TO_CITY = 9, + SEARCH_DESTINATIONS_FROM_AIRPORT = 10, + SEARCH_REACHABLE_DESTINATIONS_FROM_AIRPORT_IN_N_STOPS = 11, + SEARCH_MAXIMUM_TRIP = 12, + SEARCH_TOP_N_AIRPORTS_WITH_GREATEST_TRAFFIC = 13, + SEARCH_AIRPORTS_ESSENTIAL_TO_NETWORK_CIRCULATION = 14 + }; + cout << "\n" + " ┌─ Search ────────────────────────────────────────────────────────────────────┐\n" + " │ │\n" + " │ Options: │\n" + " │ [1] Search all countries │\n" + " │ [2] Search all airports │\n" + " │ [3] Search all airlines │\n" + " │ [4] Search airlines by country │\n" + " │ [5] Search cities in country │\n" + " │ [6] Search airports in city │\n" + " │ [7] Search flights from airport │\n" + " │ [8] Search countries flying to airport │\n" + " │ [9] Search countries flying to city │\n" + " │ [10] Search destinations from airport │\n" + " │ [11] Search reachable destinations from airport in n stops │\n" + " │ [12] Search maximum trip │\n" + " │ [13] Search top n airports with greatest traffic │\n" + " │ [14] Search airports essential to network circulation │\n" + " │ │\n" + " └─────────────────────────────────────────────────────────────────────────────┘\n" + "\n"; + switch(receiveOption(NUM_OPTIONS)){ + case Option::SEARCH_ALL_COUNTRIES: + displayAllCountries(); + break; + case Option::SEARCH_ALL_AIRPORTS: + displayAllAirports(); + break; + case Option::SEARCH_ALL_AIRLINES: + displayAllAirlines(); + break; + case Option::SEARCH_AIRLINES_BY_COUNTRY: + displayAirlinesByCountry(); + break; + case Option::SEARCH_CITIES_IN_COUNTRY: + displayCitiesByCountry(); + break; + case Option::SEARCH_AIRPORTS_IN_CITY: + displayAirportsByCity(); + break; + case Option::SEARCH_FLIGHTS_FROM_AIRPORT: + displayFlightsFromAirport(); + break; + case Option::SEARCH_COUNTRIES_FLYING_TO_AIRPORT: + displayCountriesFlyingToAirport(); + break; + case Option::SEARCH_COUNTRIES_FLYING_TO_CITY: + displayCountriesFlyingToCity(); + break; + case Option::SEARCH_DESTINATIONS_FROM_AIRPORT: + break; + case Option::SEARCH_REACHABLE_DESTINATIONS_FROM_AIRPORT_IN_N_STOPS: + break; + case Option::SEARCH_MAXIMUM_TRIP: + break; + case Option::SEARCH_TOP_N_AIRPORTS_WITH_GREATEST_TRAFFIC: + break; + case Option::SEARCH_AIRPORTS_ESSENTIAL_TO_NETWORK_CIRCULATION: + break; + } +} + +void Program::statisticsMenu(){ + +} + void Program::clearScreen() { system("clear || cls"); } @@ -76,6 +170,654 @@ void Program::leave() { waitForEnter(); } +void Program::displayAllCountries() { + static const int RESULTS_PER_PAGE = 10; + enum Option { + NEXT_PAGE = 1, + PREVIOUS_PAGE = 2, + GO_BACK = 3, + }; + int page = 1; + int total_pages = ceil((double) dataset_.getCountries().size() / RESULTS_PER_PAGE); + while (true) { + clearScreen(); + cout << "\n" + " ┌─ Search results ──────────────────────────────────────────────────────────────────────┐\n" + " │ │\n"; + + int count = 0; + for (auto it = dataset_.getCountries().begin(); it != dataset_.getCountries().end(); ++it) { + if (count >= (page - 1) * RESULTS_PER_PAGE && count < page * RESULTS_PER_PAGE) { + cout << " │ " << left << setw(85) << (*it)->getName() << "│\n"; + } + ++count; + } + + + cout << " │ │\n" + " │ Page " << setw(80) << to_string(page) + " of " + to_string(total_pages) << "│\n"; + if (page < total_pages) + cout << " │ [1] Next page │\n"; + + if (page > 1) + cout << " │ [2] Previous page │\n"; + + cout << " │ [3] Go back │\n" + " │ │\n" + " └───────────────────────────────────────────────────────────────────────────────────────┘\n\n"; + + + int option; + cout << "Please choose an option: "; + bool valid_option = false; + while (true) { + if (!(cin >> option)) { + cin.clear(); + cin.ignore(numeric_limits::max(), '\n'); + cout << "Invalid option. Please choose another option: "; + continue; + } + + switch (option) { + case Option::NEXT_PAGE: + if (page < total_pages) { + page++; + valid_option = true; + } else { + valid_option = false; + } + break; + case Option::PREVIOUS_PAGE: + if (page > 1) { + page--; + valid_option = true; + } else { + valid_option = false; + } + break; + case Option::GO_BACK: + displayMainMenu(); + return; + } + if (valid_option) + break; + cout << "Invalid option. Please choose another option: "; + } + } +} +void Program::displayAllAirports(){ + static const int RESULTS_PER_PAGE = 10; + enum Option { + NEXT_PAGE = 1, + PREVIOUS_PAGE = 2, + GO_BACK = 3, + }; + int page = 1; + int total_pages = ceil((double) dataset_.getAirports().size() / RESULTS_PER_PAGE); + while (true) { + clearScreen(); + cout << "\n" + " ┌─ Search results ──────────────────────────────────────────────────────────────────────┐\n" + " │ │\n"; + + int count = 0; + for (auto it = dataset_.getAirports().begin(); it != dataset_.getAirports().end(); ++it) { + if (count >= (page - 1) * RESULTS_PER_PAGE && count < page * RESULTS_PER_PAGE) { + cout << " │ " << left << setw(60) << "Name: " + (*it)->getInfo().getName() + << left << setw(25) << " Code: " + (*it)->getInfo().getCode() + << "│\n"; + } + ++count; + } + + cout << " │ │\n" + " │ Page " << setw(80) << to_string(page) + " of " + to_string(total_pages) << "│\n"; + if (page < total_pages) + cout << " │ [1] Next page │\n"; + + if (page > 1) + cout << " │ [2] Previous page │\n"; + + cout << " │ [3] Go back │\n" + " │ │\n" + " └───────────────────────────────────────────────────────────────────────────────────────┘\n\n"; + + + int option; + cout << "Please choose an option: "; + bool valid_option = false; + while (true) { + if (!(cin >> option)) { + cin.clear(); + cin.ignore(numeric_limits::max(), '\n'); + cout << "Invalid option. Please choose another option: "; + continue; + } + + switch (option) { + case Option::NEXT_PAGE: + if (page < total_pages) { + page++; + valid_option = true; + } else { + valid_option = false; + } + break; + case Option::PREVIOUS_PAGE: + if (page > 1) { + page--; + valid_option = true; + } else { + valid_option = false; + } + break; + case Option::GO_BACK: + displayMainMenu(); + return; + } + if (valid_option) + break; + cout << "Invalid option. Please choose another option: "; + } + + } +} +void Program::displayAllAirlines(){ + static const int RESULTS_PER_PAGE = 10; + enum Option { + NEXT_PAGE = 1, + PREVIOUS_PAGE = 2, + GO_BACK = 3, + }; + int page = 1; + int total_pages = ceil((double) dataset_.getAirlines().size() / RESULTS_PER_PAGE); + while (true) { + clearScreen(); + cout << "\n" + " ┌─ Search results ─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐\n" + " │ │\n"; + + int count = 0; + for (auto it = dataset_.getAirlines().begin(); it != dataset_.getAirlines().end(); ++it) { + if (count >= (page - 1) * RESULTS_PER_PAGE && count < page * RESULTS_PER_PAGE) { + cout << " │ " << left << setw(49) << "Name: " + (*it).lock()->getName() + << left << setw(12) << " Code: " + (*it).lock()->getCode()<< left <getCallsign() + <getCountry().lock()->getName() + << "│\n"; + } + ++count; + } + + cout << " │ │\n" + " │ Page " << setw(143) << to_string(page) + " of " + to_string(total_pages) << "│\n"; + if (page < total_pages) + cout << " │ [1] Next page │\n"; + + if (page > 1) + cout << " │ [2] Previous page │\n"; + + cout << " │ [3] Go back │\n" + " │ │\n" + " └──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘\n\n"; + + + int option; + cout << "Please choose an option: "; + bool valid_option = false; + while (true) { + if (!(cin >> option)) { + cin.clear(); + cin.ignore(numeric_limits::max(), '\n'); + cout << "Invalid option. Please choose another option: "; + continue; + } + + switch (option) { + case Option::NEXT_PAGE: + if (page < total_pages) { + page++; + valid_option = true; + } else { + valid_option = false; + } + break; + case Option::PREVIOUS_PAGE: + if (page > 1) { + page--; + valid_option = true; + } else { + valid_option = false; + } + break; + case Option::GO_BACK: + displayMainMenu(); + return; + } + if (valid_option) + break; + cout << "Invalid option. Please choose another option: "; + } + + } + +} +void Program::displayAirlinesByCountry(){ + static const int RESULTS_PER_PAGE = 10; + CountryRef country = receiveCountry(); + if(country.expired()) + return; + vector airlines = dataset_.getAirlinesFromCountry(*country.lock()); + enum Option { + NEXT_PAGE = 1, + PREVIOUS_PAGE = 2, + GO_BACK = 3, + }; + int page = 1; + int total_pages = ceil((double) dataset_.getAirlines().size() / RESULTS_PER_PAGE); + while (true) { + clearScreen(); + cout << "\n" + " ┌─ Search results ─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐\n" + " │ │\n"; + for(auto it = airlines.begin(); it != airlines.end(); ++it){ + cout << " │ " << left << setw(49) << "Name: " + (*it).lock()->getName() + << left << setw(12) << " Code: " + (*it).lock()->getCode()<< left <getCallsign() + <getCountry().lock()->getName() + << "│\n"; + } + cout << " │ │\n" + " │ Page " << setw(143) << to_string(page) + " of " + to_string(total_pages) << "│\n"; + if (page < total_pages) + cout << " │ [1] Next page │\n"; + + if (page > 1) + cout << " │ [2] Previous page │\n"; + + cout << " │ [3] Go back │\n" + " │ │\n" + " └──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘\n\n"; + + + int option; + cout << "Please choose an option: "; + bool valid_option = false; + while (true) { + if (!(cin >> option)) { + cin.clear(); + cin.ignore(numeric_limits::max(), '\n'); + cout << "Invalid option. Please choose another option: "; + continue; + } + + switch (option) { + case Option::NEXT_PAGE: + if (page < total_pages) { + page++; + valid_option = true; + } else { + valid_option = false; + } + break; + case Option::PREVIOUS_PAGE: + if (page > 1) { + page--; + valid_option = true; + } else { + valid_option = false; + } + break; + case Option::GO_BACK: + displayMainMenu(); + return; + } + if (valid_option) + break; + cout << "Invalid option. Please choose another option: "; + } + + } + +} +void Program::displayCitiesByCountry() { + CountryRef country = receiveCountry(); + if(country.expired()) + return; + vector cities = dataset_.getCitiesFromCountry(*country.lock()); + while (true) { + clearScreen(); + cout << "\n" + " ┌─ Search results ──────────────────────────────────────────────────────────────────────┐\n" + " │ │\n"; + for(const auto& city : cities){ + cout << " │ " << left << setw(85) << city.lock()->getName() << "│\n"; + } + cout << " │ │\n" + " └───────────────────────────────────────────────────────────────────────────────────────┘\n\n"; + waitForEnter(); + displayMainMenu(); + } +} + +void Program::displayAirportsByCity() { + static const int RESULTS_PER_PAGE = 10; + CityRef city = receiveCity(); + if(city.expired()) + return; + vector airports = dataset_.getAirportsFromCity(*city.lock()); + enum Option { + NEXT_PAGE = 1, + PREVIOUS_PAGE = 2, + GO_BACK = 3, + }; + int page = 1; + int total_pages = ceil((double) dataset_.getAirlines().size() / RESULTS_PER_PAGE); + while (true) { + clearScreen(); + cout << "\n" + " ┌─ Search results ──────────────────────────────────────────────────────────────────────┐\n" + " │ │\n"; + + int count = 0; + for (auto it = airports.begin(); it != airports.end(); ++it) { + if (count >= (page - 1) * RESULTS_PER_PAGE && count < page * RESULTS_PER_PAGE) { + cout << " │ " << left << setw(60) << "Name: " + (*it).lock()->getInfo().getName() + << left << setw(25) << " Code: " + (*it).lock()->getInfo().getCode() + << "│\n"; + } + ++count; + } + + cout << " │ │\n" + " │ Page " << setw(80) << to_string(page) + " of " + to_string(total_pages) << "│\n"; + if (page < total_pages) + cout << " │ [1] Next page │\n"; + + if (page > 1) + cout << " │ [2] Previous page │\n"; + + cout << " │ [3] Go back │\n" + " │ │\n" + " └───────────────────────────────────────────────────────────────────────────────────────┘\n\n"; + + + int option; + cout << "Please choose an option: "; + bool valid_option = false; + while (true) { + if (!(cin >> option)) { + cin.clear(); + cin.ignore(numeric_limits::max(), '\n'); + cout << "Invalid option. Please choose another option: "; + continue; + } + + switch (option) { + case Option::NEXT_PAGE: + if (page < total_pages) { + page++; + valid_option = true; + } else { + valid_option = false; + } + break; + case Option::PREVIOUS_PAGE: + if (page > 1) { + page--; + valid_option = true; + } else { + valid_option = false; + } + break; + case Option::GO_BACK: + displayMainMenu(); + return; + } + if (valid_option) + break; + cout << "Invalid option. Please choose another option: "; + } + + } + +} + +void Program::displayFlightsFromAirport() { + static const int RESULTS_PER_PAGE = 10; + AirportRef airport = receiveAirportByCode(); + if(airport.expired()) + return; + vector flights = dataset_.searchFlightsFromAirport(airport.lock()->getInfo().getCode()); + enum Option { + NEXT_PAGE = 1, + PREVIOUS_PAGE = 2, + GO_BACK = 3, + }; + int page = 1; + int total_pages = ceil((double) dataset_.getAirlines().size() / RESULTS_PER_PAGE); + while (true) { + clearScreen(); + cout << "\n" + " ┌─ Search results ──────────────────────────────────────────────────────────────────────────────────────────────────────────────┐\n" + " │ │\n"; + + int count = 0; + for (auto it = flights.begin(); it != flights.end(); ++it) { + if (count >= (page - 1) * RESULTS_PER_PAGE && count < page * RESULTS_PER_PAGE) { + cout << " │ " << left << setw(55) << "Destination: " + (*it).getDest().lock()->getInfo().getName() + << left << setw(15) << " Code: " + (*it).getDest().lock()->getInfo().getCode() << left << setw(55) << " Airline: " + (*it).getInfo().getAirline().lock()->getName() + << "│\n"; + } + ++count; + } + + cout << " │ │\n" + " │ Page " << setw(120) << to_string(page) + " of " + to_string(total_pages) << "│\n"; + if (page < total_pages) + cout << " │ [1] Next page │\n"; + + if (page > 1) + cout << " │ [2] Previous page │\n"; + + cout << " │ [3] Go back │\n" + " │ │\n" + " └───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘\n\n"; + int option; + cout << "Please choose an option: "; + bool valid_option = false; + while (true) { + if (!(cin >> option)) { + cin.clear(); + cin.ignore(numeric_limits::max(), '\n'); + cout << "Invalid option. Please choose another option: "; + continue; + } + + switch (option) { + case Option::NEXT_PAGE: + if (page < total_pages) { + page++; + valid_option = true; + } else { + valid_option = false; + } + break; + case Option::PREVIOUS_PAGE: + if (page > 1) { + page--; + valid_option = true; + } else { + valid_option = false; + } + break; + case Option::GO_BACK: + displayMainMenu(); + return; + } + if (valid_option) + break; + cout << "Invalid option. Please choose another option: "; + } + + } +} + +void Program::displayCountriesFlyingToAirport() { + static const int RESULTS_PER_PAGE = 10; + AirportRef airport = receiveAirportByCode(); + if(airport.expired()) + return; + vector countries = dataset_.getCountriesAirportFliesTo(*airport.lock()); + enum Option { + NEXT_PAGE = 1, + PREVIOUS_PAGE = 2, + GO_BACK = 3, + }; + int page = 1; + int total_pages = ceil((double) countries.size() / RESULTS_PER_PAGE); + while (true) { + clearScreen(); + cout << "\n" + " ┌─ Search results ──────────────────────────────────────────────────────────────────────┐\n" + " │ │\n"; + + int count = 0; + for (auto it = countries.begin(); it != countries.end(); ++it) { + if (count >= (page - 1) * RESULTS_PER_PAGE && count < page * RESULTS_PER_PAGE) { + cout << " │ " << left << setw(85) << (*it).lock()->getName() << "│\n"; + } + ++count; + } + + + cout << " │ │\n" + " │ Page " << setw(80) << to_string(page) + " of " + to_string(total_pages) << "│\n"; + if (page < total_pages) + cout << " │ [1] Next page │\n"; + + if (page > 1) + cout << " │ [2] Previous page │\n"; + + cout << " │ [3] Go back │\n" + " │ │\n" + " └───────────────────────────────────────────────────────────────────────────────────────┘\n\n"; + + + int option; + cout << "Please choose an option: "; + bool valid_option = false; + while (true) { + if (!(cin >> option)) { + cin.clear(); + cin.ignore(numeric_limits::max(), '\n'); + cout << "Invalid option. Please choose another option: "; + continue; + } + + switch (option) { + case Option::NEXT_PAGE: + if (page < total_pages) { + page++; + valid_option = true; + } else { + valid_option = false; + } + break; + case Option::PREVIOUS_PAGE: + if (page > 1) { + page--; + valid_option = true; + } else { + valid_option = false; + } + break; + case Option::GO_BACK: + displayMainMenu(); + return; + } + if (valid_option) + break; + cout << "Invalid option. Please choose another option: "; + } + } +} +void Program::displayCountriesFlyingToCity() { +static const int RESULTS_PER_PAGE = 10; + CityRef city = receiveCity(); + if(city.expired()) + return; + vector countries = dataset_.getCountriesCityFliesTo(*city.lock()); + enum Option { + NEXT_PAGE = 1, + PREVIOUS_PAGE = 2, + GO_BACK = 3, + }; + int page = 1; + int total_pages = ceil((double) countries.size() / RESULTS_PER_PAGE); + while (true) { + clearScreen(); + cout << "\n" + " ┌─ Search results ──────────────────────────────────────────────────────────────────────┐\n" + " │ │\n"; + + int count = 0; + for (auto it = countries.begin(); it != countries.end(); ++it) { + if (count >= (page - 1) * RESULTS_PER_PAGE && count < page * RESULTS_PER_PAGE) { + cout << " │ " << left << setw(85) << (*it).lock()->getName() << "│\n"; + } + ++count; + } + cout << " │ │\n" + " │ Page " << setw(80) << to_string(page) + " of " + to_string(total_pages) << "│\n"; + if (page < total_pages) + cout << " │ [1] Next page │\n"; + + if (page > 1) + cout << " │ [2] Previous page │\n"; + + cout << " │ [3] Go back │\n" + " │ │\n" + " └───────────────────────────────────────────────────────────────────────────────────────┘\n\n"; + + + int option; + cout << "Please choose an option: "; + bool valid_option = false; + while (true) { + if (!(cin >> option)) { + cin.clear(); + cin.ignore(numeric_limits::max(), '\n'); + cout << "Invalid option. Please choose another option: "; + continue; + } + + switch (option) { + case Option::NEXT_PAGE: + if (page < total_pages) { + page++; + valid_option = true; + } else { + valid_option = false; + } + break; + case Option::PREVIOUS_PAGE: + if (page > 1) { + page--; + valid_option = true; + } else { + valid_option = false; + } + break; + case Option::GO_BACK: + displayMainMenu(); + return; + } + if (valid_option) + break; + cout << "Invalid option. Please choose another option: "; + } + } +} + CountryRef Program::receiveCountry() const { string name; cout << "Please enter the country's name: "; @@ -152,3 +894,6 @@ AirportRef Program::receiveAirportByName() const { waitForEnter(); return {}; } + + + diff --git a/test/tests.cpp b/test/tests.cpp index 6761292..9e9e107 100644 --- a/test/tests.cpp +++ b/test/tests.cpp @@ -1,6 +1,7 @@ #include #include #include "Dataset.h" +#include "Program.h" using namespace std; @@ -36,26 +37,28 @@ TEST(FileParseTestSuite, ReadFilesTest) { EXPECT_EQ(444, dataset.getAirlines().size()); AirlineRef americanAirlines = dataset.getAirline("AAL"); - EXPECT_EQ(americanAirlines.lock()->getName(),"American Airlines"); - EXPECT_EQ(americanAirlines.lock()->getCountry().lock()->getName(),"United States"); - EXPECT_EQ(americanAirlines.lock()->getCallsign(),"AMERICAN"); + EXPECT_EQ(americanAirlines.lock()->getName(), "American Airlines"); + EXPECT_EQ(americanAirlines.lock()->getCountry().lock()->getName(), "United States"); + EXPECT_EQ(americanAirlines.lock()->getCallsign(), "AMERICAN"); AirlineRef airEuropa = dataset.getAirline("AEA"); - EXPECT_EQ(airEuropa.lock()->getName(),"Air Europa"); - EXPECT_EQ(airEuropa.lock()->getCountry().lock()->getName(),"Spain"); - EXPECT_EQ(airEuropa.lock()->getCallsign(),"EUROPA"); + EXPECT_EQ(airEuropa.lock()->getName(), "Air Europa"); + EXPECT_EQ(airEuropa.lock()->getCountry().lock()->getName(), "Spain"); + EXPECT_EQ(airEuropa.lock()->getCallsign(), "EUROPA"); AirlineRef airCaraibes = dataset.getAirline("FWI"); - EXPECT_EQ(airCaraibes.lock()->getName(),"Air Caraibes"); - EXPECT_EQ(airCaraibes.lock()->getCountry().lock()->getName(),"France"); - EXPECT_EQ(airCaraibes.lock()->getCallsign(),"FRENCH WEST"); + EXPECT_EQ(airCaraibes.lock()->getName(), "Air Caraibes"); + EXPECT_EQ(airCaraibes.lock()->getCountry().lock()->getName(), "France"); + EXPECT_EQ(airCaraibes.lock()->getCallsign(), "FRENCH WEST"); int total = 0; for (auto &v: dataset.getNetwork().getVertexSet()) - total += (int)v->getAdj().size(); + total += (int) v->getAdj().size(); EXPECT_EQ(63832, total); AirportRef JFKAirport = dataset.getAirport("JFK"); vector flights = JFKAirport.lock()->getAdj(); - auto specific_flight = find_if(flights.begin(), flights.end(), [](const Flight& f) { return f.getDest().lock()->getInfo().getCode() == "FRA" && f.getInfo().getAirline().lock()->getCode() == "ETH"; }); + auto specific_flight = find_if(flights.begin(), flights.end(), [](const Flight &f) { + return f.getDest().lock()->getInfo().getCode() == "FRA" && f.getInfo().getAirline().lock()->getCode() == "ETH"; + }); EXPECT_NE(specific_flight, flights.end()); AirportRef SCKAirport = dataset.getAirport("SCK");