Advertisement
riggnaros

restaurant finder structured array

Nov 21st, 2017
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 9.95 KB | None | 0 0
  1. #include <iostream>
  2. #include <iomanip>
  3. #include <fstream>
  4. #include <string>
  5.  
  6. using namespace std;
  7.  
  8. struct restaurantListings {
  9.     string restName;
  10.     string cuisine;
  11.     string priceRange;
  12.     int starRating;
  13. };
  14.  
  15. void showMenu(restaurantListings listings[]);
  16. void readData(restaurantListings listings[]);
  17. void nameResults(restaurantListings listings[]);
  18. void cuisineResults(restaurantListings listings[]);
  19. void priceRangeResults(restaurantListings listings[]);
  20. void starRatingResults(restaurantListings listings[]);
  21. void showAllListings(restaurantListings listings[]);
  22.  
  23. int main()
  24. {
  25.     restaurantListings listings[10];
  26.  
  27.     readData(listings);
  28.     showMenu(listings);
  29.  
  30.     return 0;
  31. }
  32.  
  33. void readData(restaurantListings listings[])
  34. {
  35.  
  36.     ifstream infile;
  37.     infile.open("restaurantData.txt");
  38.  
  39.     for (int i = 0; i < 10; i++) {
  40.         getline(infile, listings[i].restName);
  41.         getline(infile, listings[i].cuisine);
  42.         getline(infile, listings[i].priceRange);
  43.         infile >> listings[i].starRating;
  44.  
  45.         //if (infile.peek() == '\n')
  46.  
  47.         infile.ignore();
  48.     }
  49.     infile.close();
  50. };
  51.  
  52. void showMenu(restaurantListings listings[])
  53. {
  54.     int mainMenuSelection = 0;
  55.  
  56.     cout << "Welcome to the Restaurant Finder!";
  57.     cout << "\nDisplayed as: (Name / Cuisine / Price / 5-Star Rating)";
  58.     cout << "\n1. Search by Restaurant Name.";
  59.     cout << "\n2. Search by Cuisine Type.";
  60.     cout << "\n3. Search by Price Range (High/Medium/Low).";
  61.     cout << "\n4. Search by Star Rating (1-5).";
  62.     cout << "\n5. Show all Restaurant Listings.";
  63.     cout << endl;
  64.     cout << endl;
  65.  
  66.     cout << "Please enter your selection: ";
  67.     cin >> mainMenuSelection;
  68.     cout << endl;
  69.  
  70.     if (mainMenuSelection == 1) {
  71.         nameResults(listings);
  72.     }
  73.     else if (mainMenuSelection == 2) {
  74.         cuisineResults(listings);
  75.     }
  76.     else if (mainMenuSelection == 3) {
  77.         priceRangeResults(listings);
  78.     }
  79.     else if (mainMenuSelection == 4) {
  80.         starRatingResults(listings);
  81.     }
  82.     else if (mainMenuSelection == 5) {
  83.         showAllListings(listings);
  84.     }
  85.     else if (mainMenuSelection != 1 && mainMenuSelection != 2 && mainMenuSelection != 3 && mainMenuSelection != 4 && mainMenuSelection != 5) {
  86.         cout << "Please input a number selection of 1-5.";
  87.         cout << endl;
  88.         showMenu(listings);
  89.     }
  90. };
  91.  
  92. void nameResults(restaurantListings listings[])
  93. {
  94.     string listedName;
  95.     string answer;
  96.  
  97.     cout << "Please enter the name of the restaurant you would like to find information on: ";
  98.     cin.ignore();
  99.     getline(cin, listedName);
  100.     cout << endl;
  101.  
  102.     for (int i = 0; i < 10; i++) {
  103.        
  104.  
  105.  
  106.         if (listedName == listings[i].restName) {
  107.             cout << "\nHere is your restaurant information: ";
  108.             cout << listings[i].restName << ' ' << listings[i].cuisine << ' ' << listings[i].priceRange << ' ' << listings[i].starRating << endl;
  109.         }
  110.     }
  111.    
  112.     cout << "Would you like to make another selection?: ";
  113.     cin >> answer;
  114.         cout << endl;
  115.  
  116.  
  117.     if (answer == "Yes" || answer == "yes") {
  118.         showMenu(listings);
  119.     }
  120.     else if (answer == "No" || answer == "no") {
  121.         cout << "\nThank you and have a wonderful day!";
  122.         cout << "\nGoodbye.";
  123.     }
  124. };
  125.  
  126. void cuisineResults(restaurantListings listings[])
  127. {
  128.     string cuisineSelection;
  129.     string answer;
  130.  
  131.     cout << "\nPlease pick from the following Cuisine Types: ";
  132.     cout << "\n Southern";
  133.     cout << "\n Italian";
  134.     cout << "\n Asian";
  135.     cout << "\n Traditional";
  136.     cout << "\n German";
  137.     cout << "\n American";
  138.     cout << "\n Mexican";
  139.     cout << endl;
  140.     cout << endl;
  141.  
  142.     cin >> cuisineSelection;
  143.     cout << endl;
  144.  
  145.     for (int i = 0; i < 10; i++) {
  146.  
  147.         if ((cuisineSelection == "Southern" || cuisineSelection == "southern") && listings[i].cuisine == "Southern") {
  148.             cout << listings[i].restName << ' ' << listings[i].cuisine << ' ' << listings[i].priceRange << ' ' << listings[i].starRating << endl;
  149.         }
  150.         else if ((cuisineSelection == "Italian" || cuisineSelection == "italian") && listings[i].cuisine == "Italian") {
  151.             cout << listings[i].restName << ' ' << listings[i].cuisine << ' ' << listings[i].priceRange << ' ' << listings[i].starRating << endl;
  152.         }
  153.         else if ((cuisineSelection == "Asian" || cuisineSelection == "asian") && listings[i].cuisine == "Asian") {
  154.             cout << listings[i].restName << ' ' << listings[i].cuisine << ' ' << listings[i].priceRange << ' ' << listings[i].starRating << endl;
  155.         }
  156.         else if ((cuisineSelection == "Traditional" || cuisineSelection == "traditional") && listings[i].cuisine == "Traditional") {
  157.             cout << listings[i].restName << ' ' << listings[i].cuisine << ' ' << listings[i].priceRange << ' ' << listings[i].starRating << endl;
  158.         }
  159.         else if ((cuisineSelection == "German" || cuisineSelection == "german") && listings[i].cuisine == "German") {
  160.             cout << listings[i].restName << ' ' << listings[i].cuisine << ' ' << listings[i].priceRange << ' ' << listings[i].starRating << endl;
  161.         }
  162.         else if ((cuisineSelection == "American" || cuisineSelection == "american") && listings[i].cuisine == "American") {
  163.             cout << listings[i].restName << ' ' << listings[i].cuisine << ' ' << listings[i].priceRange << ' ' << listings[i].starRating << endl;
  164.         }
  165.         else if ((cuisineSelection == "Mexican" || cuisineSelection == "mexican") && listings[i].cuisine == "Mexican") {
  166.             cout << listings[i].restName << ' ' << listings[i].cuisine << ' ' << listings[i].priceRange << ' ' << listings[i].starRating << endl;
  167.         }
  168.     }
  169.     cout << "Would you like to make another selection?: ";
  170.     cin >> answer;
  171.         cout << endl;
  172.  
  173.  
  174.     if (answer == "Yes" || answer == "yes") {
  175.         cuisineResults(listings);
  176.     }
  177.     else if (answer == "No" || answer == "no") {
  178.         cout << "\nThank you and have a wonderful day!";
  179.         cout << "\nGoodbye.";
  180.     }
  181. };
  182.  
  183. void starRatingResults(restaurantListings listings[])
  184. {
  185.  
  186.     int starRatingSelection = 0;
  187.     string answer;
  188.  
  189.     cout << "\nPlease Enter the Star Rating you wish to search for (1-5): ";
  190.  
  191.     cin >> starRatingSelection;
  192.     cout << endl;
  193.  
  194.     for (int i = 0; i < 10; i++) {
  195.  
  196.         if (starRatingSelection == 1 && listings[i].starRating == 1) {
  197.             cout << listings[i].restName << ' ' << listings[i].cuisine << ' ' << listings[i].priceRange << ' ' << listings[i].starRating << endl;
  198.         }
  199.         else if (starRatingSelection == 2 && listings[i].starRating == 2) {
  200.             cout << listings[i].restName << ' ' << listings[i].cuisine << ' ' << listings[i].priceRange << ' ' << listings[i].starRating << endl;
  201.         }
  202.         else if (starRatingSelection == 3 && listings[i].starRating == 3) {
  203.             cout << listings[i].restName << ' ' << listings[i].cuisine << ' ' << listings[i].priceRange << ' ' << listings[i].starRating << endl;
  204.         }
  205.         else if (starRatingSelection == 4 && listings[i].starRating == 4) {
  206.             cout << listings[i].restName << ' ' << listings[i].cuisine << ' ' << listings[i].priceRange << ' ' << listings[i].starRating << endl;
  207.         }
  208.         else if (starRatingSelection == 5 && listings[i].starRating == 5) {
  209.             cout << listings[i].restName << ' ' << listings[i].cuisine << ' ' << listings[i].priceRange << ' ' << listings[i].starRating << endl;
  210.         }
  211.     }
  212.  
  213.     cout << "Would you like to make another selection?: ";
  214.     cin >> answer;
  215.         cout << endl;
  216.  
  217.     if (answer == "Yes" || answer == "yes") {
  218.         starRatingResults(listings);
  219.     }
  220.     else if (answer == "No" || answer == "no") {
  221.         cout << "\nThank you and have a wonderful day!";
  222.         cout << "\nGoodbye.";
  223.     }
  224. };
  225.  
  226. void priceRangeResults(restaurantListings listings[])
  227. {
  228.     string priceRangeSelection;
  229.     string answer;
  230.  
  231.     cout << "\nPlease Enter the Price Range you wish to search for (Low/Medium/High): ";
  232.  
  233.     cin >> priceRangeSelection;
  234.     cout << endl;
  235.  
  236.     for (int i = 0; i < 10; i++) {
  237.  
  238.         if ((priceRangeSelection == "Low" || priceRangeSelection == "low") && listings[i].priceRange == "Low") {
  239.             cout << listings[i].restName << ' ' << listings[i].cuisine << ' ' << listings[i].priceRange << ' ' << listings[i].starRating << endl;
  240.         }
  241.         else if ((priceRangeSelection == "Medium" || priceRangeSelection == "medium") && listings[i].priceRange == "Medium") {
  242.             cout << listings[i].restName << ' ' << listings[i].cuisine << ' ' << listings[i].priceRange << ' ' << listings[i].starRating << endl;
  243.         }
  244.         else if ((priceRangeSelection == "High" || priceRangeSelection == "high") && listings[i].priceRange == "High") {
  245.             cout << listings[i].restName << ' ' << listings[i].cuisine << ' ' << listings[i].priceRange << ' ' << listings[i].starRating << endl;
  246.         }
  247.     }
  248.     cout << "Would you like to make another selection?: ";
  249.     cin >> answer;
  250.         cout << endl;
  251.  
  252.     if (answer == "Yes" || answer == "yes") {
  253.         priceRangeResults(listings);
  254.     }
  255.     else if (answer == "No" || answer == "no") {
  256.         cout << "\nThank you and have a wonderful day!";
  257.         cout << "\nGoodbye.";
  258.     }
  259. };
  260.  
  261. void showAllListings(restaurantListings listings[])
  262. {
  263.     string answer;
  264.  
  265.     cout << "\n(Name / Cuisine / Price / 5-Star Rating)";
  266.     cout << endl;
  267.  
  268.  
  269.     for (int i = 0; i < 10; i++) {
  270.         cout << listings[i].restName << ' ' << listings[i].cuisine << ' ' << listings[i].priceRange << ' ' << listings[i].starRating << endl;
  271.     }
  272.        
  273.     cout << "Would you like to make another selection?: ";
  274.     cin >> answer;
  275.     cout << endl;
  276.     if (answer == "Yes" || answer == "yes") {
  277.         showMenu(listings);
  278.     }
  279.     else if (answer == "No" || answer == "no") {
  280.         cout << "\nThank you and have a wonderful day!";
  281.         cout << "\nGoodbye.";
  282.     }
  283. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement