The PrintMenu() isn't printing the correct output per the examples below. There is an issue with how it prints for tests 9 and 10 attached at the bottom and testing the print preview and print menu o is not outputted correctly. Please use my provided code.
Main.cpp
#include #include "ShoppingCart.h" #include "ItemToPurchase.h"
using namespace std;
void PrintMenu(ShoppingCart& cart);
int main() { string customerName; string currentDate; cout > option; cin.ignore(); if (option == 'a') { cout
cout
cout
cout > itemPrice;
cout > itemQuantity;
ItemToPurchase item(itemName, itemDescription, itemPrice, itemQuantity); cart.AddItem(item); } else if (option == 'd') { cout
cout
cart.RemoveItem(itemName); } else if (option == 'c') { cout
ItemToPurchase item;
cout
cout > itemQuantity;
item.SetName(itemName); item.SetQuantity(itemQuantity);
cart.ModifyItem(item); } else if (option == 'i') { cout
ShoppingCart.cpp
#include "ShoppingCart.h"
ShoppingCart::ShoppingCart() { customerName = "none"; currentDate = "January 1, 2016"; }
ShoppingCart::ShoppingCart(string name, string date) { customerName = name; currentDate = date; }
string ShoppingCart::GetCustomerName() { return customerName; }
string ShoppingCart::GetDate() { return currentDate; }
void ShoppingCart::AddItem(ItemToPurchase item) { cartItems.push_back(item); }
void ShoppingCart::RemoveItem(string iname) { bool found = false; int index = -1; for (vector::iterator itr = cartItems.begin(); itr != cartItems.end() && found == false; ++itr) { index++; if ((*itr).GetName() == iname) { found = true; } } if (found == false) { cout void ShoppingCart::ModifyItem(ItemToPurchase item) { bool found = false;
for (vector::iterator itr = cartItems.begin(); itr != cartItems.end() && found == false; ++itr) { if ((*itr).GetName() == item.GetName()) { found = true;
if (item.GetDescription() != "none") { (*itr).SetDescription(item.GetDescription()); }
if (item.GetPrice() != 0) { (*itr).SetPrice(item.GetPrice()); }
if (item.GetQuantity() != 0) { (*itr).SetQuantity(item.GetQuantity()); } } }
if (found == false) { cout
int ShoppingCart::GetNumItemsInCart() { int numItemsInCart = 0;
for (vector::iterator itr = cartItems.begin(); itr != cartItems.end(); ++itr) { numItemsInCart = numItemsInCart + (*itr).GetQuantity(); } return numItemsInCart; }
int ShoppingCart::GetCostOfCart() { int costOfCart = 0; for (vector::iterator itr = cartItems.begin(); itr != cartItems.end(); ++itr) { costOfCart = costOfCart + ((*itr).GetQuantity() * (*itr).GetPrice()); }
return costOfCart; }
void ShoppingCart::PrintTotal() { if (cartItems.empty()) { cout
for (vector::iterator itr = cartItems.begin(); itr != cartItems.end(); ++itr) { (*itr).PrintItemCost(); }
cout
void ShoppingCart::PrintDescriptions() { if (cartItems.empty()) { cout
cout
for (vector::iterator itr = cartItems.begin(); itr != cartItems.end(); ++itr) { (*itr).PrintItemDescription(); } } }
ItemToPurchase.cpp
#include "ItemToPurchase.h"
ItemToPurchase::ItemToPurchase() { itemName = "none"; itemDescription = "none"; itemPrice = 0; itemQuantity = 0; }
ItemToPurchase::ItemToPurchase(string iname, string idescription, int iprice, int iquantity) { itemName = iname; itemDescription = idescription; itemPrice = iprice; itemQuantity = iquantity; }
void ItemToPurchase::SetName(string iname) { itemName = iname; }
void ItemToPurchase::SetDescription(string idescription) { itemDescription = idescription; }
void ItemToPurchase::SetPrice(int iprice) { itemPrice = iprice; }
void ItemToPurchase::SetQuantity(int iquantity) { itemQuantity = iquantity; }
string ItemToPurchase::GetName() { return itemName; }
string ItemToPurchase::GetDescription() { return itemDescription; }
int ItemToPurchase::GetPrice() { return itemPrice; }
int ItemToPurchase::GetQuantity() { return itemQuantity; }
void ItemToPurchase::PrintItemCost() { cout
void ItemToPurchase::PrintItemDescription() { cout
This is where it is failing with outputs
This program extends the earlier "Online shopping cart' program. (Consider first saving your earlier program). (1) Extend the lemtoPurchase class per the following specifications: - Parameterized constructor to assign item name, item description, item price, and item quantity (default values of 0). (1 pt) - Public member functions - SetDescription() mutator & GetDescription0 accessor ( 2 pts) - Printitemcosto - Outputs the item name followed by the quantity. price, and subtotal - PrintitemDescription0-Outputs the item name and description - Private data members - string itemdescription - Initialized in default constructor to "none" Ex. of Printitemcost0 output: Dottled water 10$1$10 Ex of PrintitemDescription0 output: Bottled Water: Deer Park, 12 oz. (2) Create three new files: - ShoppingCarth- Class declaration - ShoppingCart cpp-Class definition - main.cpp - main0) function (Note: main0's functionality differs from the warm up) Bulld the ShoppingCart class with the following specifications. Note: Some can be function stubs (empty functions) initially, to be completed in later steps. - Default constructor - Parameterized constructor which takes the customer name and date as parameters (1 pt) Build the ShoppingCart class with the following specifications. Note: Some can be function stubs (empty functions) initially, to be completed in later steps. - Default constructor - Parameterized constructor which takes the customer name and date as parameters (1 pt) - Private data members - string customerName - Initialized in default constructor to "none" - string currentDate - Initialized in default constructor to "January 1, 2016" - vector > cartitems - Public member functions - GetCustomerName0 accessor (1 pt) - GetDate0 accessor (1 pt) - Additem0 - Adds an item to cartitems vector. Has a parameter of type ItemToPurchase. Does not return anything. - Removeltem0 - Removes item from cartltems vector. Has a string (an item's name) parameter. Does not return anything - If item name cannot be found, output this message: Iten not found in cart. Nothing removed. - Modifyltem0 - Modifies an item's description, price, and/or quantity. Has a parameter of type ItemToPurchase. Does not return anything. - If item can be found (by name) in cart, check if parameter has default values for description, price, and quantity. If not, modify item in cart. - If item cannot be found (by name) in cart, output this message: Item not found in cart. Nothing modified. - GetNumitemsinCarto (2 pts) - Returns quantity of all items in cart. Has no parameters. - GetCostofCart0 (2 pts) - Determines and returns the total cost of items in cart. Has no parameters. - Print Total0 - Outputs total of objects in cart. - If cart is empty, output this message: SHOPPING CART IS EMPTY - PrintDescriptions() - Outputs each item's description. Ex. of PrintTotal( output: John Doe's Shopping Cart - February 1, 2016 Number of Itemg: 8 Nike Romaleos 2 S189 - $378 Chocolate Chips 5$3$15 Powerbeats 2 Headphonea 18$128$128 Total: $521 Ex. of PrintDescriptions() output: John Doe's Shopping Cart - February 1, 2016 Item Deacriptiona Nike Romaleos: Volt color, Neightilfting ahoes Chocolate Chips: Semi-aweet Powerbeats 2 Headphones: Bluetooth headphones (3) In main0, prompt the user for a customer's name and todays date. Output the name and date. Create an object of type shoppingCart. (1 pt) Ex Enter cuatomer'a name: John Doe Enter today's date: February 1, 2016 Cuatomer name: John Doe Today's date: February 1, 2016 (4) Implement the PrintMenu0 function in main cpp to print the following menu of options to manipulate the shopping cart. (1 pt) Ex MENU a - Add iten to cart d - Remove item from cart c - Change item quantity i - Output items' descriptions - - Output shopping cart q - Quit (5) Implement the ExecuteMenu0 function in main.cpp that takes 2 parameters: a character representing the user's choice and the reference of a shopping cart. ExecuteMenu( performs the menu options described below, according to the user's choice. (1 pt) (6) In main0. call Printmenu0 and prompt for the user's choice of menu options. Each option is represented by a single character. If an invalid character is entered, continue to prompt for a valid choice. When a valid option is entered, execute the option by calling ExecuteMenu(0. Then, print the menu and prompt for a new option. Continue until the user enters ' q '. Hint: implement Quit before implementing other options. (1 pt) Ex MENU a - Rdd 1tem to cart d - Remove 1 tem from cart c - Change item quantity 1 - Output 1tems' descriptions - - output shopping cart q - Quit Choose an option: (7) Implement output shopping cart menu option in ExecuteMenu0. (3 pts) (7) Implement Output shopping cart menu option in ExecuteMenu0. ( 3 pts) Ex OUTPUT SHOPPING CART John Doe's Shopping Cart - February 1, 2016 Tumber of Itema: 8 Nike Romaleos 2 \$189 - \$378 Chocolate Chips 5$3$15 Powerbeats 2 Headphones 1 o $128$128 Total: $521 (8) Implement Output itern's description menu option in Executelenu(0. (2 pts) Ex OUTPUT ITENS' DESCRIPTIONS John Doe's shopping Cart - February 1, 2016 Item Deacriptions Nike Romaleos: Volt color, Neightlifting shoes Chocolate Chipa: semi-aweet Powerbeats 2 Headphones: Bluetooth headphones (9) Implement Add item to cart menu option in ExecuteMenu0). (3 pts) (9) Implement Add item to cart menu option in ExecuteMenu0. (3 pts) Ex ADD ITEM TO CART Enter the iten name: Nike Romaleos Enter the item description: Volt color, Weightlifting shoes Enter the item price: 189 Enter the item quantity: 2. (10) Implement remove item menu option in ExecuteMenu0. (4 pts) Ex REMOVE ITEM FRON CART Enter name of item to remove: Chocolate Chips (11) Implement Change item quantity menu option in ExecuteMenu0. Hint. Make new itemToPurchase object and use ItemToPurchase modifiers before using Modifyitem0 function. ( 5 pts) Ex CHANGE ITEM QUARTITY Enter the iten name: Nike Romaleos Enter the new quantity: 3 \#ifndef ITEMTOPURCHASE_H \#define ITEMTOPURCHASE_H \#include iostream> \#include string> using namespace std; // class declaration class ItemToPurchase \{ private: // data members string itemName; string itemDescription; int itemPrice; int itemQuantity; public: // constructors ItemToPurchase(); ItemToPurchase(string iname, string idescription, int iprice, int iquantity); void SetName(string iname); void SetDescription(string idescription); void SetPrice(int iprice); void SetQuantity(int iquantity); void PrintItemDescription(); string GetName(); 7:Unit testkeyboard arrow up 0/1 Test PrintMenu(). Should output the menu options. Compilation failed Compilation failed main.cpp: In function 'bool testpassed(std: of oftreams)': main.cpp:29:14: error: too few arguments to function 'void Printmenu (ShoppingCart \&)' 29 Printmenu(); main.cpp: 8:6: note: declared here 8 | void Printmenu (ShoppingCart \& cart); 8:Unit testkeyboard arrow up Test ExecuteMenu('o', myCart). Should output "OUTPUT SHOPPING CART John Doe's Shopping Cart - February 1, 2016 Number of Items: 0 SHOPPING CART IS EMPTY Total: \$0" Compilation failed Compilation failed main.cpp: In function 'bool testpassed(std::ofstream\&)' : main.cpp:32:4: error: 'Executemenu' was not declared in this scope 32 Executemenu(useroption, myCart); 9: Compare outputkeyboard arrow up 0/1 Output differs. See highlights below. Special character legend 9:Compare outputkeyboard arrow up 0/1 Output differs. See highlights below. Special character legend Input John Doe February 1, 2016 f s q Your output Enter customer's name: Enter today's date: Customer name: John Doe Today's date: February 1, 2016 MENU a - Add item to cart d - Remove item from cart c - Change item quantity i - output items' descriptions o - output shopping cart q - Quit Choose an option: Invalid option! MENU a - Add item to cart d - Remove item from cart c - Change item quantity i - Output items' descriptions o - output shopping cart q - Quit Choose an option: Invalid option! MENU a - Add item to cart d - Remove item from cart c - Change item quantity i - Output items' descriptions - - output shopping cart q - Quit Choose an option: Expected output Enter customer's name: Enter today's date: Customer name: John Doe Today's date: February 1, 2016 MENU a - Add item to cart d - Remove item from cart c - Change item quantity i - output items' descriptions - output shopping cart q - Quit Choose an option: Choose an option: Choose an option: 10:Compare outputkeyboard arrow yp 0/3 Output differs. See highlights below. Special character legend Input John Doe February 1, 2016 q Your output ends with name: Enter today's date: Customer name: John Doe Today's date: February 1, 2016 MENU a - Add item to cart d - Remove item from cart c - Change item quantity i - output items' descriptions - Output shopping cart q - Quit Choose an option: OUTPUT SHOPPING CART SHOPPING CART IS EMPTY MENU a - Add item to cart d - Remove item from cart c - Change item quantity i - output items' descriptions 0- output shopping cart q - Quit Choose an option: Expected output ends with OUTPUT SHOPPING CART John Doe's Shopping Cart - February 1, 2016 Number of Items: 0 SHOPPING CART IS EMPTY Total: $0 MENU a - Add item to cart d - Remove item from cart c - Change item quantity i - output items' descriptions o - output shopping cart q - Quit Choose an option