Below is the complete code as per the requirements. It is well explained inside the code using comments.
#include <iostream>
#include <vector>
#include <string>
using namespace std;
// prints the vector
void print(vector<string> shoppingList)
{
cout << endl;
for (vector<string>::const_iterator i =
shoppingList.begin(); i != shoppingList.end(); ++i)
{
cout << *i << "
";
}
cout << endl;
}
// main function
int main()
{
// create a vector of string
vector<string> shoppingList;
// print is it is empty
if (shoppingList.empty())
{
cout << "Shopping List is
empty" << endl;
}
// append items
cout << endl << "Adding Items. . ."
<< endl;
shoppingList.push_back("eggs");
shoppingList.push_back("milk");
shoppingList.push_back("sugar");
shoppingList.push_back("chocolate");
shoppingList.push_back("flour");
cout << "Items added." <<
endl;
// print the list
print(shoppingList);
// remove last element from vector and
print it
shoppingList.pop_back();
cout << "Last element removed." <<
endl;
print(shoppingList);
// append "coffee" and print it
shoppingList.push_back("coffee");
cout << "Coffee added." << endl;
print(shoppingList);
// search for "sugar" and replace it with
"honey"
vector<string>::iterator it =
find(shoppingList.begin(), shoppingList.end(), "sugar");
int pos = distance(shoppingList.begin(), it);
shoppingList.at(pos) = "honey";
cout << "sugar replaced with honey" <<
endl;
print(shoppingList);
// clear the vector
shoppingList.clear();
cout << "Shopping list cleared." <<
endl;
// print is it is empty
if (shoppingList.empty())
{
cout << "Shopping List is
empty" << endl;
}
return 0;
}
Below is the sample output:
This completes the requirement. Let me know if you have any queries.
Thanks!
Write in c++ please Imagine you are writing a program to manage a shopping list. Each...
Write in C++: Please create a shopping list using the STL list container, then follow the following instructions. Create an empty list. Append the items, "eggs," "milk," "sugar," "chocolate," and "flour" to the list. Print the list. Remove the first element from the list. Print the list. Insert the item, "coffee" at the beginning of the list. Print the list. Find the item, "sugar" and replace it with "honey." Print the list. Insert the item, "baking powder" before "milk" in...
Q1 (2 pts) Shopping list Write a program that prompts a user for items on their shopping list and keeps prompting the user until they enter "Done" (make sure your program can stop even if the user enters "Done" with different cases, like "done"), then prints out the items in the list, line by line, and prints the total number of items on the shopping list. Output (after collecting items in the while loop) should look something like this: Apple...
C++ language Shopping Cart You are to write a program that reads the name of the item, the quantity of each item, and the cost per item from a file. The program will then print out the item and how much is owed for each item. After everything is read in, it will print out the total cost of the cart. Your program should have the following functions main - This function asks the user to enter a filename and...
A specific question I have on this project is how do I make the stars all align into making a box. Whenever I post this question the stars on the right edge go in towards the item of the shopping list. I need the starts to create a a box around the shopping items. Instructions: Using Python write a program that allows a user to create and use a shopping list. Your program will display a menu of options to...
Write a program in Python that finds the index of an item in a list. For example: You create a of list of colors You find the index of the color "red" Print the list and the index of "red" Your program should work for every item in your list, and it must have at least 3 items in the list. It must also work if you search for an item and it does not exist in the list. You...
Assignment: Write a program in C++ that allows a customer to go on-line shopping. This is a start-up venture and the stock of our on-line company is currently limited to the following items: A gift card to Home Depot, $50.00 A bottle of cologne (The One by Dolce Gabbana), $24.00 3. Akeychainwithabathtubornament,$14.00 4. Acard,$4.00 Although all items are in stock, the customer should only be made aware of the items that he or she can afford. In addition, demand for...
Write a Python program (remove_first_char.py) that removes the first character from each item in a list of words. Sometimes, we come across an issue in which we require to delete the first character from each string, that we might have added by mistake and we need to extend this to the whole list. Having shorthands (like this program) to perform this particular job is always a plus. Your program should contain two functions: (1) remove_first(list): This function takes in a...
7.11 LAB: Online shopping cart - Part 2 This program extends the earlier "Online shopping cart" program. (Consider first saving your earlier program). (1) Extend the ItemToPurchase namedtuple to contain a new attribute. (2 pts) item_description (string) - Set to "none" in the construct_item() function Implement the following function with an ItemToPurchase as a parameter. print_item_description() - Prints item_name and item_description attribute for an ItemToPurchase namedtuple. Has an ItemToPurchase parameter. Ex. of print_item_description() output: Bottled Water: Deer Park, 12 oz....
11.12 LAB*: Program: Online shopping cart (continued)This program extends the earlier "Online shopping cart" program. (Consider first saving your earlier program).(1) Extend the ItemToPurchase class to contain a new attribute. (2 pts)item_description (string) - Set to "none" in default constructorImplement the following method for the ItemToPurchase class.print_item_description() - Prints item_description attribute for an ItemToPurchase object. Has an ItemToPurchase parameter.Ex. of print_item_description() output:Bottled Water: Deer Park, 12 oz.(2) Build the ShoppingCart class with the following data attributes and related methods. Note: Some can be method stubs...
Write a program that incorporates these functions and statements: • list • while loop • for loop • if • print() • input() • concatenation This program must create a grocery shopping list based on the user input • the program will ask a user to enter a new grocery item until the user presses Enter • then all user input will be added to a list • then the list with all grocery items will be printed