Question

In: Computer Science

In C++, develop a menu program which reads in data from 4 different input files -...

In C++, develop a menu program which reads in data from 4 different input files - appetizers, entrees, desserts, and drinks. Then, record the item information ordered by the customer for each item selected. When finished, display all items ordered to the screen with the subtotal, tax (10% for easy math), and the total. Be sure to get tip as well. Then, ensure enough payment was received before generating an output file receipt which can be printed off. Use functions to prevent redudant code.

  • You are free to use arrays or vectors to store program data. Your choice!
  • The input files can have different numbers of items available. Example: You have may have 5 appetizers, 10 entrees, 8 drinks and 4 desserts. The numbers are up to you. But, the program should be able to handle input files with "unknown numbers" of items for sale.
  • Make the interface and output look nice! Software is something that you want to sell to others. If it looks bad, no one will buy it. Think about the last app you downloaded that didn't look good when you used it. Do you still have it on your phone? Probably not.
  • Your program must not have redundant code! Use functions and/or generic functions where possible to remove all redundant code in your program.

Solutions

Expert Solution

program developed with user friendly interface

(code to copy)

#include<bits/stdc++.h>
using namespace std;

class Order{
    public:
    vector<pair<string, float>> itemsOrdered;
    vector<string> filenames;
    Order(vector<string> fileNames){
        filenames=fileNames;
    }
    int menuSelection(){
        cout<<"-------------Menu-------------"<<endl;
        cout<<"1. Entrees"<<endl;
        cout<<"2. Drinks"<<endl;
        cout<<"3. Appetizers"<<endl;
        cout<<"4. Desserts"<<endl;
        cout<<"0. Nothing, I am done!"<<endl;
        cout<<"What do you want to have?"<<endl;
        int option;
        cin>>option;
        return option;
    }
    void itemSelection(int category){
        //read all items in the category 
        ifstream infile(filenames[category-1]);
        vector<pair<string, float>> items;
        string itemName;
        float price;
        while(infile>>itemName){
            infile>>price;
            items.push_back(make_pair(itemName, price));
        }
        infile.close();
        //display items
        cout<<"-------------Items-------------"<<endl;
        for(int i=0;i<items.size();i++){
            cout<<(i+1)<<". "<<items[i].first<<"   -   $"<<items[i].second<<endl;
        }
        cout<<"0. Go back"<<endl;
        cout<<"What do you want to have?"<<endl;
        int option;
        cin>>option;
        if(option!=0){
            itemsOrdered.push_back(items[option-1]);
            cout<<"Item added!"<<endl;
        }
    }
    float printOrder(){
        float total_bill=0;
        if(itemsOrdered.size()==0){
            cout<<"No items ordered yet."<<endl;
        }else{
            cout<<"Items Ordered"<<endl;
            cout<<"Dish-----------------Price"<<endl;
            for(int i=0;i<itemsOrdered.size();i++){
                cout<<itemsOrdered[i].first<<"                  $"<<itemsOrdered[i].second<<endl;
                total_bill+=itemsOrdered[i].second;
            }
            cout<<"-----------------"<<endl;
            cout<<"Total              $"<<total_bill<<endl;
            cout<<"Tax @ 10%          $"<<total_bill*0.1<<endl;
            cout<<"Tax after Tax      $"<<total_bill*1.1<<endl;
            cout<<"-----------------"<<endl;
        }
        return total_bill*1.1;
    }
    float askForTip(){
        float amount=0;
        cout<<"Would you like to five a tip? y/n?  ";
        char inp;
        cin>>inp;
        if(inp=='y'||inp=='Y'){
            cout<<"Enter tip amount:  ";
            cin>>amount;
        }
        return amount;
    }
    void takeOrder(){
        while(true){
            int op = menuSelection();
            if(op==0)
                break;
            itemSelection(op);
        }
        float bill = printOrder();
        float tip = askForTip();
        float payable=bill+tip;
        cout<<"please pay $"<<payable<<endl;
        float amount;
        cin>>amount;
        cout<<"Thanks for visting us! Have a great day!"<<endl;
    }
};
int main()
{
    vector<string> filenames;
    filenames.push_back("entrees.txt");
    filenames.push_back("drinks.txt");
    filenames.push_back("appetizers.txt");
    filenames.push_back("desserts.txt");
        Order newOrder(filenames);
    newOrder.takeOrder();
}

code screenshot

Example data in entrees.txt

Example data in appetizers.txt

Example data in drinks.txt

Example data in desserts.txt

Sample Input/Output Screenshot


Related Solutions

Write a C++ or Java program that reads an input graph data from a user. Then,...
Write a C++ or Java program that reads an input graph data from a user. Then, it should present a path for the travelling salesman problem (TSP). In the assignment, you can assume that the maximum number ofvertices in the input graph is less than or equal to 20. Input format: This is a sample input from a user. 4 12 0 1 2 0 3 7 0 2 5 1 0 2 1 2 8 1 3 3 2...
C++ Write a program that reads in a list of 10 names as input from a...
C++ Write a program that reads in a list of 10 names as input from a user and places them in an array. The program will prompt for a name and return the number of times that name was entered in the list. The program should output total number of instances of that name and then prompt for another name until the word done is typed in. For this lab, use the string data type as opposed to char to...
C Program: Create a C program that prints a menu and takes user choices as input....
C Program: Create a C program that prints a menu and takes user choices as input. The user will make choices regarding different "geometric shapes" that will be printed to the screen. The specifications must be followed exactly, or else the input given in the script file may not match with the expected output. Important! Consider which control structures will work best for which aspect of the assignment. For example, which would be the best to use for a menu?...
C Program: Create a C program that prints a menu and takes user choices as input....
C Program: Create a C program that prints a menu and takes user choices as input. The user will make choices regarding different "geometric shapes" that will be printed to the screen. The specifications must be followed exactly, or else the input given in the script file may not match with the expected output. Your code must contain at least one of all of the following control types: nested for() loops a while() or a do-while() loop a switch() statement...
Write a Java program that reads an input graph data from a user. Then, it should...
Write a Java program that reads an input graph data from a user. Then, it should present a path for the travelling salesman problem (TSP). In the assignment, you can assume that the maximum number of vertices in the input graph is less than or equal to 20. Input format: This is a sample input from a user. 4 12 0 1 2 0 3 7 0 2 5 1 0 2 1 2 8 1 3 3 2 0...
using C++ 24. Using Files—Total and Average Rainfall Write a program that reads in from a...
using C++ 24. Using Files—Total and Average Rainfall Write a program that reads in from a file a starting month name, an ending month name, and then the monthly rainfall for each month during that period. As it does this, it should sum the rainfall amounts and then report the total rainfall and average rainfall for the period. For example, the output might look like this: During the months of March–June the total rainfall was 7.32 inches and the average...
In C++, write a program that reads data from a text file. Include in this program...
In C++, write a program that reads data from a text file. Include in this program functions that calculate the mean and the standard deviation. Make sure that the only global variables are the actual data points, the mean, the standard deviation, and the number of data entered. All other variables must be local to the function. At the top of the program make sure you use functional prototypes instead of writing each function before the main function... ALL LINES...
In c++ please. Write a program that reads the contents of two text files and compares...
In c++ please. Write a program that reads the contents of two text files and compares them in the following ways: It should display a list of all the unique words contained in both files. It should display a list of the words that appears in both files. It should display a list of the words that appears in the first file, but not the second. It should display a list of the words that appears in the second file,...
Write a C++ program that reads integers from standard input until end of file. Print out...
Write a C++ program that reads integers from standard input until end of file. Print out the largest integer that you read in, on a line by itself. Any erroneous input (something that is not an integer) should be detected and ignored. In the case where no integers are provided at all, print NO INTEGERS and stop. The whole program is under 40 lines of code. Just read from cin. Now, you need to detect non integers. In this case,...
Write a C++ program that reads integers from standard input until end of file. Print out...
Write a C++ program that reads integers from standard input until end of file. Print out the largest integer that you read in, on a line by itself. Any erroneous input (something that is not an integer) should be detected and ignored. In the case where no integers are provided at all, print NO INTEGERS and stop. Remember, try not to do the entire job all at once! First try input of a single number and make sure it works....
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT