#include #include #include //for class string using namespace std; //Data from the Wikipedia article: // https://en.wikipedia.org/wiki/Manhattan_address_algorithm int main() { struct avenue { string name; //of avenue int min; //a range of building numbers int max; int divisor; //Divide by this number, int addend; //then add this number to get the cross street. }; avenue a[] { {"Avenue A", 0, 9999, 20, 3}, {"Avenue B", 0, 9999, 20, 3}, {"Avenue C", 0, 9999, 20, 3}, {"Avenue D", 0, 9999, 20, 3}, {"1st Avenue", 0, 9999, 20, 3}, {"2nd Avenue", 0, 9999, 20, 3}, {"3rd Avenue", 0, 9999, 20, 10}, {"4th Avenue", 0, 9999, 20, 8}, {"5th Avenue", 63, 108, 20, 11}, {"5th Avenue", 109, 199, 20, 13}, {"5th Avenue", 200, 399, 20, 16}, {"5th Avenue", 400, 599, 20, 18}, {"5th Avenue", 600, 774, 20, 20}, {"5th Avenue", 775, 1286, 10, -18}, {"5th Avenue", 1287, 1499, 20, 45}, {"5th Avenue", 1500, 9999, 20, 24}, {"6th Avenue", 0, 9999, 20, -12}, //of the Americas {"7th Avenue", 1, 1800, 20, 12}, {"8th Avenue", 1801, 9999, 20, 9}, {"9th Avenue", 0, 9999, 20, 13}, {"10th Avenue", 0, 9999, 20, 14}, {"11th Avenue", 0, 9999, 20, 15}, {"Amsterdam Avenue", 0, 9999, 20, 59}, {"Audubon Avenue", 0, 9999, 20, 165}, {"Broadway", 756, 846, 20, -29}, {"Broadway", 847, 953, 20, -25}, {"Broadway", 954, 9999, 20, -31}, {"Central Park West", 0, 9999, 10, 60}, {"Columbus Avenue", 0, 9999, 20, 60}, {"Convent Avenue", 0, 9999, 20, 127}, {"East End Avenue", 0, 9999, 20, 79}, {"Edgecomb Avenue", 0, 9999, 20, 134}, {"Ft. Washington Avenue", 0, 9999, 20, 158}, {"Lenox Avenue", 0, 9999, 20, 110}, {"Madison Avenue", 0, 9999, 20, 27}, {"Manhattan Avenue", 0, 9999, 20, 100}, {"Park Avenue", 0, 9999, 20, 24}, {"Park Avenue South", 0, 9999, 20, 8}, {"Pleasant Avenue", 0, 9999, 20, 101}, {"Riverside Drive", 1, 567, 10, 72}, {"Riverside Drive", 568, 9999, 10, 78}, {"St. Nicholas Avenue", 0, 9999, 20, 110}, {"Vanderbilt Avenue", 0, 9999, 20, 42}, {"West End Avenue", 0, 9999, 20, 59}, {"York Avenue", 0, 9999, 20, 4} }; int n {size(a)}; //how many avenues, including Broadway & CentralParkWes //At what cross street is 100 5th Avenue? int no {100}; string ave {"5th Avenue"}; for (int i {0}; i < n; ++i) { if (ave == a[i].name && a[i].min <= no && no <= a[i].max) { int street {no / a[i].divisor + a[i].addend}; cout << street << " Street\n"; return EXIT_SUCCESS; } } cerr << "Sorry, could not find " << no << " " << ave << ".\n"; return EXIT_FAILURE; }