I have my program complete and it runs smoothly: I just need to be sure I have e
ID: 664222 • Letter: I
Question
I have my program complete and it runs smoothly: I just need to be sure I have everything the instructor asked:
instructions: Read from a file (menu.csv) the Menu items and their prices. ( I have it in a menu.txt with all the items)
The user may choose from zero to all the items in the menu.csv file but only one of each item,
Except for _getch(), your program cannot contain any “C” functions (i.e. strcpy()) only C++ functions.
My program:
#include<iostream>
#include<string>
#include<iomanip>
using namespace std;
struct menuItemType
{
string menuItem;
double menuPrice;
};
void getdata(menuItemType[], menuItemType[], int&);
void showMenu(menuItemType[], int);
void printCheck(menuItemType[], int);
int main()
{
int items = 0;
menuItemType menuList[] = { "Cheese Omelette", 3.99,
"Omelette In a Bag", 2.79,
"40-Second Omelette", 4.99,
"Denver Ometette", 5.99,
"Green Eggs and Ham Omelette", 14.99,
"Spanish Omelette", 3.59,
"French Potato Omelette", 6.97,
"Greg's Ham & Cheese Omelette", 2.99,
"Cheesy Chicken Omelette", 6.56,
"Western Omelette", 11.99,
"BLT Omelette", 5.99,
"Super Simple Omelette", 0.99,
"Hawaiian Omelette", 11.99,
"Spam Omelette", 1.99,
"Bacon Cheddar & Chives Omelette", 11.99,
"Smoked Beef Omelette", 9.99,
"Cheese And Herb Souffle Omelette", 6.99,
"Campfire Omelette", 5.99,
"Omelette Savoyarde(French)", 23.99,
"Omelette On a Stick", 4.99,
"Neapolitan Omelette", 7.99,
"German Omelette With Bacon", 8.99,
"The 123 Omelette", 2.99,
"Jelly Omelette", 1.99,
"Coffee", 0.79,
};
menuItemType order[10];
cout << "Welcome to Johnny's Restaurant menu Item price ";
showMenu(menuList, 25);
getdata(menuList, order, items);
printCheck(order, items);
//Pause the system for a while
system("pause");
return 0;
}
void printCheck(menuItemType order[], int items)
{
int i;
double total = 0, tax;
cout << "Your Check Ordered Items Item price ";
showMenu(order, items);
for (i = 0; i<items; i++)
total += order[i].menuPrice;
cout << " Items cost total " << "$" << setprecision(2) << fixed << total << endl;
tax = total*.05;
cout << "Tax " << "$" << setprecision(2) << fixed << tax << endl;
cout << "Amount Due " << "$" << setprecision(2) << fixed << total + tax << endl;
}
void getdata(menuItemType menu[], menuItemType order[], int& items)
{
char yesno = 'Y';
int n;
while (toupper(yesno) == 'Y')
{
cout << "Enter your order item number: ";
cin >> n;
while (n<1 || n>25)
{
cout << "invalid item number ";
cout << "Enter your order item number: ";
cin >> n;
}
order[items].menuItem = menu[n - 1].menuItem;
order[items].menuPrice = menu[n - 1].menuPrice;
items++;
cout << "Would you like continue?(y/n)? ";
cin >> yesno;
}
}
void showMenu(menuItemType a[], int n)
{
int i;
for (i = 0; i<n; i++)
cout << i + 1 << ". " << setw(16) << left << a[i].menuItem << "$" << setprecision(2) << fixed << a[i].menuPrice << endl;
}
Explanation / Answer
The program is successfully compiled and executed. However you can write this program in other way Keep the Menu List in a file (menu.txt). Read the data of menu.txt, to the program with the help of following code, string line; fstream myfile; myfile.open("); if (myfile.is_open()) { while(getline(myfile,line)) { coutRelated Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.