#include #include #include #include #include #include using namespace std; void printMenu(); void loadFile(vector & first, vector & last, vector & gender, vector & age, vector & camp, string filename); void showRefugees(vector, vector, vector, vector, vector); void showCamp(vector, vector, vector, vector, vector, string); char getMenu(); void nameSearch(vector, vector, vector, vector, vector, string, string); void childSearch(vector, vector, vector, vector, vector, int, char); int totalRefugees(vector); const string unknown = "UNK"; int main(){ vector first; vector last; vector gender; vector age; vector camp; char choice; bool finished = false; string filename; string campName; string firstName; string lastName; int searchAge; char searchGender; cout << fixed << setprecision(2); while (!finished){ choice = getMenu(); switch (choice){ case 'l': case 'L': cout << "Enter name of file to load: "; getline(cin, filename); loadFile(first, last, gender, age, camp, filename); break; case 'S': case 's': cout << "Enter the first name to search for: "; getline(cin, firstName); cout << "Enter the last name to search for: "; getline(cin, lastName); nameSearch(first, last, gender, age, camp, firstName, lastName); break; case 'A': case 'a': cout << "Enter the age to search for: "; cin >> searchAge; cout << "Enter the gender to search for (F/M): "; cin >> searchGender; childSearch(first, last, gender, age, camp, searchAge, searchGender); break; case 'C': case 'c': cout << "Enter the name of the camp to show: "; getline(cin, campName); showCamp(first, last, gender, age, camp, campName); break; case 'P': case 'p': showRefugees(first, last, gender, age, camp); break; case 'T': case 't': cout << "Total refugees: " << totalRefugees(last) << endl; break; case 'Q': case 'q': finished = true; break; default: cout << "Unknown menu selection." << endl; break; } } } char getMenu(){ char choice; cout << endl << endl; cout << setw(45) << "Add a camp list" << setw (10) << "L" << endl; cout << setw(45) << "Search for refugee by name" << setw(10) << "S" << endl; cout << setw(45) << "Search for child by age and gender" << setw (10) << "A" << endl; cout << setw(45) << "Show all refugees at a camp" << setw (10) << "C" << endl; cout << setw(45) << "Count of refugees" << setw (10) << "T" << endl; cout << setw(45) << "Print all refugees" << setw (10) << "P" << endl; cout << setw(45) << "Exit the program" << setw (10) << "Q" << endl; cout << endl; cout << "Please enter your choice: "; cin >> choice; cin.clear(); string trash; getline (cin,trash); return choice; cout << endl << endl; } void showRefugees(vector first, vector last, vector gender, vector age, vector camp){ for (int i = 0; i < first.size(); i++){ cout << setw(15) << first[i] << setw(15) << last[i] << setw(4) << gender[i] << setw(4) << age[i] << setw(15) << camp[i] << endl; } } void loadFile (vector & first, vector & last, vector & gender, vector & age, vector & camp, string filename){ string firstName; string lastName; char refugeeGender; int refugeeAge; string campName; ifstream refugeeFile; refugeeFile.open(filename.c_str()); if (!refugeeFile){ cout << "Unable to open file " << filename << endl; return; } int count = 0; string header; getline(refugeeFile, header); while (refugeeFile >> firstName >> lastName >> refugeeGender >> refugeeAge >> campName){ count++; first.push_back(firstName); last.push_back(lastName); gender.push_back(refugeeGender); age.push_back(refugeeAge); camp.push_back(campName); } cout << "Loaded " << count << " refugees" << endl; } void showCamp(vector first, vector last, vector gender, vector age, vector camp, string targetCamp){ for (int i = 0; i < first.size(); i++){ if (camp[i] == targetCamp){ cout << setw(15) << first[i] << setw(15) << last[i] << setw(4) << gender[i] << setw(4) << age[i] << setw(15) << camp[i] << endl; } } } void nameSearch(vector first, vector last, vector gender, vector age, vector camp, string firstName, string lastName){ // First look for exact matches: int matchCount = 0; cout << endl << endl << "Exact matches:" << endl; for (int i = 0; i < first.size(); i++){ if ((first[i] == firstName) && (last[i] == lastName)){ cout << setw(15) << first[i] << setw(15) << last[i] << setw(4) << gender[i] << setw(4) << age[i] << setw(15) << camp[i] << endl; matchCount++; } } if (matchCount == 0){ cout << "None" << endl; } matchCount = 0; cout << endl << endl << "Last name matches:" << endl; for (int i = 0; i < first.size(); i++){ if ((first[i] == unknown) && (last[i] == lastName)){ cout << setw(15) << first[i] << setw(15) << last[i] << setw(4) << gender[i] << setw(4) << age[i] << setw(15) << camp[i] << endl; matchCount++; } } if (matchCount == 0){ cout << "None" << endl; } matchCount = 0; cout << endl << endl << "First name matches:" << endl; for (int i = 0; i < first.size(); i++){ if ((first[i] == firstName) && (last[i] == unknown)){ cout << setw(15) << first[i] << setw(15) << last[i] << setw(4) << gender[i] << setw(4) << age[i] << setw(15) << camp[i] << endl; matchCount++; } } if (matchCount == 0){ cout << "None" << endl; } } void childSearch(vector first, vector last, vector gender, vector age, vector camp, int searchAge, char searchGender){ for (int i = 0; i < first.size(); i++){ if ((age[i] >= searchAge -1) && (age[i] <= searchAge + 1) && (searchGender == gender[i])){ cout << setw(15) << first[i] << setw(15) << last[i] << setw(4) << gender[i] << setw(4) << age[i] << setw(15) << camp[i] << endl; } } } int totalRefugees(vector whocares){ return whocares.size(); }