Question

In: Computer Science

In C++ Define enumeration data type menuItemName with enumerators of PlainEgg, BaconAndEgg, Muffin, FrenchToast, FruitBasket, Cereal,...

In C++

Define enumeration data type menuItemName with enumerators of PlainEgg, BaconAndEgg, Muffin, FrenchToast, FruitBasket, Cereal, Coffee, and Tea.

Use an array, menuList, of the struct menuItemType, with tree components: menuItem of type menuItemName, menuPrice of type double, and Count of type int.

Write a program to help a local restaurant automate its breakfast billing system. The program should do the following:

a. Show the customer the different breakfast items offered by the restaurant.

b. Allow the customer to select more than one item from the menu.

c. Calculate and print the bill

Assume that the restaurant offers the following breakfast items (the price of each item is shown to the right of the item):

Plain Egg​$1.45

Bacon and Egg​$2.45

Muffin​$0.99

French Toast​$1.99

Fruit Basket​$2.49

Cereal​$0.69

Coffee​$0.50

Tea​$0.75

Use an array, menuList, of the struct menuItemType, with three components: menuItem of enummenuItemName as described above, menuPrice of type double, and Count of type int. Your program must contain at least the following functions:

● Function showMenu: This function shows the different items offered by the restaurant and tells the user how to select the items.

● Function printCheck: This function calculates and prints the check. (Note that the billing amount should include a 5% tax.)

A sample output is:

Welcome to Johnny’s Restaurant

Bacon and Egg​1​$2.45

Muffin​1​$0.99

Coffee​2​$1.00

Amount Total​​$4.44

Tax​​$0.22

Amount Due​​$4.66

Solutions

Expert Solution

Code in C++

#include <bits/stdc++.h> 
using namespace std; 
//enum declaration
enum menuItemName { PlainEgg, BaconAndEgg, Muffin, FrenchToast, FruitBasket, Cereal, Coffee, Tea};
//function to get item name from enum number
string enum_to_string(menuItemName item) {
   switch(item){
                case PlainEgg:
                        return "PlainEgg";
                case BaconAndEgg:
                        return "BaconAndEgg";
                case Muffin:
                        return "Muffin";
                case FrenchToast:
                        return "FrenchToast";
                case FruitBasket:
                        return "FruitBasket";
                case Cereal:
                        return "Cereal";        
                case Coffee:
                        return "Coffee";
                case Tea:
                        return "Tea";
                default:
                return "Invalid";
   }
}
//struct declaration
struct menuItemType{
        menuItemName menuItem;
        double menuPrice;
        int count;
};
void show_menu(struct menuItemType menuList[], int size){
        cout<<"Select Items from Menu"<<endl;
        for(int i=0;i<size;i++){
                cout<<"Enter "<<(i+1)<<" for "<<enum_to_string(menuList[i].menuItem)<<" $"<<menuList[i].menuPrice<<endl;
        }
        cout<<"Enter -1 to finish ordering"<<endl;
}
void printCheck(struct menuItemType menuList[], int size, double tax){
        double total_price=0;
        for(int i=0;i<size;i++){
                total_price+=(menuList[i].menuPrice*menuList[i].count);
        }
        setprecision(2);
        cout<<"Amount Total = $"<<total_price<<endl;
        cout<<"Tax = $"<<tax<<endl;
        double final_amount = total_price+((total_price*tax)/100);
        cout<<"Amount Due = $"<<final_amount<<endl;
}
int main(int argc, char const *argv[])
{
        //print welcome message
        cout<<"Welcome to Johnny's Restaurant"<<endl;
        //set precision to 2 so that we only see amounts till two decimal places
        setprecision(2);
        // create menuList array
        struct menuItemType menuList[8];
        menuList[0] = {static_cast<menuItemName>(0), 1.45, 0};
        menuList[1] = {static_cast<menuItemName>(1), 2.45, 0};
        menuList[2] = {static_cast<menuItemName>(2), 0.99, 0};
        menuList[3] = {static_cast<menuItemName>(3), 1.99, 0};
        menuList[4] = {static_cast<menuItemName>(4), 2.49, 0};
        menuList[5] = {static_cast<menuItemName>(5), 0.69, 0};
        menuList[6] = {static_cast<menuItemName>(6), 0.50, 0};
        menuList[7] = {static_cast<menuItemName>(7), 0.75, 0};
        int val;
        do{
                show_menu(menuList,8);
                cin>>val;
                if(val>=1 && val<=8){
                        cout<<enum_to_string(menuList[val-1].menuItem)<<" added"<<endl;
                        menuList[val].count++;
                }
        }while(val!=-1);
        //call printCheck
        printCheck(menuList,8,5);
}

Sample Console Input/Output

Welcome to Johnny's Restaurant
Select Items from Menu        
Enter 1 for PlainEgg $1.45    
Enter 2 for BaconAndEgg $2.45 
Enter 3 for Muffin $0.99      
Enter 4 for FrenchToast $1.99 
Enter 5 for FruitBasket $2.49
Enter 6 for Cereal $0.69     
Enter 7 for Coffee $0.5      
Enter 8 for Tea $0.75        
Enter -1 to finish ordering
4
FrenchToast added
Select Items from Menu
Enter 1 for PlainEgg $1.45
Enter 2 for BaconAndEgg $2.45
Enter 3 for Muffin $0.99
Enter 4 for FrenchToast $1.99
Enter 5 for FruitBasket $2.49
Enter 6 for Cereal $0.69
Enter 7 for Coffee $0.5
Enter 8 for Tea $0.75
Enter -1 to finish ordering
5
FruitBasket added
Select Items from Menu
Enter 1 for PlainEgg $1.45
Enter 2 for BaconAndEgg $2.45
Enter 3 for Muffin $0.99
Enter 4 for FrenchToast $1.99
Enter 5 for FruitBasket $2.49
Enter 6 for Cereal $0.69
Enter 7 for Coffee $0.5
Enter 8 for Tea $0.75
Enter -1 to finish ordering
2
BaconAndEgg added
Select Items from Menu
Enter 1 for PlainEgg $1.45
Enter 2 for BaconAndEgg $2.45
Enter 3 for Muffin $0.99
Enter 4 for FrenchToast $1.99
Enter 5 for FruitBasket $2.49
Enter 6 for Cereal $0.69
Enter 7 for Coffee $0.5
Enter 8 for Tea $0.75
Enter -1 to finish ordering
3
Muffin added
Select Items from Menu
Enter 1 for PlainEgg $1.45
Enter 2 for BaconAndEgg $2.45
Enter 3 for Muffin $0.99
Enter 4 for FrenchToast $1.99
Enter 5 for FruitBasket $2.49
Enter 6 for Cereal $0.69
Enter 7 for Coffee $0.5
Enter 8 for Tea $0.75
Enter -1 to finish ordering
3
Muffin added
Select Items from Menu
Enter 1 for PlainEgg $1.45
Enter 2 for BaconAndEgg $2.45
Enter 3 for Muffin $0.99
Enter 4 for FrenchToast $1.99
Enter 5 for FruitBasket $2.49
Enter 6 for Cereal $0.69
Enter 7 for Coffee $0.5
Enter 8 for Tea $0.75
Enter -1 to finish ordering
4
FrenchToast added
Select Items from Menu
Enter 1 for PlainEgg $1.45
Enter 2 for BaconAndEgg $2.45
Enter 3 for Muffin $0.99
Enter 4 for FrenchToast $1.99
Enter 5 for FruitBasket $2.49
Enter 6 for Cereal $0.69
Enter 7 for Coffee $0.5
Enter 8 for Tea $0.75
Enter -1 to finish ordering
-1
Amount Total = $10.64
Tax = $5
Amount Due = $11.172

Let me know in comments if you have any doubts. Do leave a thumbs up if this was helpful.


Related Solutions

(C++ ONLY) You will define your own data type. It will be a struct called Fraction....
(C++ ONLY) You will define your own data type. It will be a struct called Fraction. The struct will have 2 integer fields: numerator and denominator. You will write a function called reduce that takes a Fraction as a parameter and returns that Fraction in its reduced form. For example, if the fraction 2/4 is passed to the function, the fraction 1/2 will be returned. Consider any fraction with a denominator of 1 to be in reduced form. You will...
Java problem Implement class Course containing: String name, enumeration Type (Foundamental, Specialization, Discipline), enumeration Stream (English,...
Java problem Implement class Course containing: String name, enumeration Type (Foundamental, Specialization, Discipline), enumeration Stream (English, French, German), int creditPoints.  Class Contract has an array of courses with methods addCourse(Course), deleteCourse(type, stream, name) sort(), display().  Courses are sorted by stream, type, name.  If 2 courses are equal raise a custom exception in method sort().  Make Contract implement Storable.
(1)Discuss the syntax for combining the definition and declaration of an enumeration type into one statement....
(1)Discuss the syntax for combining the definition and declaration of an enumeration type into one statement. Provide some examples. (2) Describe the syntax of a namespace statement. Discuss the syntax for accessing a namespace member. Also, review the syntax for the using namespace statement and discuss how this simplifies the process of accessing namespace members.
The probability that a randomly selected box of a certain type of cereal has a particular...
The probability that a randomly selected box of a certain type of cereal has a particular prize is 0.2. Suppose you purchase box after box until you have obtained four of these prizes. (a) What is the probability that you purchase x boxes that do not have the desired prize? h(x; 4, 0.2) b(x; 4, 2, 10)      nb(x; 4, 2, 10) b(x; 4, 0.2) h(x; 4, 2, 10) nb(x; 4, 0.2) (b) What is the probability that you purchase...
1) A manufacturer of cereal claims that the mean weight of a particular type of box...
1) A manufacturer of cereal claims that the mean weight of a particular type of box of cereal is 1.2 pounds. A random sample of 71 boxes reveals a sample average of 1.186 pounds and a sample standard deviation of .117 pound. Using the .01 level of significance, is there evidence that the average weight of the boxes is different from 1.2 pounds? Is the test statistic for this test Z or t? Select one: a. t b. z 2)...
Define a healthy brand of cereal to be one with both low sodium and low sugar....
Define a healthy brand of cereal to be one with both low sodium and low sugar. Given a data set of different cereal brands with their respective amounts of sodium and sugar, what graphical (charts, plots, etc) and numerical (mean, mode, variance, etc) data summary methods might be useful in determining what brand of cereal is the healthiest?
Define a healthy brand of cereal to be one with both low sodium and low sugar....
Define a healthy brand of cereal to be one with both low sodium and low sugar. Given a data set of different cereal brands with their respective amounts of sodium and sugar, what graphical (charts, plots, etc) and numerical (mean, mode, variance, etc) data summary methods might be useful in determining what brand of cereal is the healthiest?
Java Programmig Enumeration Assignment. What Will You Learn Using enumerations to ensure data integrity and using...
Java Programmig Enumeration Assignment. What Will You Learn Using enumerations to ensure data integrity and using enumerations for making business decisions. Deliverables Person.java Student.java StudentAthlete.java App.java Address.java (Optional) AddressType.java Contents Using inheritance and the classes (below) The Person class has first name last name age hometown a list of addresses The Student class is a person with an id and a major and a GPA Student has to call super passing the parameters for the super class constructor The StudentAthlete...
In c++, define a class with the name BankAccount and the following members: Data Members: accountBalance:...
In c++, define a class with the name BankAccount and the following members: Data Members: accountBalance: balance held in the account interestRate: annual interest rate. accountID: unique 3 digit account number assigned to each BankAccount object. Use a static data member to generate this unique account number for each BankAccount count: A static data member to track the count of the number of BankAccount objects created. Member Functions void withdraw(double amount): function which withdraws an amount from accountBalance void deposit(double...
Implement a program as an object using a class (abstract data type) in C++ that does...
Implement a program as an object using a class (abstract data type) in C++ that does the following: 1) reads the firstName, lastName and 3 test scores of at least five students. 2) calculate student test score totals, average, letter grade for each student. 3) Display the results in a table format showing firstName, lastName, test1, test2, test3, total, average, letterGrade, of all the students. 3 files .h, .cpp, main.cpp create an object that can hold records. must get records...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT