Question: #include #include #include #include functions.h using std::cout, std::cin, std::endl, std::exception, std::invalid _ argument; using std::getline, std::string; int mapping ( string loc ) { int

#include
#include
#include
#include "functions.h"
using std::cout, std::cin, std::endl, std::exception, std::invalid_argument;
using std::getline, std::string;
int mapping (string loc){
int num =0;
if (loc == "Boston") num =1;
else if (loc == "Hartford") num =2;
else if (loc == "NewYork") num =3;
else if (loc == "Philadelphia") num =4;
else if (loc == "Baltimore") num =5;
else if (loc == "WashingtonDC") num =6;
else if (loc == "Pittsburgh") num =7;
else if (loc == "Cleveland") num =8;
else if (loc == "Detroit") num =9;
else if (loc == "Chicago") num =10;
else if (loc == "Indianapolis") num =11;
else if (loc == "Nashville") num =12;
else if (loc == "Atlanta") num =13;
else if (loc == "Houston") num =14;
else if (loc == "Austin") num =15;
else if (loc == "Dallas") num =16;
else if (loc == "Denver") num =17;
else if (loc == "Albuquerque") num =18;
else if (loc == "Phoenix") num =19;
else if (loc == "Sacramento") num =20;
else {
try { throw invalid_argument("Undefined location"); }
catch (std::invalid_argument const& e){ cout << e.what()<< endl; }
}
return num;
}
string rev_mapping (int num){
string loc;
switch (num)
{
case 1: { loc = "Boston"; break; }
case 2: { loc = "Hartford"; break; }
case 3: { loc = "NewYork"; break; }
case 4: { loc = "Philadelphia"; break; }
case 5: { loc = "Baltimore"; break; }
case 6: { loc = "WashingtonDC"; break; }
case 7: { loc = "Pittsburgh"; break; }
case 8: { loc = "Cleveland"; break ; }
case 9: { loc = "Detroit"; break; }
case 10: { loc = "Chicago"; break; }
case 11: { loc = "Indianapolis"; break; }
case 12: { loc = "Nashville"; break; }
case 13: { loc = "Atlanta"; break; }
case 14: { loc = "Houston"; break; }
case 15: { loc = "Austin"; break; }
case 16: { loc = "Dallas"; break; }
case 17: { loc = "Denver"; break; }
case 18: { loc = "Albuquerque"; break; }
case 19: { loc = "Phoenix"; break; }
case 20: { loc = "Sacramento"; break; }
default: { loc = "undefined"; break;}
}
if (loc == "undefined"){
try { throw invalid_argument("Undefined location"); }
catch (std::invalid_argument const& e){ cout << e.what()<< endl; }
}
return loc;
}
void get_op(const string& line, string* operation){
std::istringstream sin(line);
sin >>*operation;
if (sin.fail()){
sin.clear();
sin.ignore(std::numeric_limits::max(),'
');
*operation = "ignore";
}
}
void get_loc(const string& line, string* location){
std::istringstream sin(line);
sin >>*location;
if (sin.fail()){
sin.clear();
sin.ignore(std::numeric_limits::max(),'
');
}
}
void print_inst_1(){
cout <<"*** enter operation: push | insert | pop | clear | print | locations | quit" << endl;
cout <<"*** enter location from above list on next line" << endl;
cout <<"*** enter an empty line to end input" << endl;
cout <<"***"<< endl;
cout <<"*** WARNING: push operation pushes location in push order without any location ordering" << endl;
cout <<"***"<< endl;
}
void print_inst_2(){
cout <<"*** Locations: Boston | Hartford | NewYork | Philadelphia | Baltimore | WashingtonDC | Pittsburgh | Cleveland | Detroit | Chicago |"<< endl;
cout <<"*** Indianapolis | Nashville | Atlanta | Houston | Dallas | Austin | Denver | Albuquerque | Phoenix | Sacramento" << endl;
cout <<"***.... you can repeat this list anytime at prompt by typing locations ...."<< endl;
cout <<"***"<< endl;
}
void print_inst_3(){
cout << endl;
cout << "next" << endl;
}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!