Question: c + + code use the code i already have just help me inplement these things #include #include #include #include #include using namespace std; int
c code use the code i already have just help me inplement these things #include
#include
#include
#include
#include
using namespace std;
int main
const int CHOICE CHOICE CHOICE DONECHOICE ;
int choice;
string itemName;
vector walmartItems, hometownMarketItems, samsClubItems;
do
cout "Grocery Store Menu" endl;
cout WalMart" endl;
cout Hometown Market" endl;
cout Sam's Club" endl;
cout Done choose to exit program endl;
cout "Please enter your choice: endl;
cin choice;
while choice CHOICE choice DONECHOICE
cout "Please enter a valid menu option: ;
cin choice;
if choice DONECHOICE
for int item ; item ; item
cout "Enter item item : endl;
cin itemName;
switch choice
case CHOICE:
walmartItems.pushbackitemName;
break;
case CHOICE:
hometownMarketItems.pushbackitemName;
break;
case CHOICE:
samsClubItems.pushbackitemName;
break;
while choice DONECHOICE;
Display in alphabetical order
cout
Items entered for WalMart in alphabetical order:
;
sortwalmartItemsbegin walmartItems.end;
for const auto &item : walmartItems
cout item endl;
cout
Items entered for Hometown Market in alphabetical order:
;
sorthometownMarketItemsbegin hometownMarketItems.end;
for const auto &item : hometownMarketItems
cout item endl;
cout
Items entered for Sam's Club in alphabetical order:
;
sortsamsClubItemsbegin samsClubItems.end;
for const auto &item : samsClubItems
cout item endl;
Create an output file
ofstream outputFilegrocerylist.txt;
if outputFileisopen
outputFile "Items entered for WalMart in alphabetical order:
;
for const auto &item : walmartItems
outputFile item endl;
outputFile
Items entered for Hometown Market in alphabetical order:
;
for const auto &item : hometownMarketItems
outputFile item endl;
outputFile
Items entered for Sam's Club in alphabetical order:
;
for const auto &item : samsClubItems
outputFile item endl;
outputFile.close;
cout
Data written to 'grocerylist.txt
;
else
cout "Unable to open file for writing.
;
return ;
Initialization:
Define constants for menu choices CHOICE CHOICE CHOICE
DONECHOICE
Declare variables for user input choice and itemName
Create vectors walmartItems hometownMarketItems.
samsclubitems to store items for each store.
Menu Loop:
Use a dowhile loop to display the menu and get the user's choice.
Validate the user's choice to ensure it is within the menu options.
Item Entry Loop:
If the user hasn't chosen to exit choice DONECHOICE enter a
loop to get items for the selected store.
Use a loop to get five items from the user.
Based on the user's choice, store each item in the corresponding
vector walmartItems hometownMarketItems, samsclubItems
Display Items:
After the user is done, sort each vector in alphabetical order.
Display the sorted items for each store using a loop.
File Output:
Open an output file grocerylist.txt
Write the sorted items for each store to the file.
Close the output file.
Conclusion:
Display a message indicating that the data has been written to the
file.
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
