Code for user to make grocery list in map of key-value pairs


Question 1) Write code which allows a user to make a grocery list. The program would also allow the user to export grocery lists to comma delimited file that could be read by a spreadsheet program (i.e., CSV file) No classes are needed, just a main function.

The function declarations are:

a) void DisplayMenu();

b) void CreateList( map< string, vector >& lists );

c) void ExportLists( map< string, vector >& lists );

The main program should:

1) Use DisplayMenu function to display the menu.

2) Prompt the user for a menu choice.

3) Use CreateList and ExportLists functions to execute the user's choice.

4) Exit if user chooses to exit.

5) Re-prompt the user for invalid choices.

The main program should store grocery lists in the map of key-value pairs called: lists. The key should be a string containing a grocery store name and value should be a vector of strings containing the grocery list of items for that store.

The DisplayMenu function should show the following options:

1) Create a new grocery list

2) Export grocery lists

3) Quit

The CreateList function should:

1) Ask the user for a grocery store name.

2) Ask the user to enter a list of items for this grocery store, until the user enters “done”.

3) Add the items to the vector of strings as they are entered.

4) Display: “Added item to grocery store name list.” after each item is entered, where “item” is the item entered and “grocery store name” is the name entered in Step 1 above.

The ExportLists function should:

1) Ask the user for an output file name.

2) Display: “Writing to filename...”, where “filename” is the output file name entered by the user.

3) Use iterator for-loops to read map called, lists, and save values in a CSV file with two columns. The first column’s header must be: Grocery Store; and the second column’s header should be: Item.

4) Display: “Grocery lists written to filename”, where “filename” is the output file name entered by the user.

Request for Solution File

Ask an Expert for Answer!!
JAVA Programming: Code for user to make grocery list in map of key-value pairs
Reference No:- TGS04584

Expected delivery within 24 Hours