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...
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...
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....
Q20. Using C++ style string to write a program that reads a sentence as input and...
Q20. Using C++ style string to write a program that reads a sentence as input and converts each word of the sentence following the rule below: For every word in the sentence, the first letter is relocated the end of the word. Then append the string “KPU” to the word. More requirements: All letters in the output should be uppercase. More assumptions: The input sentence contains no non-alphabetic letters Sample Run: Please enter the original sentence: i LOVE to program...
Use C language Write a program that reads in a series of lines of input character...
Use C language Write a program that reads in a series of lines of input character by character (using getchar()). The first line of the input contains an integer which specifies the number of remaining lines of input, each of which contains a floating point number. The integer value on the first line can be read with scanf(), but all of the following lines can only be read with getchar(). Each line after the first contains a single floating point...
Q20. Using C++ style string to write a program that reads a sentence as input and...
Q20. Using C++ style string to write a program that reads a sentence as input and converts each word of the sentence following the rule below: For every word in the sentence, the first letter is relocated the end of the word. Then append the string “KPU” to the word. More requirements: All letters in the output should be uppercase. More assumptions: The input sentence contains no non-alphabetic letters Sample Run: Please enter the original sentence: i LOVE to program...
How do I create this program? Using C++ language! Write a program that reads data from...
How do I create this program? Using C++ language! 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 varibles are the mean, standard deviation, and the number of data entered. All other varibles 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...
in python Using this baseline template, write a program to input a choice from a menu...
in python Using this baseline template, write a program to input a choice from a menu def calcArea(length, width):    pass    def CalcVolumeSa(length, width, height):    pass def menu():    pass        def getValuesArea(): pass    def getValuesVolSa(): pass       def main():    menu() if __name__ == "__main__":    main() [1] - Calculate Area of rectangle [2] - calculate Volume and Surface area of Rectangle [x} - Exit Please select Option: input the appropriate values and calculate...
C++ Programming Develop and submit an original implementation of a menu-driven program performing a number of...
C++ Programming Develop and submit an original implementation of a menu-driven program performing a number of tasks relating to student marks scored in a number of assessments including: displaying all marks, adding new student marks, calculating the mean score, median score, finding the minimum and maximum scores as well as displaying the average mark of a given student. The problem: Student marks are kept in a text file as a single column. Each student may have a different number of...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT