1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221
|
#include "Driver.h"
#include "Flight.h"
;
using std::cout; using std::cin;
using std::endl; using std::string;
using std::vector; using std::map;
void updateRecord(outMap::const_iterator n, string& city);
std::string v; //has to be string value because m is also a selection, therefore cant be int
int succes = 0;
void Read()
{
std::ifstream infile("data.txt");
string info;
vector<string> temp;
while(getline(infile, info))
{
if(info == " ")
{
cout << "No data has been found \nGoing to Menu\n" << endl;
system("pause");
Menu();
}else{
succes = 1;
temp = split(info);
record.setRecord(temp[0], temp[1], temp[2], atoi(temp[3].c_str()), atoi(temp[4].c_str()));
Flights[record.getCountry()][record.getCity()] = record;
}
}
if(succes == 1)
{
cout << "Load was Succesful, Launching Menu" << endl;
system("pause");
system("cls");
}
}
void Menu()
{
cout << "#############################" << endl;
cout << "# Menu #" << endl;
cout << "#############################" << endl;
cout << "1) Display all records" << endl;
cout << "2) Display one record" << endl;
cout << "3) Add record" << endl;
cout << "4) Update record" << endl;
cout << "5) Delete record" << endl;
cout << "6) Save changes" << endl;
cout << "7) Calculate average age" << endl;
cout << "8) Calculate average weight" << endl;
cout << "0) Exit program" << endl;
cout << "\nOption: ";
cin.clear();
getline(cin, v);
if(EOF_test(v) == true)
{
system("cls");
Menu();
}
errorCheck(v);
}
void errorCheck(string& input)
{
if(input == "0")
{
Option(quit);
}
if(input == "m" || input == "M")
{
system("cls");
Menu();
}
try
{
option = atoi(input.c_str());
if(option == 0)
{
throw std::domain_error( "You have performed an illegal operation, Please try again. . ." );
}
}
catch(std::domain_error e){
system("CLS");
cout << e.what() << endl;
Menu();
}
Option(option);
}
void Option(int& o)
{
system("cls");
switch(o)
{
case 1:
cout << "Displaying all the records" << endl;
displayAll();
system("pause");
break;
case 2:
cout << "Displaying a Selective record" << endl;
displayOne();
break;
case 3:
cout << "Adding a flight record" << endl;
addRecord();
break;
default:
//in case a input does not match the options avalible
cout << "Not a valid option \nBack to main menu" << endl;
cout << "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" << endl;
//restarting the menu function
Menu();
}
}
void displayAll()
{
//create a size type to measure the size of the map
outMap::size_type count = 0;
//printing all of the data in the file
for(outMap::const_iterator itx = Flights.begin(); itx != Flights.end(); ++itx)
{
for(inMap::const_iterator ity = itx->second.begin(); ity != itx->second.end(); ++ity)
{
ity->second.display();
cout << endl;
count++;
}
}
cout << "Thats all the Flight Records." << endl;
//pausing the program for the user to read all the data that is showing
system("PAUSE");
system("cls");
//returnign to the menu
Menu();
}
void displayOne()
{
int x = 2;
//creating a size type to make sure that errors don't occur
outMap::size_type num_Flights = 0;
cout << "Please enter country, m: to go back to menu: ";
string search = " ";
//getting inputted data
getline(cin, search);
//making sure an EOF input wasn't inputted
if((EOF_test(search) == true)||(search.size() == 0)){
cout << "No entry \nPlease enter a country!";
cin.clear();
displayOne();
system("PAUSE");
system("CLS");
}
//calling the data but making sure it cannot be changed
outMap::const_iterator country;
inMap::const_iterator citySearch;
string city;
//searching the data for the inputted data
if(Flights.find(search) != Flights.end()){
system("CLS");
country = Flights.find(search);
cout << "~~~~~~~~~~~~~~~~~~~~~~~~~\n Flights Found! \n~~~~~~~~~~~~~~~~~~~~~~~~~" << endl;
//displaying the data that matches the inputted data
for (inMap::const_iterator ity = country->second.begin(); ity != country->second.end(); ++ity){
ity->second.display();
num_Flights++;
city = ity->first;
}
//if there is more then one person with the same country the program then asks for the city
//and searchs again this time with the city
if(num_Flights > 1){
cout << "\nThere is to many Flights with that country!"
<< "\nPlease enter city : ";
cin.clear();
getline(cin, search);
//making sure that there is data inputted and that an EOF wasn't inputted
while((EOF_test(search) == true)||(search.size() == 0)|| country->second.find(search) == country->second.end()){
cout << "Invalid option!" << endl;
cin.clear();
cout << "Please enter city :" ;
getline(cin, search);
}
if(country->second.find(search) != country->second.end()){
citySearch = country->second.find(search);
}
system("CLS");
//printing the requested data for the user to view
cout << "~~~~~~~~~~~~~~~\n Person found! \n~~~~~~~~~~~~~~~" << endl;
for (inMap::const_iterator ity = country->second.begin(); ity != country->second.end(); ++ity){
if(citySearch == ity){
ity->second.display();
city = ity->first;
}
}
}
}else if(search == "m"|| search == "M"){
system("CLS");
//returning to the menu
Menu();
}else{
//printing error when the search does not match
cout << "No such record exsists!\n";
//rerunning the program
displayOne();
}
//running the endtest function to check if the user wants to do the action again
system("pause");
}
|