Question
c++ code Redo Exercise 4 so that the customer can select multiple items of a particular type. A sample output in this case is: #include
c++ code
RedoExercise 4so that the customer can select multiple items of a particular type. A sample output in this case is:
#include
#include
#include
#include
usingnamespacestd;
constintNO_OF_ITEMS=8;
structmenuItemType
{
stringmenuItem;
doublemenuPrice;
};
voidgetData(ifstream&inFile,menuItemTypemList[],intlistSize);
voidshowMenu(menuItemTypemList[],intlistSize);
voidprintCheck(menuItemTypemList[],intlistSize,
intcList[],intcListLength);
voidmakeSelection(intlistSize,
intcList[],int&cListLength);
boolisItemSelected(intcList[],intcListLength,intitemNo);
intmain()
{
menuItemTypemenuList[NO_OF_ITEMS];
intchoiceList[NO_OF_ITEMS];
intchoiceListLength;
ifstreaminFile;
cout< inFile.open("Ch9_Ex4Data.txt"); if(!inFile) { cout<<"Cannotopentheinputfile.ProgramTerminates!" < return1; } getData(inFile,menuList,NO_OF_ITEMS); showMenu(menuList,NO_OF_ITEMS); makeSelection(NO_OF_ITEMS, choiceList,choiceListLength); printCheck(menuList,NO_OF_ITEMS, choiceList,choiceListLength); return0; } voidgetData(ifstream&inFile,menuItemTypemList[],intlistSize) { charch; for(inti=0;i { getline(inFile,mList[i].menuItem); inFile>>mList[i].menuPrice; inFile.get(ch); } } voidshowMenu(menuItemTypemList[],intlistSize) { cout<<"WelcometoJohnny'sResturant"< cout<<"----Today'sMenu----"< for(inti=0;i cout< < cout< } voidprintCheck(menuItemTypemList[],intlistSize, intcList[],intcListLength) { inti; doublesalesTax; doubleamountDue=0; cout<<"WelcometoJohnny'sResturant"< for(i=0;i { cout< < amountDue+=mList[cList[i]].menuPrice; } salesTax=amountDue*.05; cout< < amountDue=amountDue+salesTax; cout< <<"$"< } voidmakeSelection(intlistSize, intcList[],int&cListLength) { intselectionNo=0; intitemNo; charresponse; cListLength=0; cout<<"Youcanmakeupto"< <<"singleorderselections"< cout<<"DoyouwanttomakeselectionY/y(Yes),N/n(No):"; cin>>response; cout< while((response=='Y'||response=='y')&& cListLength<8) { cout<<"Enteritemnumber:"; cin>>itemNo; cout< if(!isItemSelected(cList,cListLength,itemNo)) cList[cListLength++]=itemNo-1; else cout<<"Itemalreadyselected"< cout<<"SelectanotheritemY/y(Yes),N/n(No):"; cin>>response; cout< } } boolisItemSelected(intcList[],intcListLength,intitemNo) { boolfound=false; for(inti=0;i if(cList[i]==itemNo) { found=true; break; } returnfound; } 3 eggs and tea Input Output Results Tax$0.26Amount Due$5.35Welcome to Johnny's Resturant ----Today's Menu---- 1: Plain Egg $1.45 2: Bacon and Egg $2.45 3: Muffin $0.99 4: French Toast $1.99 5: Fruit Basket $2.49 6: Cereal $0.69 7: Coffee $0.50 8: Tea $0.75 You can make up to 8 different selections Do you want to make selection Y/y (Yes), N/n (No): Y Enter item number: 1 How many orders: 3 Select another item Y/y (Yes), N/n (No): Y Enter item number: 8 How many orders: 1 Select another item Y/y (Yes), N/n (No): N Welcome to Johnny's Resturant 3 Plain Egg $4.35 1 Tea $0.75 Tax $0.26 Amount Due $5.35
Y 1 3 Y 8 1 N
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started