Write a program to help a local restaurant automate its breakfast billing system
ID: 3855571 • Letter: W
Question
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
Your program must contain at least the
following functions:
Function getData: This function loads the data into the array
menuList.
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 :$2.45
Muffin: $0.99
Coffee: $0.50
Tax: $0.20
Amount Due: $4.14
Format your output with two decimal places. The name of each item in the
output must be left justified. You may assume that the user selects only one
item of a particular type.
PART 2
Redo the exercise so that the customer can select multiple items of a particular type. A sample output in this case is:
Welcome to Johnny's Restaurant
1 Bacon and Egg $2.45
2 Muffin $1.98
1 Coffee $0.50
Tax $0.25
Amount Due $5.18
Explanation / Answer
The required code is as follows.Hope it will be of help.Here it goes:
Restra.cpp
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
using namespace std;
struct mnuItm
{
string itemMn;
double priceMn;
};
void getDat(mnuItm mnList[]);
void dispMn(mnuItm mnList[], int io);
void chck(mnuItm mnList[], int order[], int io);
int main()
{
const int mnItems = 8;
mnuItm mnList[mnItems];
int order[mnItems] = {0};
int ch = 0;
bool orders = true;
int cnt = 0;
getDat(mnList);
dispMn(mnList, mnItems);
while(orders)
{
cout << "Please enter the number for the item you would "
<< "like to order, or enter [0] to complete your order."
<< endl;
cin >> ch;
if (ch > 0 && ch <= mnItems)
{
order[ch - 1] += 1;
}
else
orders = false;
}
chck(mnList, order, mnItems);
cin.ignore(2);
return 0;
}
void getDat(mnuItm mnList[])
{
mnuItm PEgg;
mnuItm bEgg;
mnuItm muff;
mnuItm fToast;
mnuItm fBAsk;
mnuItm cer;
mnuItm beans;
mnuItm chai;
PEgg.itemMn = "Plain Egg";
PEgg.priceMn = 1.45;
bEgg.itemMn = "Bacon and Egg";
bEgg.priceMn = 2.45;
muff.itemMn = "Muffin";
muff.priceMn = 0.99;
fToast.itemMn = "French Toast";
fToast.priceMn = 1.99;
fBAsk.itemMn = "Fruit Basket";
fBAsk.priceMn = 2.49;
cer.itemMn = "Cereal";
cer.priceMn = 0.69;
beans.itemMn = "Coffee";
beans.priceMn = 0.50;
chai.itemMn = "Tea";
chai.priceMn = 0.75;
mnList[0] = PEgg;
mnList[1] = bEgg;
mnList[2] = muff;
mnList[3] = fToast;
mnList[4] = fBAsk;
mnList[5] = cer;
mnList[6] = beans;
mnList[7] = chai;
}
void dispMn(mnuItm mnList[], int io)
{
int cnt;
cout << "Welcome to Akshay Cafe!" << endl;
cout << "What would you to order?" << endl;
for(cnt = 0; cnt < io; cnt++)
{
cout << setw(2) << left << "[" << cnt + 1 << "]"
<< mnList[cnt].itemMn << '$'
<< mnList[cnt].priceMn << endl;
}
}
void chck(mnuItm mnList[], int order[], int mnItems)
{
double chckTtl = 0;
double chckTax = 0;
const double RATE = .05;
cout << "Thanks for eating at Akshay Cafe!"
<< "Customer check: " << endl;
for(int i = 0; i < mnItems; i++)
{
if(order[i] > 0) {
cout << setprecision(3) << setw(10) << left << mnList[i].itemMn
<< '$' << (mnList[i].priceMn * order[i]) << endl;
chckTtl += (mnList[i].priceMn * order[i]);
}
}
chckTax = chckTtl * RATE;
chckTtl += chckTax;
cout << setw(14) << left << "Tax" << chckTax << endl
<< setw(14) << left << "Total" << chckTtl << endl;
}
Please rate the answer if it helped.....Thankyou
Hope it helps.....
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.