Begin with your corrected code from Program 5B: Restaurant Menu. (Be sure to see my solution and ensure that your code is accurate before you continue with this assignment.)
Extend your restaurant menu program to include:
You do NOT need to display an itemized list at the end. Once you learn more C++ skills you will add that feature. For now, simply display the grand total for all items ordered to the user at the end.
Your job is to redesign your code to use functions.
At a minimum, you must:
For example, if your Menu consists of:
1. Blueberry Pie
2. Apple Pie
3. Peach Pie
4. Pumpkin Pie
5. Quit
Then create a function called blueberryPie to process the order, adding the cost of blueberry pie to the total and asking the user about 3 options to add on while totaling the price. NOTE: This is mostly a copy and paste of your existing code.
You will need to move constants from main into the function to ensure that the scope (visibility) is accurate OR pass them as parameters. Your choice.
You decide if you use void or value returning functions and if you use value or reference parameters in your functions or none at all.
Each student's solution will be unique. And there are multiple design approaches that are correct.
No global variables are allowed. None. Nada. This is an exercise to reinforce the use of parameters and local variables and constants.
#include <iomanip> #include<iostream> using namespace std; const string ITEM1 = "Cheese Pizza"; const string ITEM2 = "Taco"; const string ITEM3 = "Ice coffee"; const string ITEM4 = "Chicken Salad"; const double COST_ITEM1 = 10.60; const double COST_ITEM2 = 5.25; const double COST_ITEM3 = 4.55; const double COST_ITEM4 = 6.25; const double COST_ADD_ON = 1.5; int main() { string str, data; int item, ch; float cost = 0; cost = 0; cout << "\n Welcome to" << endl; cout << << endl << endl; cout << Moon_light Kitchen (Eat Like There's No Tomorrow)" << endl<< endl; cout << " << endl; cout << "Food menu is here: "<<endl; add more: cout << << endl; cout << "1." << std::left << setw(20) « ITEM1 << $" << std::right << setw(2) << COST_ITEM1 << endl; cout << "2." << std::left << setw(20) << ITEM2 << $" << std::right < setw(2) << COST_ITEM2 << endl; cout << "3." << std:: left << setw(20) « ITEM3 << "$" << std::right < setw(2) << COST_ITEM3 << endl; cout << "4." << std::left << setw(20) « ITEM4 << "$" << std::right << " setw(2) << COST_ITEM4 << endl; cout << " << endl; cout << "Please Make your selection" << endl; cin >> item; switch (item) { case 1: cost += COST_ITEM1 + 0.85; cout << "===== << endl; cout << "Do you want to add extra item in your order yes or no?" « endl; cin >> str; cout << " << endl; if (str == "yes" || str == "YES") { cout << << endl;
endl; cout << "Do you want " << ITEM1 << with " << endl; cout << "1.Extra Cheese\n2. Jalapeno\n3. Pepperoni" << endl; cout << "Cost of each Add-ON is S « COST_ADD_ON << endl; cout << " cin >> ch; if (ch == 1) ( cost + COST_ADD_ON; cout << " With Extra Cheese" << endl; else if (ch == 2) cost - COST ADD_ON; cout << with Jalapeno" << endl; else if (ch3) { cost - COST_ADD ON; cout << " with Pepperoni" << endl; else { cout << "Sorry sir we dont have that Item" << endl; ) else { cout << "cost is: $" << cost << endl; ? break; case 2: cost += COST_ITEN2 0.42; cout << "EEEE < endl; cout << "Do you want to add extra item in your order yes or no?" << endl; cin > str: cout << "asas << endl; if (str a "yes" Il str ** "YES") cout << " < endl; cout << "Do you want " << ITENI << with " << endl; cout << "1.Cheddar Cheese\n2.Cabbage \n3.Sour Cream" << endl; cout << "Cost of each Add-ON is $. « COST_ADD_ON << endl; cout << " << endl; cin >> ch; if (ch == 1) cost + COST ADD ON cout << with Cheddar Cheese " << endl; else if (ch == 2) { cost = COST ADD_ON; cout << "with Cabbage" << endl;
else if (ch == 3) ( cost = COST ADD ON: cout << " With Sour Cream" << endl; ). else cout << "Sorry sir We dont have that Iten" << endl; 3 } else { cout << "Cost is : $" << cost << endl; break; case 3: cost += COST_ITEM3 + 0.36; cout << "============ == " << endl; cout << "Do you want to add extra item in your order yes or no?" < endl; cin >> stri cout << "ess << endl; if (str == "yes" 11 str == "YES") { cout << " endl; cout << "Do you want " << ITEM3 << with " << endl; cout << "1. Whip Topping\n2. Chocolate Syrup\n3. Cherry" << endl; cout << "Cost of each Add-ON is $COST ADD ON < endl; cout << " endl; cin >> ch; if (ch == 1) { cost = COST_ADD_ON; cout << " With Whip Topping " << endl; } else if (ch * 2) cost + COST ADD ON; cout << "With Chocolate Syrup" << endl; 2 else if (ch == 3) cost += COST ADD_ON; cout << "with Cherry" << endl; else { cout << "Sorry sir we dont have that Item" << endl; } else { cout << "cost is : $" << cost << endl; > break; case 4: cost + COST_ITEM4 + 0.50; ) ܐܶ
cout < endl; endl; << endl; cout << "Do you want to add extra item in your order yes or no?" cin >> stri cout << " " << endl; 1f (str == "yes" || str == "YES") cout << "Do you want << ITEM << with " << endl; cout << "1. Avacado\n2. Bacon\n3. Extra chicken" << endl; cout << "Cost of each Add-ON is $ " << COST ADD_ON << endl; cout << " cin >> ch; if (ch - 1) { cost +- COST_ADD_ON; cout << " With Avacado " << endl; else if (ch == 2) { cost + COST ADD_ON: cout << "with Bacon" << endl; else if (ch - 3) ( cost + COST ADD ON: cout << " With Extra Chicken" << endl; Perse cout << "Sorry sir We dont have that Item" << endl; else << cout << " endl; cout << "Cost is: $" << cost << endl; break; default: cout << "Sorry sir we dont have that Item" << endl; break; cout << endl; cout << "Do you want to add something more from our menu item yes or no" << endl; cin >> data; if (data == "yes" || data za "YES") ( goto add_more; else { cout << " " << endl; cout << "Your total cost is: $" << cost << endl; >
Begin with your corrected code from Program 5B: Restaurant Menu. (Be sure to see my solution and ensure that your code i
-
answerhappygod
- Site Admin
- Posts: 899604
- Joined: Mon Aug 02, 2021 8:13 am
Begin with your corrected code from Program 5B: Restaurant Menu. (Be sure to see my solution and ensure that your code i
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!