In this program you will be building a GroceryList class that simulates checking out at a grocery store. Your class will support adding items to the grocery list (think of scanning an item at the...

In this program you will be building a GroceryList class that simulates checking out at a grocery store. Your class will support adding items to the grocery list (think of scanning an item at the checkout), as well as a function that will get a receipt (an array of strings listing each distinct item that was checked out, and how many times that specific item was added.) Start with the checkout.cpp file provided on canvas. Without changing the provided main function, write a c++ class that works with the existing main() function that simulates checking out at a grocery store. You will want to carefully consider what functions are needed for the provided main class to work. Ensure that you class makes the provided main() output match the examples exactly. The add() function should add a checkout item to the items being bought, either increasing the amount by one if the item is already present or adding it to the list if it is new. You may directly compare strings when adding, thus if the string is different at all it can be treated as a new item. The checkout() function should return a list of all items and their quantities, along with a final additional line saying how many items were bought. Note that the item bought is the sum of the quantities, not the amount of different types of items on the list. The order that you display the items is not important (but the order the examples use is probably the easiest to do). Some assumptions you can make to simplify this problem: 1. You can assume fewer than 200 items will be checked out. 2. You shouldn’t need to implement a destructor, copy constructor, or assignment operator for this assignment. (one or more non-dynamic arrays will be sufficient) Hints • There are several ways to make the GroceryList class work. • You do not need to limit yourself to only the functions, methods, and classes required to make main work. Writing some helper functions, or even a helper class, can make this problem easier to solve. • An easy way to make a string piece by piece in C++ (such as the receipt string, which contains multiple pieces of information) is to use the overloaded + or += string operators. These operators, with strings, allow you to combine strings. To add a number into a string you will first need to use the to_string function to convert that number into a string. (This function should exist for any reasonably up-to-date C++ version) Example: string x = " " ; x += to_string (2); x += " x Apples " ; cout < x ; // shows "2 x apples " 3examples example 1 apple banana apple !checkout receipt: 2x apple 1x banana --------- total items: 3 example 2 apple banana apple checkout !checkout receipt: 1x apple 1x banana 1x apple 1x checkout ----------- total items: 4 4example 3 pasta milk pasta milk rice milk rice milk !checkout receipt: 2x pasta 4x milk 2x rice -------- total items: 8 x="" ;="" shows="" "2="" x="" apples="" "="" 3examples="" example="" 1="" apple="" banana="" apple="" !checkout="" receipt:="" 2x="" apple="" 1x="" banana="" ---------="" total="" items:="" 3="" example="" 2="" apple="" banana="" apple="" checkout="" !checkout="" receipt:="" 1x="" apple="" 1x="" banana="" 1x="" apple="" 1x="" checkout="" -----------="" total="" items:="" 4="" 4example="" 3="" pasta="" milk="" pasta="" milk="" rice="" milk="" rice="" milk="" !checkout="" receipt:="" 2x="" pasta="" 4x="" milk="" 2x="" rice="" --------="" total="" items:="">
Apr 20, 2021
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here