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
|
#include <algorithm>
#include <cctype>
#include <iostream>
#include <map>
#include <stdexcept>
#include <string>
int get_OU(std::string in)
{
static const std::map<std::string, int> OU {
{"wsl", 101}, {"ucb", 102}, {"ucs", 103}, {"wls", 104},
};
std::transform(in.begin(), in.end(), in.begin(), ::tolower);
{
auto it = OU.find(in);
if(it != OU.end())
return it->second;
}
if(all_of(in.begin(), in.end(), ::isdigit))
return std::stoi(in);
throw std::invalid_argument("Bad OU string");
}
int get_area(std::string in)
{
static const std::map<std::string, int> area {
{"texas", 1}, {"denver", 1}, {"midland", 1}, {"dallas", 1}, {"houston", 1},
{"oklahoma", 2}, {"kansas", 2},
};
std::transform(in.begin(), in.end(), in.begin(), ::tolower);
{
auto it = area.find(in);
if(it != area.end())
return it->second;
}
if(all_of(in.begin(), in.end(), ::isdigit))
return std::stoi(in);
throw std::invalid_argument("Bad AREA string");
}
int main()
{
try {
std::string temp;
std::cout << "Please enter the ticket OU:\n";
std::cin >> temp;
int ou = get_OU(std::move(temp));
std::cout << "\nPlease enter the city the ticket originates from:\n";
std::cin >> temp;
int area = get_area(std::move(temp));
std::cout << "\n\n";
if (ou == 101 && area == 1 ) {
std::cout << "Your tech is Michael McDonald.\n";
} else if (ou == 102 && area == 1) {
std::cout << "Your tech is Michael McDonald.\n";
} else if (ou == 103 && area == 1) {
std::cout << "Your tech is Michael McDonald.\n";
} else if (ou == 104 && area == 1) {
std::cout << "Your tech is Michael McDonald.\n";
}
} catch(std::exception& e) {
std::cerr << e.what();
return EXIT_FAILURE;
}
}
|
Please enter the ticket OU:
WSL
Please enter the city the ticket originates from:
DenVEr
Your tech is Michael McDonald. |