Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

C++ My code is at the bottom. I'm passing some of the test cases, but not all of them. I'm not sure what I need

C++ My code is at the bottom. I'm passing some of the test cases, but not all of them. I'm not sure what I need to change.

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

---------------------------------------------------------------------------------------main.cpp-------------------------------------------------

#include #include using namespace std;

#include "ShoppingCart.h"

void PrintMenu() { /* Type your code here */ cout

void ExecuteMenu(char option, ShoppingCart& cart) { string iname, idescription; int iprice, iquantity; if (option == 'q') { return;} else { cout

switch(option) {

case 'a': { cout > iprice; cout > iquantity; ItemToPurchase item(iname, idescription, iprice,iquantity); cart.AddItem(item); break; } case 'd': { cout > iquantity; item.SetName(iname); item.SetQuantity(iquantity); cart.ModifyItem(item); break;} case 'i': { cout

int main() { /* Type your code here */ string cname, cdate; char option; cout

cin >> option; ExecuteMenu(option, cart); return 0;}

--------------------------------------------------------------------ShoppingCart.cpp---------------------------------------------------

/* Type your code here */ #include #include "ShoppingCart.h"

ShoppingCart::ShoppingCart(){ this->customerName = "none"; this->currentDate = "January 1, 2016"; } ShoppingCart::ShoppingCart(string name, string date){ this->customerName = name; this->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 item_name){ bool found = false; int index = -1; for (vector::iterator itr = cartItems.begin(); itr != cartItems.end() && found == false;itr++) { index++; if ((*itr).GetName() == item_name) found = true; } if (found == false) cout

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 ::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

cout

for (vector::iterator itr = cartItems.begin(); itr != cartItems.end(); ++itr) { (*itr).PrintItemDescription(); } } }

--------------------------------------------------------------ShoppingCart.h--------------------------------------------------------

/* Type your code here */ #ifndef SHOPPINGCART_H #define SHOPPINGCART_H

#include "ItemToPurchase.h" #include

class ShoppingCart { private: string customerName, currentDate; vector cartItems; public: ShoppingCart(); ShoppingCart(string name, string date); string GetCustomerName(); string GetDate(); void AddItem(ItemToPurchase item); void RemoveItem(string item_name); void ModifyItem(ItemToPurchase item); int GetNumItemsInCart(); int GetCostOfCart(); void PrintTotal(); void PrintDescriptions(); }; #endif // SHOPPINGCART_H

---------------------------------------------------------ItemToPurchase.cpp---------------------------------------------------

#include using namespace std;

#include "ItemToPurchase.h"

ItemToPurchase::ItemToPurchase(){ this->itemName = "none"; this->itemPrice = 0; this->itemQuantity = 0; } ItemToPurchase::ItemToPurchase(string name, string description, int price, int quantity){ this->itemName = name; this->itemDescription = description; this->itemPrice = price; this->itemQuantity = quantity; } void ItemToPurchase::SetName(string name){ this->itemName = name; } string ItemToPurchase::GetName(){ return itemName; } void ItemToPurchase::SetPrice(int price){ this->itemPrice = price; } int ItemToPurchase::GetPrice(){ return itemPrice; } void ItemToPurchase::SetQuantity(int quantity){ this->itemQuantity = quantity; } int ItemToPurchase::GetQuantity(){ return itemQuantity; } void ItemToPurchase::SetDescription(string description){ this->itemDescription = description; } string ItemToPurchase::GetDescription(){ return itemDescription; } void ItemToPurchase::PrintItemCost(){ cout

----------------------------------------------------------ItemToPurchase.h--------------------------------------------------------------------

#ifndef ITEM_TO_PURCHASE_H #define ITEM_TO_PURCHASE_H

#include using namespace std;

class ItemToPurchase { public: ItemToPurchase(); ItemToPurchase(string name, string description, int price, int quantity); void SetName(string name); string GetName(); void SetPrice(int price); int GetPrice(); void SetQuantity(int quantity); int GetQuantity(); void SetDescription(string description); string GetDescription(); void PrintItemCost(); void PrintItemDescription(); private: string itemName, itemDescription; int itemPrice, itemQuantity; };

#endif

3.28 LAB*: Program: Online shopping cart (Part 2) This program extends the earlier "Online shopping cart" program. (Consider first saving your earlier program). (1) Extend the ItemToPurchase 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 o SetDescription() mutator & GetDescription accessor (2 pts) PrintItemCost() - Outputs the item name followed by the quantity, price, and subtotal o Printltem Description() - Outputs the item name and description . Private data members o string item Description - Initialized in default constructor to "none" Ex. of PrintItemCost output: Bottled Water 10 @ $1 = $10 Ex. of PrintItem Description() output: Bottled Water: Deer Park, 12 oz. (2) Create three new files: . Shopping Carth-Class declaration Shopping Cart.cpp - Class definition main.cpp - main() function (Note: main)'s functionality differs from the warm up) Build the Shopping Cart 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 o string customerName - Initialized in default constructor to "none" o string currentDate - Initialized in default constructor to "January 1, 2016" o vector cartItems Public member functions o GetCustomerName() accessor (1 pt) o GetDate() accessor (1 pt) o Additem Adds an item to cartitems vector. Has parameter Item ToPurchase. Does not return anything. o Removeltem Removes item from cartitems vector. Has a string (an item's name) parameter. Does not return anything. If item name cannot be found output this message: Item not found in Not removed. o Modifyltem Modifies an item's description, price, and/or quantity. Has parameter Item ToPurchase. 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. o GetNumltemsInCarto (2 pts) Returns quantity of all items in cart. Has no parameters. o GetCostOfCart0 (2 pts) Determines and returns the total cost of items in cart. Has no parameters. o Print Total Outputs total of objects in cart. If cart is empty, output this message: SHOPPING CART IS EMPTY o PrintDescriptions Outputs each item's description. Ex. of Print Total output: John Doe's Shopping Cart - February 1, 2016 Number of Items : 8 Nike Romaleos 2 @ $189 = $378 Chocolate chips 5 @ $3 = $15 Powerbeats 2 Headphones 1 @ $128 = $128 Total: $ 521 Ex. of PrintDescriptions() output: John Doe's Shopping Cart - February 1, 2016 Item Descriptions Nike Romaleos: Volt color, Weightlifting shoes Chocolate Chips: Semi-sweet Powerbeats 2 Headphones: Bluetooth headphones (3) In main, prompt the user for a customer's name and today's date. Output the name and date. Create an object of type Shopping Cart (1 pt) Ex: Enter customer's name: John Doe Enter today's date: February 1, 2016 Customer name: John Doe Today's date: February 1, 2016 (4) Implement the PrintMenu() function in main.cpp to print the following menu of options to manipulate the shopping cart. (1 pt) Ex: 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 (5) Implement the ExecuteMenu() function in main.cpp that takes 2 parameters: a character representing the user's choice and the reference of a shopping cart. ExecuteMenuo performs the menu options described below, according to the user's choice. (1 pt) (6) In main(), call PrintMenu() 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(). 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 - Add item to cart d - Remove item from cart - Change item quantity i - Output items' descriptions Output shopping cart o q - Quit Choose an option: (7) Implement Output shopping cart menu option in ExecuteMenu(). (3 pts) Ex: OUTPUT SHOPPING CART John Doe's Shopping Cart - February 1, 2016 Number of Items: 8 Nike Romaleos 2 @ $189 = $378 Chocolate Chips 5 @ $3 = $15 Powerbeats 2 Headphones 1 @ $128 = $128 Total: $521 (8) Implement Output item's description menu option in ExecuteMenu0. (2 pts) Ex: OUTPUT ITEMS' DESCRIPTIONS John Doe's Shopping Cart February 1, 2016 Item Descriptions Nike Romaleos: Volt color, Weightlifting shoes Chocolate chips: Semi-sweet Powerbeats 2 Headphones: Bluetooth headphones (9) Implement Add item to cart menu option in Execute Menu0. (3 pts) Ex: ADD ITEM TO CART Enter the item 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 ExecuteMenu(). (4 pts) Ex: REMOVE ITEM FROM CART Enter name of item to remove: Chocolate Chips (11) Implement Change item quantity menu option in ExecuteMenu. Hint: Make new Item To Purchase object and use Item ToPurchase modifiers before using Modifyltem() function. (5 pts) Ex: CHANGE ITEM QUANTITY Enter the item name: Nike Romaleos Enter the new quantity: 3

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_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

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

Get Started

Recommended Textbook for

Data Analysis In Microsoft Excel

Authors: Alex Holloway

1st Edition

B0CCCPKTTX, 979-8852388452

More Books

Students also viewed these Databases questions

Question

What are some of Samsungs greatest competitive strengths?

Answered: 1 week ago