Question

In C++ Programming Write a program in Restaurant.cpp to help a local restaurant automate its breakfast...

In C++ Programming

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

  1. Show the customer the different breakfast items offered by the restaurant.
  2. Allow the customer to select more than one item from the menu.
  3. 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):

Name Price
Egg (cooked to order) $1.99
Golden-Brown Pancake $1.99
French Toast $2.99
Muffin $0.99
Bagel w/ Spread $1.20
Fresh Fruit $3.49
Steel-Cut Irish Oatmeal $4.69
Coffee $1.50
Pot of Assorted Tea $1.75
Hot Chocolate $1.75

Define a struct named MenuItem with two components: name of type string and price of type double. Use an array of the struct MenuItem to store each menu item and a parallel array to store the quantity of each item a customer orders.

Your program must contain at least the following functions:

  1. Function getData: This function loads the item and price data from a text file named menu.txt (with a lowercase m) into the array of MenuItems. You will need to create the text file that contains this menu information. Format your text file so that it works well for your program (you may pick the format). This function should have two parameters: (1) an array of MenuItems and (2) the array length. The function should return the number of items read from the file.

    Hint: If you use getline() to read the entire line as each menu item’s name, you will need to ignore the rest of the line after reading in the price as a double. There is also a 3-parameter overload of getline() that allows you to change the default delimiter ('\n') to another character like a tab ('\t').

  2. Function showMenu: This function shows the different items offered by the restaurant and tells the user how to select the items. As expected, this function will need access to the MenuItems and know the number of items. It should not modify the MenuItems, so make that first parameter const. The function should show the welcome message first as shown in the example output below.
  3. Function makeSelection: This function repeatedly asks the customer if they would like to make a selection until the enter an N or n. If the customer enters Y or y, the program gets a menu item by number and a quantity from the customer. Validate the user input and store the quantities of each item purchased in a parallel array of integers. This function should not reference or modify the menuList array. See the example output below for what prompts to provide. If the user selects the same item number twice, replace the original quantity with the latest quantity.
  4. Function printReceipt: This function calculates and prints the check. It requires the two parallel arrays as parameters: (1) the MenuItem array, (2) the int array, and (3) the array size. (Note that the billing amount should include a 7% sales tax.)

Sample Output (user input is in yellow)

 Welcome to the Programmers' Cafe
-----------Today's Menu-----------
 1: Egg (cooked to order)    $1.99
 2: Golden-Brown Pancake     $1.99
 3: French Toast             $2.99
 4: Muffin                   $0.99
 5: Bagel w/ Spread          $1.20
 6: Fresh Fruit              $3.49
 7: Steel-Cut Irish Oatmeal  $4.69
 8: Coffee                   $1.50
 9: Pot of Assorted Tea      $1.75
10: Hot Chocolate            $1.75

Do you want to place an order? (y/n): y

Enter item number: 12

Enter item number between 1 and 10: 1

Enter item quantity: 12

Select another item? (y/n): y

Enter item number: 3

Enter item quantity: 1

Select another item? (y/n): y

Enter item number: 7

Enter item quantity: 20

Select another item? (y/n): y

Enter item number: 10

Enter item quantity: 2

Select another item? (y/n): n

  Thank you for eating at
   The Programmers' Cafe
------------------------------------
Receipt                 Qty   Amount
------------------------------------
Egg (cooked to order)    12  $ 23.88
French Toast              1  $  2.99
Steel-Cut Irish Oatmeal  20  $ 93.80
Hot Chocolate             2  $  3.50
    Tax                      $  8.69
    Amount Due               $132.86

Format your output as shown in the example. The name of each item in the output must be left justified. Right justify the price and quantities.

Upload your source code (Restaurant.cpp) and the text file with the menu information.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

C++ Program

/* C++ Program that displays menu, ask for selection and prints price */

#include <iostream>
#include <iomanip>
#include <fstream>
#include <string>

using namespace std;

//Structure to hold each menu item
struct MenuItem
{
string name;
double price;
};

//Function that reads data from file
int getData(struct MenuItem menuList[])
{
//Opening file for reading
fstream fin("menu.txt", ios::in);

int i=0;

struct MenuItem temp;

//Loop till entire data is processed
while(fin.good())
{
//Getting name
getline(fin, temp.name);

//Reading price
fin >> temp.price;

fin.ignore();

//Storing in array
menuList[i] = temp;

i++;
}

//Closing file
fin.close();

return i;
}

//Function that displays menu
void showMenu(struct MenuItem menuList[], int cnt)
{
int i;
cout << "\n Welcome to the Programmers' Cafe \n\n --------Today's Menu-------- \n";

//Looping over menu and printing to user
for(i=0; i<cnt; i++)
{
//Printing menu item
cout << fixed << setprecision(2);
cout << "\n " << right << setw(3) << (i+1) << ". " << left << setw(25) << menuList[i].name << left << setw(2) << "$ " << left << setw(10) << menuList[i].price;
}

cout << "\n \n";
}

//Function that reads user selection
int makeSelection(int item[], int quantity[], int cnt)
{
int i=0, temp;

char ch;

//Prompting user
cout << "\n\n Do you want place an order? (y/n): ";
cin >> ch;

//Loop till user wants to stop
while(ch == 'y' || ch == 'Y')
{
//Reading item number
cout << "\n\n Enter item number: ";
cin >> temp;

while(temp < 1 || temp > cnt)
{
//Reading item number
cout << "\n\n Enter item number between 1 and " << cnt << ": ";
cin >> temp;
}

//Storing in array
item[i] = temp;

//Reading item quantity
cout << "\n Enter item quantity: ";
cin >> temp;

//Storing in array
quantity[i] = temp;

//Prompting user again
cout << "\n\n Select another item? (y/n): ";
cin >> ch;

i++;
}

return i;
}

//Function that calculates the price
void priceCheck(struct MenuItem menuList[], int item[], int quantity[], int items)
{
int i=0;

double total = 0, tax;

cout << "\n\n Thank you for eating at The Programmers' Cafe \n\n";

cout << "----------------------------------------------------------";
cout << "\n " << left << setw(20) << "Receipt" << left << setw(5) << "Qty" << left << setw(5) << " Amount \n";
cout << "----------------------------------------------------------\n";

cout << fixed << setprecision(2);

//Printing menu selected
for(i=0; i<items; i++)
{
cout << "\n " << left << setw(20) << menuList[item[i] - 1].name << left << setw(5) << quantity[i] << left << setw(2) << " $ " << left << setw(2) << (quantity[i] * (menuList[item[i] - 1].price));
total += (quantity[i] * (menuList[item[i] - 1].price));
}

//Calculating tax
tax = (7/100.0) * total;

//Printing tax
cout << "\n\n " << left << setw(25) << " Tax " << left << setw(2) << " $ " << left << setw(2) << tax;

//Printing total amount due
cout << "\n\n " << left << setw(25) << " Amount Due " << left << setw(2) << " $ " << left << setw(2) << (total + tax) << "\n\n";
}

//Main function
int main()
{
struct MenuItem menuList[10];
int item[20], quantity[20];
int totalItems, cnt;

//Reading data
cnt = getData(menuList);

//Displaying menu
showMenu(menuList, cnt);

//Making user selection
totalItems = makeSelection(item, quantity, cnt);

//Checking price
priceCheck(menuList, item, quantity, totalItems);

cout << "\n\n";
return 0;
}

______________________________________________________________________________________________________________________

Input File:

Egg (cooked to order)
1.99
Golden-Brown Pancake
1.99
French Toast
2.99
Muffin
0.99
Bagel w/ Spread
1.20
Fresh Fruit
3.49
Steel-Cut Irish Oatmeal
4.69
Coffee
1.50
Pot of Assorted Tea
1.75
Hot Chocolate
1.75

_______________________________________________________________________________________________________________________

Sample Run:

CATC\Restaurant_2\bin\Debug Restaurant_2.exe Welcome to the Programmers Cafe --------Todays Menu -------- $ 1.99 1.99 2.99

Add a comment
Know the answer?
Add Answer to:
In C++ Programming Write a program in Restaurant.cpp to help a local restaurant automate its breakfast...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • c++ Write a C++ program using the struct keyword to help a local restaurant automate its...

    c++ Write a C++ program using the struct keyword 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) Menu Plain...

  • In C++ Programming Write a program in to help a local restaurant automate its breakfast

    Write a program to help a local restaurant automate its breakfast billing system. The program should do the following:Show the customer the different breakfast items offered by the restaurant.Allow the customer to select more than one item from the menu.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):Use an array menuList of type menuItemType, as defined in Programming Exercise 3. Your program must contain at least the...

  • IN C# Write a program to help a local restaurant automate its lunch billing system. The...

    IN C# Write a program to help a local restaurant automate its lunch billing system. The program should do the following: Show the customer the different lunch items offered by the restaurant. Allow the customer to select more than one item from the menu. Calculate and print the bill. Assume that the restaurant offers the following lunch items (the price of each item is shown to the right of the item): Ham and Cheese Sandwich $5.00 Tuna Sandwich $6.00 Soup...

  • #include <iostream> #include <iomanip> #include <vector> #include <string> using namespace std; struct menuItemType { string menuItem;...

    #include <iostream> #include <iomanip> #include <vector> #include <string> using namespace std; struct menuItemType { string menuItem; double menuPrice; }; void getData(menuItemType menuList[]); void showMenu(menuItemType menuList[], int x); void printCheck(menuItemType menuList[], int menuOrder[], int x); int main() { const int menuItems = 8; menuItemType menuList[menuItems]; int menuOrder[menuItems] = {0}; int orderChoice = 0; bool ordering = true; int count = 0; getData(menuList); showMenu(menuList, menuItems); while(ordering) { cout << "Enter the number for the item you would\n" << "like to order, or...

  • Need help with a C++ problem I have

    For my assignment I have to write a program that creates a restaurant billing system. I think that I got it correct but it says that it is incorrect, so I was wondering if someone would be able to look over my code. It says that I need tax of $0.20, and the amount due to be $4.10, which is what I have in my output.https://imgur.com/a/jgglmvWMy issue is that I have the correct outcome when I run my program but...

  • Your assignment is to create a restaurant ordering system where the cashier can create the menu...

    Your assignment is to create a restaurant ordering system where the cashier can create the menu and then take in the order and display the order back to the customer Sample Execution – Level 1 Welcome to your Menu Creation system. How many items would you like to have on your menu? 2 Create your menu! Enter item #1: Coffee Enter item #2: Tea This is the menu: Coffee Tea What would you like to order? Cake That isn’t on...

  • THIS IS FOR C++ PROGRAMMING USING VISUAL STUDIO THE PROGRAM NEEDS TO BE IN C++ PROGRAMMING #inclu...

    THIS IS FOR C++ PROGRAMMING USING VISUAL STUDIO THE PROGRAM NEEDS TO BE IN C++ PROGRAMMING #include "pch.h" #include #include using namespace std; // Function prototype void displayMessage(void); void totalFees(void); double calculateFees(int); double calculateFees(int bags) {    return bags * 30.0; } void displayMessage(void) {    cout << "This program calculates the total amount of checked bag fees." << endl; } void totalFees() {    double bags = 0;    cout << "Enter the amount of checked bags you have." << endl;    cout <<...

  • C++ HELP I need help with this program. I have done and compiled this program in...

    C++ HELP I need help with this program. I have done and compiled this program in a single file called bill.cpp. It works fine. I am using printf and scanf. Instead of printf and scanf use cin and cout to make the program run. after this please split this program in three files 1. bill.h = contains the class program with methods and variables eg of class file class bill { } 2. bill.cpp = contains the functions from class...

  • C program help: Write a C program that uses three functions to perform the following tasks:...

    C program help: Write a C program that uses three functions to perform the following tasks: – The first function should read the price of an item sold at a grocery store together with the quantity from the user and return all the values to main(). example: #include void getInput(int *pNum1, int *pNum2); // note: *pNum1 & *pNum2 are pointers to ints int main () {    int numDucks,numCats;    getInput(&numDucks, &numCats); // passing addresses of num1 & num2 to...

  • Sample Execution – Level 3 Welcome to your Menu Creation system. How many items would you...

    Sample Execution – Level 3 Welcome to your Menu Creation system. How many items would you like to have on your menu? 2 Create your menu! Enter item #1: Coffee Enter the number of toppings: 2 Enter topping #1: Whipped Cream Enter topping #2: Cinnamon Enter item #2: Tea Enter the number of toppings: 2 Enter topping #1: Milk Enter topping #2: Sugar May I take your order? This is the menu: Coffee Tea Pop How many items would you...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT