Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <iomanip>
- #include <fstream>
- #include <string>
- using namespace std;
- struct restaurantListings {
- string restName;
- string cuisine;
- string priceRange;
- int starRating;
- };
- void showMenu(restaurantListings listings[]);
- void readData(restaurantListings listings[]);
- void nameResults(restaurantListings listings[]);
- void cuisineResults(restaurantListings listings[]);
- void priceRangeResults(restaurantListings listings[]);
- void starRatingResults(restaurantListings listings[]);
- void showAllListings(restaurantListings listings[]);
- int main()
- {
- restaurantListings listings[10];
- readData(listings);
- showMenu(listings);
- return 0;
- }
- void readData(restaurantListings listings[])
- {
- ifstream infile;
- infile.open("restaurantData.txt");
- for (int i = 0; i < 10; i++) {
- getline(infile, listings[i].restName);
- getline(infile, listings[i].cuisine);
- getline(infile, listings[i].priceRange);
- infile >> listings[i].starRating;
- //if (infile.peek() == '\n')
- infile.ignore();
- }
- infile.close();
- };
- void showMenu(restaurantListings listings[])
- {
- int mainMenuSelection = 0;
- cout << "Welcome to the Restaurant Finder!";
- cout << "\nDisplayed as: (Name / Cuisine / Price / 5-Star Rating)";
- cout << "\n1. Search by Restaurant Name.";
- cout << "\n2. Search by Cuisine Type.";
- cout << "\n3. Search by Price Range (High/Medium/Low).";
- cout << "\n4. Search by Star Rating (1-5).";
- cout << "\n5. Show all Restaurant Listings.";
- cout << endl;
- cout << endl;
- cout << "Please enter your selection: ";
- cin >> mainMenuSelection;
- cout << endl;
- if (mainMenuSelection == 1) {
- nameResults(listings);
- }
- else if (mainMenuSelection == 2) {
- cuisineResults(listings);
- }
- else if (mainMenuSelection == 3) {
- priceRangeResults(listings);
- }
- else if (mainMenuSelection == 4) {
- starRatingResults(listings);
- }
- else if (mainMenuSelection == 5) {
- showAllListings(listings);
- }
- else if (mainMenuSelection != 1 && mainMenuSelection != 2 && mainMenuSelection != 3 && mainMenuSelection != 4 && mainMenuSelection != 5) {
- cout << "Please input a number selection of 1-5.";
- cout << endl;
- showMenu(listings);
- }
- };
- void nameResults(restaurantListings listings[])
- {
- string listedName;
- string answer;
- cout << "Please enter the name of the restaurant you would like to find information on: ";
- cin.ignore();
- getline(cin, listedName);
- cout << endl;
- for (int i = 0; i < 10; i++) {
- if (listedName == listings[i].restName) {
- cout << "\nHere is your restaurant information: ";
- cout << listings[i].restName << ' ' << listings[i].cuisine << ' ' << listings[i].priceRange << ' ' << listings[i].starRating << endl;
- }
- }
- cout << "Would you like to make another selection?: ";
- cin >> answer;
- cout << endl;
- if (answer == "Yes" || answer == "yes") {
- showMenu(listings);
- }
- else if (answer == "No" || answer == "no") {
- cout << "\nThank you and have a wonderful day!";
- cout << "\nGoodbye.";
- }
- };
- void cuisineResults(restaurantListings listings[])
- {
- string cuisineSelection;
- string answer;
- cout << "\nPlease pick from the following Cuisine Types: ";
- cout << "\n Southern";
- cout << "\n Italian";
- cout << "\n Asian";
- cout << "\n Traditional";
- cout << "\n German";
- cout << "\n American";
- cout << "\n Mexican";
- cout << endl;
- cout << endl;
- cin >> cuisineSelection;
- cout << endl;
- for (int i = 0; i < 10; i++) {
- if ((cuisineSelection == "Southern" || cuisineSelection == "southern") && listings[i].cuisine == "Southern") {
- cout << listings[i].restName << ' ' << listings[i].cuisine << ' ' << listings[i].priceRange << ' ' << listings[i].starRating << endl;
- }
- else if ((cuisineSelection == "Italian" || cuisineSelection == "italian") && listings[i].cuisine == "Italian") {
- cout << listings[i].restName << ' ' << listings[i].cuisine << ' ' << listings[i].priceRange << ' ' << listings[i].starRating << endl;
- }
- else if ((cuisineSelection == "Asian" || cuisineSelection == "asian") && listings[i].cuisine == "Asian") {
- cout << listings[i].restName << ' ' << listings[i].cuisine << ' ' << listings[i].priceRange << ' ' << listings[i].starRating << endl;
- }
- else if ((cuisineSelection == "Traditional" || cuisineSelection == "traditional") && listings[i].cuisine == "Traditional") {
- cout << listings[i].restName << ' ' << listings[i].cuisine << ' ' << listings[i].priceRange << ' ' << listings[i].starRating << endl;
- }
- else if ((cuisineSelection == "German" || cuisineSelection == "german") && listings[i].cuisine == "German") {
- cout << listings[i].restName << ' ' << listings[i].cuisine << ' ' << listings[i].priceRange << ' ' << listings[i].starRating << endl;
- }
- else if ((cuisineSelection == "American" || cuisineSelection == "american") && listings[i].cuisine == "American") {
- cout << listings[i].restName << ' ' << listings[i].cuisine << ' ' << listings[i].priceRange << ' ' << listings[i].starRating << endl;
- }
- else if ((cuisineSelection == "Mexican" || cuisineSelection == "mexican") && listings[i].cuisine == "Mexican") {
- cout << listings[i].restName << ' ' << listings[i].cuisine << ' ' << listings[i].priceRange << ' ' << listings[i].starRating << endl;
- }
- }
- cout << "Would you like to make another selection?: ";
- cin >> answer;
- cout << endl;
- if (answer == "Yes" || answer == "yes") {
- cuisineResults(listings);
- }
- else if (answer == "No" || answer == "no") {
- cout << "\nThank you and have a wonderful day!";
- cout << "\nGoodbye.";
- }
- };
- void starRatingResults(restaurantListings listings[])
- {
- int starRatingSelection = 0;
- string answer;
- cout << "\nPlease Enter the Star Rating you wish to search for (1-5): ";
- cin >> starRatingSelection;
- cout << endl;
- for (int i = 0; i < 10; i++) {
- if (starRatingSelection == 1 && listings[i].starRating == 1) {
- cout << listings[i].restName << ' ' << listings[i].cuisine << ' ' << listings[i].priceRange << ' ' << listings[i].starRating << endl;
- }
- else if (starRatingSelection == 2 && listings[i].starRating == 2) {
- cout << listings[i].restName << ' ' << listings[i].cuisine << ' ' << listings[i].priceRange << ' ' << listings[i].starRating << endl;
- }
- else if (starRatingSelection == 3 && listings[i].starRating == 3) {
- cout << listings[i].restName << ' ' << listings[i].cuisine << ' ' << listings[i].priceRange << ' ' << listings[i].starRating << endl;
- }
- else if (starRatingSelection == 4 && listings[i].starRating == 4) {
- cout << listings[i].restName << ' ' << listings[i].cuisine << ' ' << listings[i].priceRange << ' ' << listings[i].starRating << endl;
- }
- else if (starRatingSelection == 5 && listings[i].starRating == 5) {
- cout << listings[i].restName << ' ' << listings[i].cuisine << ' ' << listings[i].priceRange << ' ' << listings[i].starRating << endl;
- }
- }
- cout << "Would you like to make another selection?: ";
- cin >> answer;
- cout << endl;
- if (answer == "Yes" || answer == "yes") {
- starRatingResults(listings);
- }
- else if (answer == "No" || answer == "no") {
- cout << "\nThank you and have a wonderful day!";
- cout << "\nGoodbye.";
- }
- };
- void priceRangeResults(restaurantListings listings[])
- {
- string priceRangeSelection;
- string answer;
- cout << "\nPlease Enter the Price Range you wish to search for (Low/Medium/High): ";
- cin >> priceRangeSelection;
- cout << endl;
- for (int i = 0; i < 10; i++) {
- if ((priceRangeSelection == "Low" || priceRangeSelection == "low") && listings[i].priceRange == "Low") {
- cout << listings[i].restName << ' ' << listings[i].cuisine << ' ' << listings[i].priceRange << ' ' << listings[i].starRating << endl;
- }
- else if ((priceRangeSelection == "Medium" || priceRangeSelection == "medium") && listings[i].priceRange == "Medium") {
- cout << listings[i].restName << ' ' << listings[i].cuisine << ' ' << listings[i].priceRange << ' ' << listings[i].starRating << endl;
- }
- else if ((priceRangeSelection == "High" || priceRangeSelection == "high") && listings[i].priceRange == "High") {
- cout << listings[i].restName << ' ' << listings[i].cuisine << ' ' << listings[i].priceRange << ' ' << listings[i].starRating << endl;
- }
- }
- cout << "Would you like to make another selection?: ";
- cin >> answer;
- cout << endl;
- if (answer == "Yes" || answer == "yes") {
- priceRangeResults(listings);
- }
- else if (answer == "No" || answer == "no") {
- cout << "\nThank you and have a wonderful day!";
- cout << "\nGoodbye.";
- }
- };
- void showAllListings(restaurantListings listings[])
- {
- string answer;
- cout << "\n(Name / Cuisine / Price / 5-Star Rating)";
- cout << endl;
- for (int i = 0; i < 10; i++) {
- cout << listings[i].restName << ' ' << listings[i].cuisine << ' ' << listings[i].priceRange << ' ' << listings[i].starRating << endl;
- }
- cout << "Would you like to make another selection?: ";
- cin >> answer;
- cout << endl;
- if (answer == "Yes" || answer == "yes") {
- showMenu(listings);
- }
- else if (answer == "No" || answer == "no") {
- cout << "\nThank you and have a wonderful day!";
- cout << "\nGoodbye.";
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement