Using visual studio C++ programming, develop a menu program which reads in data from 4 different input files appetizers, main courses, desserts, and drinks. Then, record the item information ordered by the customer for each item selected. When finished, display all items ordered to the screen with the subtotal, tax (10% for easy math), and the total. Be sure to get tip as well. Your program must not have redundant code! Use functions where possible to remove all redundant code in your program. The code below is what I have so far. Need help to finish. #include #include #include #include using namespace void filecheck { if (file is open()) {cout
Expert Answer
Completed C++ program code is given below:
#include<iostream>
#include<string>
#include<fstream>
#include<iomanip>
using namespace std;
void fileCheck(ifstream &iFile,string name)
{
if(!iFile.is_open())
{
cout<<name<<“File not found”<<endl;
system(“pause”);
exit(1);
}
}
int getStuff(string name[],ifstream &iFile,float cost[])
{
int i=0;
while(!iFile.eof())
{
iFile>>name[i];
iFile>>cost[i];
iFile.ignore();
i++;
}
return i;
}
void output(int count,float cost[],string name[],string text)
{
for(int a=0;a<count;a++)
{
cout<<a+1<<“)”<<text<<name[a]<<” “<<cost[a]<<endl;
}
}
void menu()
{
cout<<“1. Drinks”<<endl;
cout<<“2. Appetizer”<<endl;
cout<<“3: Main Courses”<<endl;
cout<<“4: Dessert”<<endl;
cout<<“5: EXIT”<<endl;
}
int main()
{
const int x=100;
string drink[x],appetizer[x],mainCourse[x],dessert[x];
float drinkCost[x],appetizerCost[x],mainCourseCost[x],dessertCost[x];
int drinksCounter=0;
int appetizerCounter=0;
int mainCourseCounter=0;
int dessertCounter=0;
ifstream drinks;
ifstream appetizers;
ifstream mainCourses;
ifstream desserts;
drinks.open(“drink.txt”);
appetizers.open(“appetizer.txt”);
mainCourses.open(“mainCourse.txt”);
desserts.open(“dessert.txt”);
fileCheck(drinks,”Drinks”);
fileCheck(appetizers,”Appetizer”);
fileCheck(mainCourses,”Main Course”);
fileCheck(desserts,”Dessert”);
drinksCounter=getStuff(drink,drinks,drinkCost);
appetizerCounter=getStuff(appetizer,appetizers,appetizerCost);
mainCourseCounter=getStuff(mainCourse,mainCourses,mainCourseCost);
dessertCounter=getStuff(dessert,desserts,dessertCost);
output(drinksCounter,drinkCost,drink,”Drinks: “);
output(appetizerCounter,appetizerCost,appetizer,”Appetzers: “);
output(mainCourseCounter,mainCourseCost,mainCourse,”Main Course: “);
output(dessertCounter,dessertCost,dessert,”Dessert: “);
drinks.close();
appetizers.close();
mainCourses.close();
desserts.close();
float tax=0.00;
float total=0.00;
int ch;
int choice;
do{
tax=0.00;
total=0.00;
do
{
menu();
cout<<“Enter the choice”<<endl;
cin>>ch;
int cho;
switch(ch)
{
case 1: output(drinksCounter,drinkCost,drink,”Drinks: “);
cout<<“Enter the drinks you want: “;
cin>>cho;
total=total+drinkCost[cho-1];
tax=tax+0.01*drinkCost[cho-1];
break;
case 2: output(appetizerCounter,appetizerCost,appetizer,”Appetzers: “);
cout<<“Enter the appetizer you want: “;
cin>>cho;
total=total+appetizerCost[cho-1];
tax=tax+0.01*appetizerCost[cho-1];
break;
case 3: output(mainCourseCounter,mainCourseCost,mainCourse,”Main Course: “);
cout<<“Enter the main course you want: “;
cin>>cho;
total=total+mainCourseCost[cho-1];
tax=tax+0.01*mainCourseCost[cho-1];
break;
case 4: output(dessertCounter,dessertCost,dessert,”Dessert: “);
cout<<“Enter the dessert you want: “;
cin>>cho;
total=total+dessertCost[cho-1];
tax=tax+0.01*dessertCost[cho-1];
break;
case 5:
break;
}
}while(ch!=5);
float tip;
cout<<“Enter tip: “;
cin>>tip;
total=total+tip;
cout<<“Total cost: “<<total<<endl;
cout<<“Tax: “<<tax<<endl;
cout<<“Do you want to continue (0/1)”<<endl;
cin>>choice;
}while(choice!=0);
system(“pause”);
return 0;
}
Sample Output:
Sample Text Files: