Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Having a hard time getting it to work. I was wondering if you could look at it and help me figure out the problems?? ItemToPurchase.cpp

Having a hard time getting it to work. I was wondering if you could look at it and help me figure out the problems??

image text in transcribed

ItemToPurchase.cpp

#include "ItemToPurchase.h" #include using namespace std;

//Default constructor ItemToPurchase::ItemToPurchase() { itemName = ""; itemDescription = "none"; itemPrice = 0; itemQuantity = 0; }

//parameterized constructor ItemToPurchase::ItemToPurchase(string name, string description, int price, int quantity) { itemName = name; itemPrice = price; itemQuantity = quantity; itemDescription = description; } //Implement methods accessors and mutators string ItemToPurchase::GetName() { return itemName; }

int ItemToPurchase::GetPrice() { return itemPrice; }

int ItemToPurchase::GetQuantity() { return itemQuantity; }

void ItemToPurchase::SetName(string name) { itemName = name; }

void ItemToPurchase::SetPrice(int price) { itemPrice = price; } void ItemToPurchase::SetQuantity(int quantity) { itemQuantity = quantity; } void ItemToPurchase::SetDescription(string item) { itemDescription = item; } string ItemToPurchase:: GetDescription() { return itemDescription; } //Implement output display methods void ItemToPurchase::PrintItemDescription() { cout

void ItemToPurchase::PrintItemCost() { cout

image text in transcribed

ShoppingCart.cpp

#include "ShoppingCart.h"

//Default constructor ShoppingCart::ShoppingCart() { customerName = "none"; currentDate = "January 1, 2016"; }

//parametrized constructor ShoppingCart::ShoppingCart(string name, string date) { customerName = name; currentDate = date; } //accessor methods string ShoppingCart::GetCustomerName() { return customerName; }

string ShoppingCart::GetDate() { return currentDate; }

//implement the method AddItem void ShoppingCart::AddItem(ItemToPurchase item) { this->cartItems.push_back(item); }

//implement the method RemoveItem void ShoppingCart::RemoveItem(string itemName) { for (int i = 0; i cartItems.at(i).GetName() == itemName) { this->cartItems.erase(cartItems.begin() + i); return; } } cout

//implement the method ModifyItem void ShoppingCart::ModifyItem(ItemToPurchase item) { for (int i = 0; i

//implement the method ModifyItem GetNumItemsInCart() int ShoppingCart::GetNumItemsInCart() { int numItems = 0; for (int i = 0; i

//implement the method ModifyItem GetCostOfCart() int ShoppingCart::GetCostOfCart() { int totalCost = 0; for (int i = 0; i

//implement the method ModifyItem PrintTotal() void ShoppingCart::PrintTotal() { cout

//implement the method ModifyItem PrintDescriptions() void ShoppingCart::PrintDescriptions() { cout

main.cpp

#include #include #include "ItemToPurchase.h" #include "ShoppingCart.h" using namespace std;

//implement AddItem void AddItem(ShoppingCart &cart) { ItemToPurchase addItem; string addItemName; string addItemDescription; int addItemPrice; int addItemQuantity; cout > addItemPrice; addItem.SetPrice(addItemPrice); cout > addItemQuantity; addItem.SetQuantity(addItemQuantity); cart.AddItem(addItem); }

//implement method RemoveItem() void RemoveItem(ShoppingCart &cart) { string removeItem;

cout

//implement method ChangeItemQuantity() void ChangeItemQuantity(ShoppingCart &cart) { string changeQuantityItem; int changeQuantityNumber; ItemToPurchase updateItem; cout > changeQuantityNumber; updateItem.SetQuantity(changeQuantityNumber); cart.ModifyItem(updateItem); }

//implement method OutputItemsDescriptions() void OutputItemsDescriptions(ShoppingCart cart, string customerName, string todaysDate) { cout

//implement method OutputShoppingCart() void OutputShoppingCart(ShoppingCart cart, string customerName, string todaysDate) { cout

//implement method PrintMenu() void PrintMenu(ShoppingCart cart) { //declare local variables string customerName; string todaysDate; char userOption = '1'; cout > userOption; if (cin.fail()) { cin.clear(); cin.ignore(1000, ' '); return; } cout

//declare main int main() { //Create object for the class Shopping cart ShoppingCart cart; //call the method with the object PrintMenu(cart); return 0; }

image text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribed

Current file: Item To Purchase.h 1 #ifndef ITEMTOPURCHASE H #define ITEMTOPURCHASE_H 4 #include 5 #include using namespace std; 9 //Declare class 10 class ItemToPurchase 11 12 public: 13 ItemToPurchase(); 14 //parameterized constructor ItemToPurchase(string, string, int, int); void SetName(string name); 17 string GetName(); void SetPrice(int price); int GetPrice(); void Set Quantity (int quantity); int GetQuantity(); 18 21 25 //Added methods in the class void Set Description(string); string GetDescription(); void PrintItemDescription(); void PrintItemCost(); 32 33 29 private: 30 //Declare local variables 31 string itemName; int itemPrice; int itemQuantity; 34 string itemDescription; 35 }; 35 Fendi Current file: Shopping Cart.h #include #include "ItemToPurchase.h" 3 #include 4 #include 6 using namespace std; 8 //declare class 9 class ShoppingCart 11 //declare data members 12 private: string customerName; string currentDate; vector cart Items; 18 19 public: //Declare member functions ShoppingCart(); ShoppingCart(string name, string date); string GetCustomerName(); string GetDate(); void AddItem(ItemToPurchase item); void RemoveItem(string itemName); void ModifyItem(ItemToPurchase item); int GetNumItemsInCart(); int GetcostofCart(); void Print Total(); void PrintDescriptions(); 31 28 30 8: Compare output A Output is nearly correct; but whitespace differs. See highlights below. Special character legend John Doe February 1, 2016 Input Enter customer's name: Enter today's date: Customer name: John Doe Today's date: February 1, 2016 Your output MENU a - Add item to cart d - Remove item from cart C - Change item quantity i - Output items' descriptions 0 - Output shopping cart a - Quit Choose an option: Choose an option: Choose an option: Enter customer's name: Enter today's date: Customer name: John Doe Today's date: February 1, 2016 Expected output MENU a - Add item to cart d - Remove item from cart C - Change item quantity i - Output items' descriptions 0 - Output shopping cart a - Quit Choose an option: Choose an option: Choose an option: 9: Compare output Output differs. See highlights below. Special character legend John Doe February 1, 2016 Input OUTPUT SHOPPING CART John Doe's Shopping Cart - February 1, 2016 Number of Items: 0 SHOPPING CART IS EMPTY Total: $0 Your output ends with 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: OUTPUT SHOPPING CART John Doe's Shopping Cart - February 1, 2016 Number of Items: 0 SHOPPING CART IS EMPTY Total: $0 Expected output ends with 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: 10: Compare output Output differs. See highlights below. Special character legend John Dee February 1, 2016 Nike Romaleos Voit color, treightlifting shoes Input ADD ITEM TO CART Enter the item name: Enter the item description: Enter the item price: Enter the item quantity: MENU : - Add item to CC d - RAM sten som ca - Change in quantity 1 - Output scena descriptions - - Output ahopping cart Choose an option: Your output ends OUTPUT SEOPPING CART John Dee's Shopping Cart - February 1, 2016 Nanber of Items: 2 Nike Ronales 2 8123 - 5378 Total: 5378 MENU : - Add item to cart d - Remove it on to cart - Change it an quantity 1 - Output stea' descriptions O-Output ahopping cart - Ost Choose an option: ADD TEX TO CARI Enter the item name: Enter the item description: Enter the item price: Enter the item quantity: MENO : - Add item to CC d - Remove iten en Cart - Change item quantity 1 - Output stana descriptions - - Output ahopping cart - Quit Expected output ends with Choose an option: OUTPUT SEOPPING CART John Dee's Shopping Cart - February 1, 2016 Numbes 6 Items: 2 Nike Fanaleca 2 5129 - $378 Total: 8378 MENU : - Add item to cart d - Ramov sten to cart - Change it en quantity 1 - Output steg deriptions 0 - Output Shopping cart Choose an option: 12: Compare output A Output differs. See highlights below. Speciel cherche legend John Dee February 1, 2016 Nike Ronale Voit color, treightlifting shoes Chocolate chipa Santa : Input O beats 2 Beadphones Bluetooth headphones Chocolate Chips REMOVE ITEM FROM CARI Ente: nane of item to reve: 3E : - Add item to cart d - Remove iten en Cart - Change ste quantity 1 - Output scena descriptions - - Output Shopping cart - Out Choose an option: Your output ends OUTPUT SHOPPING CART John Dee's Shopping Cart - February 1, 2016 Nike Romaleos 2 5129 - $378 Po beata 2 Headphones 1 8128 - $128 Total: 5506 3E : - Add item to cart d - Remove it on to cart - Change it an quantity 1 - Output scena descriptions - - Output Shopping cart 9 - Quit Choose an option: REMOVE ITEM FROM CARI Ente name of item to 2 : : - Add item to cart d - Remove it on to cart - Change ten quantity 1 - Output scena descriptions O-Output Shopping cart - Quit Choose an option: OUTPUT SEOPPING CART John Doe's Shopping Cart - February 1, 2016 Number of Items: 3 Expected output ends with NKR Ronales 2 5189 - $378 Pobeats 2 Headphones 1 5122 - 6128 Total 850E MENU - Add item to cart 12: Compare Output A Output differs. See highlights below. Speciel cherche legend John Dee February 1, 2016 NKR Ronales Voit coide, tightlifting shoes 189 Chocolate chips Input Powerbeats 2 Headphones Bluetooth headphones Thermos Stainless Steel King CHANCE TREM QUANTITY Enter the item name: Ente: the ne quantity: Item not found in caet. Nothing moditie. Your output ends MENU - Add Icam to cart d - Remove it from ca: - Change in quantity 1 - Output steg deriptions - - Output Shopping cart Choose an option: CHANGE ITEM QUANTITY Enter the item name: Enter the na quantity: Item not found in cart. Nothing modidied. Expected output ends with MENU - Add Icam to cart d - Remove it on to cart - Change it an quantity 1 - Output stana descriptions O-Output Shopping cart - Quit Choose an option: John Doe February 1, 2016 NKR Ronales Voit color, tightlifting shoes Chocolate chips Sense Input PODATA 2 Headphones Bluetooth headphones Today's date: February 1, 2016- MEND 2 - A Scom to cat- 4 - Remate iten en cast- - - Change iten geantity 1 - Outpat itens' descripcions 0 - Outpat shopping cart- - Quit Choose an option: ADD ITEN TO CARTH Enter the item name: Enter the item Acription: Enter the icon price: Enter the icon Quantity:- MEND- a - Add to cart- 4 - Remate iten en cast- - Change iten quantity 1 - Output itens descriptions 0 - Outpat shopping cart- - Quit- Choose an option: ADD ITEM TO CARTH Enter the item name: Enter the icon description: Enter the icon price: Enter the itan quantity: Your output ends with YEND- - Add to cart 4 - Remove iten en cat- - Change iten quantity 1 - Outpat itens' descriptions - Outpat shopping east- - Quit- Choose an option: ADD ITEM TO CART Enter the ta name: Enter the icon description: Enter the price: Enter the con quantity: MENU- : - Add to cart d - Remove item son cat- - - Change iten geantity 1 - Output itens descriptions - Output shopping cast- - Quit- Choose an option: OUTSUI SEOPPING CARE John Doe's Shopping Cart - February 1, 2015 Item Decriptions Nike Ronales: Voit colos, Weightlifting shoes CHANTARA SOARE Your output ends MENU- - AAA Scom to cart 4 - Amoeiten un cast- - Change item quantity 1 - Output items' descriptions - - Output Shopping cart - Quit- Choose an option: ADD ITEM TO CARTH Enter the item name: Enter the iten description: Enter the in price: Enter the itan quantity: - Add to cart - Remove item un cast- - Change iten quantity 1 - Output itona' description - Output Shopping cart - Quit Choose an option: OUTPUT SEOPPING CARS John Dee's Shopping Cart - February 3, 2016 Item Descriptions Nike Romaleoa: Voit color, Weightlifting shoes Chocolate chips: Semi-aut Pobata 2 Headphones Bluetooth headphones : - Add item to cart d - Remove it on to cart - Change in quantity 1 - Output scena descriptions - Output ahopping cart Choose an option: OUTPUT ITEMS' DESCRIPTIONS John Doe'Shopping Cart - February 1, 2016 Item Descriptions Nike Ronal : Voit color, Weightlifting shoes Chocolate Chipar Semi- Pobata 2 Headphones Bluetooth headphones Expected output ends with MENU - Add item to cart d - Remove it from ca: - Change scan quantity 1 - Output stana descriptions - - Output Shopping cart Choose an option: Current file: Item To Purchase.h 1 #ifndef ITEMTOPURCHASE H #define ITEMTOPURCHASE_H 4 #include 5 #include using namespace std; 9 //Declare class 10 class ItemToPurchase 11 12 public: 13 ItemToPurchase(); 14 //parameterized constructor ItemToPurchase(string, string, int, int); void SetName(string name); 17 string GetName(); void SetPrice(int price); int GetPrice(); void Set Quantity (int quantity); int GetQuantity(); 18 21 25 //Added methods in the class void Set Description(string); string GetDescription(); void PrintItemDescription(); void PrintItemCost(); 32 33 29 private: 30 //Declare local variables 31 string itemName; int itemPrice; int itemQuantity; 34 string itemDescription; 35 }; 35 Fendi Current file: Shopping Cart.h #include #include "ItemToPurchase.h" 3 #include 4 #include 6 using namespace std; 8 //declare class 9 class ShoppingCart 11 //declare data members 12 private: string customerName; string currentDate; vector cart Items; 18 19 public: //Declare member functions ShoppingCart(); ShoppingCart(string name, string date); string GetCustomerName(); string GetDate(); void AddItem(ItemToPurchase item); void RemoveItem(string itemName); void ModifyItem(ItemToPurchase item); int GetNumItemsInCart(); int GetcostofCart(); void Print Total(); void PrintDescriptions(); 31 28 30 8: Compare output A Output is nearly correct; but whitespace differs. See highlights below. Special character legend John Doe February 1, 2016 Input Enter customer's name: Enter today's date: Customer name: John Doe Today's date: February 1, 2016 Your output MENU a - Add item to cart d - Remove item from cart C - Change item quantity i - Output items' descriptions 0 - Output shopping cart a - Quit Choose an option: Choose an option: Choose an option: Enter customer's name: Enter today's date: Customer name: John Doe Today's date: February 1, 2016 Expected output MENU a - Add item to cart d - Remove item from cart C - Change item quantity i - Output items' descriptions 0 - Output shopping cart a - Quit Choose an option: Choose an option: Choose an option: 9: Compare output Output differs. See highlights below. Special character legend John Doe February 1, 2016 Input OUTPUT SHOPPING CART John Doe's Shopping Cart - February 1, 2016 Number of Items: 0 SHOPPING CART IS EMPTY Total: $0 Your output ends with 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: OUTPUT SHOPPING CART John Doe's Shopping Cart - February 1, 2016 Number of Items: 0 SHOPPING CART IS EMPTY Total: $0 Expected output ends with 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: 10: Compare output Output differs. See highlights below. Special character legend John Dee February 1, 2016 Nike Romaleos Voit color, treightlifting shoes Input ADD ITEM TO CART Enter the item name: Enter the item description: Enter the item price: Enter the item quantity: MENU : - Add item to CC d - RAM sten som ca - Change in quantity 1 - Output scena descriptions - - Output ahopping cart Choose an option: Your output ends OUTPUT SEOPPING CART John Dee's Shopping Cart - February 1, 2016 Nanber of Items: 2 Nike Ronales 2 8123 - 5378 Total: 5378 MENU : - Add item to cart d - Remove it on to cart - Change it an quantity 1 - Output stea' descriptions O-Output ahopping cart - Ost Choose an option: ADD TEX TO CARI Enter the item name: Enter the item description: Enter the item price: Enter the item quantity: MENO : - Add item to CC d - Remove iten en Cart - Change item quantity 1 - Output stana descriptions - - Output ahopping cart - Quit Expected output ends with Choose an option: OUTPUT SEOPPING CART John Dee's Shopping Cart - February 1, 2016 Numbes 6 Items: 2 Nike Fanaleca 2 5129 - $378 Total: 8378 MENU : - Add item to cart d - Ramov sten to cart - Change it en quantity 1 - Output steg deriptions 0 - Output Shopping cart Choose an option: 12: Compare output A Output differs. See highlights below. Speciel cherche legend John Dee February 1, 2016 Nike Ronale Voit color, treightlifting shoes Chocolate chipa Santa : Input O beats 2 Beadphones Bluetooth headphones Chocolate Chips REMOVE ITEM FROM CARI Ente: nane of item to reve: 3E : - Add item to cart d - Remove iten en Cart - Change ste quantity 1 - Output scena descriptions - - Output Shopping cart - Out Choose an option: Your output ends OUTPUT SHOPPING CART John Dee's Shopping Cart - February 1, 2016 Nike Romaleos 2 5129 - $378 Po beata 2 Headphones 1 8128 - $128 Total: 5506 3E : - Add item to cart d - Remove it on to cart - Change it an quantity 1 - Output scena descriptions - - Output Shopping cart 9 - Quit Choose an option: REMOVE ITEM FROM CARI Ente name of item to 2 : : - Add item to cart d - Remove it on to cart - Change ten quantity 1 - Output scena descriptions O-Output Shopping cart - Quit Choose an option: OUTPUT SEOPPING CART John Doe's Shopping Cart - February 1, 2016 Number of Items: 3 Expected output ends with NKR Ronales 2 5189 - $378 Pobeats 2 Headphones 1 5122 - 6128 Total 850E MENU - Add item to cart 12: Compare Output A Output differs. See highlights below. Speciel cherche legend John Dee February 1, 2016 NKR Ronales Voit coide, tightlifting shoes 189 Chocolate chips Input Powerbeats 2 Headphones Bluetooth headphones Thermos Stainless Steel King CHANCE TREM QUANTITY Enter the item name: Ente: the ne quantity: Item not found in caet. Nothing moditie. Your output ends MENU - Add Icam to cart d - Remove it from ca: - Change in quantity 1 - Output steg deriptions - - Output Shopping cart Choose an option: CHANGE ITEM QUANTITY Enter the item name: Enter the na quantity: Item not found in cart. Nothing modidied. Expected output ends with MENU - Add Icam to cart d - Remove it on to cart - Change it an quantity 1 - Output stana descriptions O-Output Shopping cart - Quit Choose an option: John Doe February 1, 2016 NKR Ronales Voit color, tightlifting shoes Chocolate chips Sense Input PODATA 2 Headphones Bluetooth headphones Today's date: February 1, 2016- MEND 2 - A Scom to cat- 4 - Remate iten en cast- - - Change iten geantity 1 - Outpat itens' descripcions 0 - Outpat shopping cart- - Quit Choose an option: ADD ITEN TO CARTH Enter the item name: Enter the item Acription: Enter the icon price: Enter the icon Quantity:- MEND- a - Add to cart- 4 - Remate iten en cast- - Change iten quantity 1 - Output itens descriptions 0 - Outpat shopping cart- - Quit- Choose an option: ADD ITEM TO CARTH Enter the item name: Enter the icon description: Enter the icon price: Enter the itan quantity: Your output ends with YEND- - Add to cart 4 - Remove iten en cat- - Change iten quantity 1 - Outpat itens' descriptions - Outpat shopping east- - Quit- Choose an option: ADD ITEM TO CART Enter the ta name: Enter the icon description: Enter the price: Enter the con quantity: MENU- : - Add to cart d - Remove item son cat- - - Change iten geantity 1 - Output itens descriptions - Output shopping cast- - Quit- Choose an option: OUTSUI SEOPPING CARE John Doe's Shopping Cart - February 1, 2015 Item Decriptions Nike Ronales: Voit colos, Weightlifting shoes CHANTARA SOARE Your output ends MENU- - AAA Scom to cart 4 - Amoeiten un cast- - Change item quantity 1 - Output items' descriptions - - Output Shopping cart - Quit- Choose an option: ADD ITEM TO CARTH Enter the item name: Enter the iten description: Enter the in price: Enter the itan quantity: - Add to cart - Remove item un cast- - Change iten quantity 1 - Output itona' description - Output Shopping cart - Quit Choose an option: OUTPUT SEOPPING CARS John Dee's Shopping Cart - February 3, 2016 Item Descriptions Nike Romaleoa: Voit color, Weightlifting shoes Chocolate chips: Semi-aut Pobata 2 Headphones Bluetooth headphones : - Add item to cart d - Remove it on to cart - Change in quantity 1 - Output scena descriptions - Output ahopping cart Choose an option: OUTPUT ITEMS' DESCRIPTIONS John Doe'Shopping Cart - February 1, 2016 Item Descriptions Nike Ronal : Voit color, Weightlifting shoes Chocolate Chipar Semi- Pobata 2 Headphones Bluetooth headphones Expected output ends with MENU - Add item to cart d - Remove it from ca: - Change scan quantity 1 - Output stana descriptions - - Output Shopping cart Choose an option

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions