Question

In: Computer Science

The purpose of the program is for the user to be able to manage a grocery...

The purpose of the program is for the user to be able to manage a grocery list. The user should be presented with a menu to either add and item or quit. The menu input should be case insensitive (e.g. 'a' and 'A' should both work to add).

At the top of the starting code, you will notice the function prototypes for two functions:

char chooseMenu()

this function should present the menu and return what the user inputs (as a character). However, if the user enters anything other than the options (a/A/q/Q), it should present the menu again.

vector addItem(vector )

this function should receive a vector of strings and ask the user to enter an item and get their input (spaces allowed). That item should be added to the end of the vector and then returned.

I have the following code done.

#include
#include
using namespace std;

// function prototypes
char chooseMenu();
vector addItem(vector );

// main program
int main() {
vector list;
char choice;
  
cout << "Welcome to Grocery List Manager\n";
cout << "===============================\n";
do{
choice = chooseMenu();
if( choice == 'a' || choice == 'A' ){
list = addItem(list);
}
}while( choice != 'q' && choice != 'Q' );
  
return 0;
}

// function definitions


// Menu input/output
cout << "Menu\n----\n";
cout << "(A)dd item\n";
cout << "(Q)uit\n";
  
cin >> input;
cin.ignore();


// item input/output
cout << "Enter item:\n";
getline(cin,input);

The program should take the following input. If someone enters a letter not a or q then it asks again if a or A is entered let the user enter an item to add if they enter q or Q stop program.

x

a

onions

a

cheese

A

tilapia

Q

Solutions

Expert Solution

#include <iostream>
#include <vector>
using namespace std;

// function prototypes
char chooseMenu();
vector <string> addItem(vector <string>);

// main program
int main() {
vector <string> list;
char choice;
  
cout << "Welcome to Grocery List Manager\n";
cout << "===============================\n";
do{
choice = chooseMenu();
if( choice == 'a' || choice == 'A' ){
list = addItem(list);
}
}while( choice != 'q' && choice != 'Q' );
  
return 0;
}

// function definitions

char chooseMenu(){
// Menu input/output
cout << "Menu\n----\n";
cout << "(A)dd item\n";
cout << "(Q)uit\n";
char input;  
cin >> input;
cin.ignore();
return input;
}

vector <string> addItem(vector <string>A){
// item input/output
cout << "Enter item:\n";
string input;
getline(cin,input);
A.push_back(input);
return A;
}

Refer below for indentation and output preview.


Related Solutions

9) This is in Python Code a program that allows the user to manage its expenses...
9) This is in Python Code a program that allows the user to manage its expenses accepting the following commands: - Add <player_name> -> This command adds a new player to the system. Assume there can’t be repeated names. If a name already exists then an error is shown to the user. - Score <player_name> <score> -> This command adds the score to the player with the name player-name. Each score needs to be added individually - Report -> This...
Create a program in visual basic that allows the user to manage vehicle information including: •...
Create a program in visual basic that allows the user to manage vehicle information including: • License plate number • Owner name • Owner phone number The user interface will be GUI-based providing the following capabilities: • Add up to 100 vehicles • Remove specified vehicles • View a sorted list of all known license plates • View the data for a specified vehicle • Save the database contents into a file • Load a saved database from a file
Suppose you manage a local grocery store, and you learn that a very popular national grocery...
Suppose you manage a local grocery store, and you learn that a very popular national grocery chain is about to open a store just a few miles away. Use the model of monopolistic competition to analyze the impact of this new store on the quantity of output your store should produce (Q) and the price your store should charge (P). What will happen to your profits? Explain your reasoning in detail. How and why do profits change? What could you...
Suppose you manage a local grocery store, and you learn that a very popular national grocery...
Suppose you manage a local grocery store, and you learn that a very popular national grocery chain is about to open a store just a few miles away. Use the model of monopolistic competition to analyze the impact of this new store on the quantity of output your store should produce (Q) and the price your store should charge (P). What will happen to your profits? Please show graphically and explain your reasoning in detail. For example, how and why...
Suppose you manage a local grocery store, and you learn that a very popular national grocery...
Suppose you manage a local grocery store, and you learn that a very popular national grocery chain is about to open a store just a few miles away. Use the model of monopolistic competition to analyze the impact of this new store on the quantity of output your store should produce (Q) and the price your store should charge (P). What will happen to your profits? Please show graphically and explain your reasoning in detail. For example, how and why...
Suppose you manage a local grocery store, and you learn that a very popular national grocery...
Suppose you manage a local grocery store, and you learn that a very popular national grocery chain is about to open a store just a few miles away. Use the model of monopolistic competition to analyze the impact of this new store on the quantity of output your store should produce (Q) and the price your store should charge (P). What will happen to your profits? Please show graphically and explain your reasoning in detail. For example, how and why...
Suppose you manage a local grocery store and yo have learn that a popular national grocery...
Suppose you manage a local grocery store and yo have learn that a popular national grocery chain is about to open a store in your town a few miles away. Use model of monopolistic competition to analyze the impact of this new store on quantity of output should produce and your store should charge . Explain how opening of this new store affect your business, be asure to address what happen to your customers, supply demand and prices. what will...
Suppose you manage a local grocery store, and you learn that a very popular national grocery...
Suppose you manage a local grocery store, and you learn that a very popular national grocery chain (Whole Foods or Walmart) is about to open a store just a few miles away. Use the model of monopolistic competition to analyze the impact of this new store on the quantity of output your store should produce (Q) and the price your store should charge (P). What will happen to your profits? Please show graphically and explain your reasoning in detail. For...
Suppose you manage a local grocery store, and you learn that a very popular national grocery...
Suppose you manage a local grocery store, and you learn that a very popular national grocery chain is about to open a store just a few miles away. Use the model of monopolistic competition to analyze the impact of this new store on the quantity of output your store should produce (Q) and the price your store should charge (P). What will happen to your profits? Explain your reasoning in detail. How and why do profits change? What could you...
Grocery List Program Write a program that keeps track of the user's grocery list items. Prompt...
Grocery List Program Write a program that keeps track of the user's grocery list items. Prompt the user if they'd like to (each action is a function): See the list Display all items (if any) in the list Add item to their list Confirm with the user before adding item (y/n or yes/no) If they enter a duplicate item, notify them the item already exists Remove items from their list Confirm with the user before removing item (y/n or yes/no)...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT