SlideShare a Scribd company logo
I finished most of the program, but having trouble with some key features. I bolded and italicized
the parts I can't figure out, and included them below. I included my code at the bottom. Thanks!
1. I can't get my RemoveItem() and ModifyItem() functions to work.
2. GetNumItemsInCart() is returning the wrong value. For example, my cart has 5 chocolate chip
cookies, 1 headphone, and 2 sneakers. GetNumItemsInCart() returns 3 instead of 8 when I output
my shopping cart.
3. When PrintDescriptions() is called, the first letter of my item description is missing. For
example, for the chocolate chip cookies, the description is Semi-sweet. When PrintDescriptions()
is called, it returns emi-sweet, with the S gone.
4. Shopping Cart improperly initialized with default constructor , and I don't know why.
12.9 Program: Online shopping cart (continued) (C++)
This program extends the earlier "Online shopping cart" 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
SetDescription() mutator & GetDescription() accessor (2 pts)
PrintItemCost() - Outputs the item name followed by the quantity, price, and subtotal
PrintItemDescription() - Outputs the item name and description
Private data members
string itemDescription - Initialized in default constructor to "none"
Ex. of PrintItemCost() output:
Ex. of PrintItemDescription() output:
(2) Create three new files:
ShoppingCart.h - Class declaration
ShoppingCart.cpp - Class definition
main.cpp - main() function (Note: main()'s functionality differs from the warm up)
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 < ItemToPurchase > cartItems
Public member functions
GetCustomerName() accessor (1 pt)
GetDate() accessor (1 pt)
AddItem()
Adds an item to cartItems vector. Has parameter ItemToPurchase. Does not return anything.
RemoveItem()
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 cart. Nothing removed.
ModifyItem()
Modifies an item's description, price, and/or quantity. Has parameter 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.
GetNumItemsInCart() (2 pts)
Returns quantity of all items in cart. Has no parameters.
GetCostOfCart() (2 pts)
Determines and returns the total cost of items in cart. Has no parameters.
PrintTotal()
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:
Ex. of PrintDescriptions() output:
(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 ShoppingCart. (1 pt)
Ex.
(4) Implement the PrintMenu() function. PrintMenu() has a ShoppingCart parameter, and
outputs a menu of options to manipulate the shopping cart. Each option is represented by a single
character. Build and output the menu within the function.
If the an invalid character is entered, continue to prompt for a valid choice. Hint: Implement Quit
before implementing other options. Call PrintMenu() in the main() function. Continue to execute
the menu until the user enters q to Quit. (3 pts)
Ex:
(5) Implement Output shopping cart menu option. (3 pts)
Ex:
(6) Implement Output item's description menu option. (2 pts)
Ex.
(7) Implement Add item to cart menu option. (3 pts)
Ex:
(8) Implement remove item menu option. (4 pts)
Ex:
(9) Implement Change item quantity menu option. Hint: Make new ItemToPurchase object and
use ItemToPurchase modifiers before using ModifyItem() function. (5 pts)
Ex:
My Program:
ItemToPurchase.h
#ifndef ITEMTOPURCHASE_H
#define ITEMTOPURCHASE_H
#include
#include
using namespace std;
class ItemToPurchase {
public:
ItemToPurchase();
ItemToPurchase(string itemName, double itemPrice, int itemQuantity, string
itemDescription);
void SetName(string itemName);
void SetPrice(double itemPrice);
void SetQuantity(int itemQuantity);
void SetDescription(string itemDescription);
string GetName();
double GetPrice();
int GetQuantity();
string GetDescription();
void PrintItemCost();
void PrintItemDescription();
private:
string itemName;
double itemPrice;
int itemQuantity;
string itemDescription;
};
#endif
ItemToPurchase.cpp
#include
#include
#include "ItemToPurchase.h"
using namespace std;
ItemToPurchase::ItemToPurchase() {
itemName = "NoName";
itemPrice = 0.0;
itemQuantity = 0;
itemDescription = "NoDescription";
return;
}
ItemToPurchase::ItemToPurchase(string itemName, double itemPrice, int itemQuantity, string
itemDescription) {
SetName(itemName);
SetPrice(itemPrice);
SetQuantity(itemQuantity);
SetDescription(itemDescription);
return;
}
void ItemToPurchase::SetName(string item_Name) {
itemName = item_Name;
return;
}
void ItemToPurchase::SetPrice(double item_Price) {
itemPrice = item_Price;
return;
}
void ItemToPurchase::SetQuantity(int item_Quantity) {
itemQuantity = item_Quantity;
return;
}
void ItemToPurchase::SetDescription(string item_Description) {
itemDescription = item_Description;
return;
}
string ItemToPurchase::GetName() {
return itemName;
}
double ItemToPurchase::GetPrice() {
return itemPrice;
}
int ItemToPurchase::GetQuantity() {
return itemQuantity;
}
string ItemToPurchase::GetDescription() {
return itemDescription;
}
void ItemToPurchase::PrintItemCost() {
cout << itemName << " " << itemQuantity << " @ $" << itemPrice << " = $" <<
itemQuantity * itemPrice << endl;
return;
}
void ItemToPurchase::PrintItemDescription() {
cout << itemName << ": " << itemDescription << endl;
return;
}
ShoppingCart.h
#include
#include
#include
#include "ItemToPurchase.h"
using namespace std;
class ShoppingCart {
public:
ShoppingCart();
ShoppingCart(string customerName, string currentDate );
string GetCustomerName();
string GetDate();
void AddItem(ItemToPurchase);
void RemoveItem(string);
void ModifyItem(ItemToPurchase);
int GetNumItemsInCart();
int GetCostOfCart();
void PrintTotal();
void PrintDescriptions();
private:
string customerName;
string currentDate;
vector cartItems;
};
#endif
ShoppingCart.cpp
ShoppingCart::ShoppingCart() {
customerName = "NoName";
currentDate = "October 23, 2016";
return;
}
ShoppingCart::ShoppingCart(string cName, string cDate) {
customerName = cName;
currentDate = cDate;
return;
}
string ShoppingCart::GetCustomerName(){
return customerName;
}
string ShoppingCart::GetDate(){
return currentDate ;
}
void ShoppingCart::AddItem(ItemToPurchase itemToAdd){
cartItems.push_back(itemToAdd);
return;
}
void ShoppingCart::RemoveItem(string itemToRemove){
unsigned int oldsize = cartItems.size();
for (unsigned int i = 0; i < cartItems.size(); ++i){
if (cartItems.at(i).GetName() == itemToRemove) {
cartItems.erase(cartItems.begin()+i);
}
}
if(oldsize == cartItems.size()) {
cout << "Item not found in cart. Nothing removed." << endl;
}
return;
}
void ShoppingCart::ModifyItem(ItemToPurchase itemToChange){
bool itemToModify = false;
for (unsigned int i = 0; i < cartItems.size(); ++i){
if (cartItems.at(i).GetName() == itemToChange.GetName()) {
cartItems.at(i).SetQuantity(itemToChange.GetQuantity());
itemToModify = true;
}
}
if (itemToModify == false) {
cout << "Item not found in cart. Nothing modified.";
}
return;
}
int ShoppingCart::GetNumItemsInCart(){
int numItems = cartItems.size();
return numItems;
}
int ShoppingCart::GetCostOfCart() {
int sum = 0;
for (unsigned int i = 0; i < cartItems.size(); ++i){
sum = sum + (cartItems.at(i).GetPrice()*cartItems.at(i).GetQuantity());
}
return sum;
}
void ShoppingCart::PrintTotal(){
int total = 0;
cout << customerName << "'s Shopping Cart - " << currentDate << endl;
if(cartItems.size() == 0){
cout << "Number of Items: " << GetNumItemsInCart() << endl;
cout << endl;
cout << "SHOPPING CART IS EMPTY" << endl;
cout << endl;
cout << "Total: $" << total << endl;
}
else{
cout << "Number of Items: " << GetNumItemsInCart() << endl;
cout << endl;
for(unsigned int i = 0; i < cartItems.size(); ++i) {
cout << cartItems.at(i).GetName() << " " << cartItems.at(i).GetQuantity() << " @ $"
<< cartItems.at(i).GetPrice()
<< " = $" << cartItems.at(i).GetPrice()*cartItems.at(i).GetQuantity() << endl;
total = total + (cartItems.at(i).GetPrice()*cartItems.at(i).GetQuantity());
}
cout << endl;
cout << "Total: $" << total << endl;
cout << endl;
}
return;
}
void ShoppingCart::PrintDescriptions(){
cout << customerName << "'s Shopping Cart - " << currentDate << endl;
cout << endl;
cout << "Item Descriptions" << endl;
for(unsigned int i = 0; i < cartItems.size(); ++i){
cout << cartItems.at(i).GetName() << ": " << cartItems.at(i).GetDescription() << endl;
}
return;
}
main.cpp
int main() {
string customerName;
string currentDate;
string itemName;
double itemPrice;
int itemQuantity;
string itemDescription;
string itemToRemove;
int newQuantity;
char userOption;
cout << "Enter Customer's Name: ";
getline(cin, customerName);
cout << "Enter Today's Date: ";
getline(cin, currentDate);
cout << "Customer Name: " << customerName << endl;
cout << "Today's Date: " << currentDate << endl;
ShoppingCart itemCart(customerName, currentDate);
while (userOption != 'q')
{
cout << endl;
cout <<"MENU" << endl;
cout << "a - Add item to cart" << endl;
cout << "d - Remove item from cart" << endl;
cout << "c - Change item quantity" << endl;
cout << "i - Output items' descriptions" << endl;
cout << "o - Output shopping cart" << endl;
cout << "q - Quit" << endl;
cout << endl;
cout << "Choose an option: ";
cin >> userOption;
cout << endl;
if (userOption == 'a' || userOption == 'A') {
cout << "ADD ITEM TO CART" << endl;
cout << "Enter the item name: ";
cin.ignore();
getline (cin, itemName);
cout << "Enter the item description: ";
cin.ignore();
getline(cin, itemDescription);
cout << "Enter the item price: ";
cin >> itemPrice;
cout << "Enter the item quantity: ";
cin >> itemQuantity;
ItemToPurchase itemToAdd(itemName, itemDescription, itemPrice, itemQuantity);
itemCart.AddItem(itemToAdd);
}
if (userOption == 'd' || userOption == 'D'){
cout << "REMOVE ITEM FROM CART" << endl;
cout << "Enter name of item to remove: ";
getline(cin, itemToRemove);
itemCart.RemoveItem(itemToRemove);
}
if (userOption == 'c' || userOption == 'C') {
cout << "CHANGE ITEM QUANTITY" << endl;
cout << "Enter the item name: ";
cin >> itemName;
cout << "Enter the new quantity: ";
cin >> newQuantity;
//ItemToPurchase itemToChange(newQuantity);
//itemCart.ModifyItem(itemToChange);
}
if (userOption == 'i' || userOption == 'I') {
cout << "OUTPUT ITEMS' DESCRIPTIONS" << endl;
itemCart.PrintDescriptions();
}
if (userOption == 'o' || userOption == 'O') {
cout << "OUTPUT SHOPPING CART" << endl;
itemCart.PrintTotal();
}
}
return 0;
}
Solution
Your code seems code good here.No changes As I reviewed your code.
void ShoppingCart::RemoveItem(string itemToRemove){
unsigned int oldsize = cartItems.size();
for (unsigned int i = 0; i < cartItems.size(); ++i){
if (cartItems.at(i).GetName() == itemToRemove) {
cartItems.erase(cartItems.begin()+i);
}
}
if(oldsize == cartItems.size()) {
cout << "Item not found in cart. Nothing removed." << endl;
}
return;
}

More Related Content

Similar to I finished most of the program, but having trouble with some key fea.pdf

show code and all classes with full implementation for these Program S.pdf
show code and all classes with full implementation for these Program S.pdfshow code and all classes with full implementation for these Program S.pdf
show code and all classes with full implementation for these Program S.pdf
AlanSmDDyerl
 
Extracting ui Design - part 4 - transcript.pdf
Extracting ui Design - part 4 - transcript.pdfExtracting ui Design - part 4 - transcript.pdf
Extracting ui Design - part 4 - transcript.pdf
ShaiAlmog1
 
Header file for an array-based implementation of the ADT bag. @f.pdf
 Header file for an array-based implementation of the ADT bag. @f.pdf Header file for an array-based implementation of the ADT bag. @f.pdf
Header file for an array-based implementation of the ADT bag. @f.pdf
sudhirchourasia86
 
Architecture - Part 2 - Transcript.pdf
Architecture - Part 2 - Transcript.pdfArchitecture - Part 2 - Transcript.pdf
Architecture - Part 2 - Transcript.pdf
ShaiAlmog1
 
Amusement Park Programming ProjectProject Outcomes1. Use the Jav.docx
Amusement Park Programming ProjectProject Outcomes1. Use the Jav.docxAmusement Park Programming ProjectProject Outcomes1. Use the Jav.docx
Amusement Park Programming ProjectProject Outcomes1. Use the Jav.docx
cullenrjzsme
 
Program Specifications Develop an inventory management system for an e.docx
Program Specifications Develop an inventory management system for an e.docxProgram Specifications Develop an inventory management system for an e.docx
Program Specifications Develop an inventory management system for an e.docx
VictormxrPiperc
 
import entity.Product; 012. import java.util.; 013. 014..pdf
import entity.Product; 012. import java.util.; 013. 014..pdfimport entity.Product; 012. import java.util.; 013. 014..pdf
import entity.Product; 012. import java.util.; 013. 014..pdf
Rubanjews
 
Ajava oep shopping application
Ajava oep shopping applicationAjava oep shopping application
Ajava oep shopping application
Paneliya Prince
 
[FEConf Korea 2017]Angular 컴포넌트 대화법
[FEConf Korea 2017]Angular 컴포넌트 대화법[FEConf Korea 2017]Angular 컴포넌트 대화법
[FEConf Korea 2017]Angular 컴포넌트 대화법
Jeado Ko
 
I really need help with this Assignment Please in C programming not .pdf
I really need help with this Assignment Please in C programming not .pdfI really need help with this Assignment Please in C programming not .pdf
I really need help with this Assignment Please in C programming not .pdf
pasqualealvarez467
 
BELOW IS MY CODE FOR THIS ASSIGMENT BUT IT NOT WORKING WELL PLEASE H.pdf
BELOW IS MY CODE FOR THIS ASSIGMENT BUT IT NOT WORKING WELL PLEASE H.pdfBELOW IS MY CODE FOR THIS ASSIGMENT BUT IT NOT WORKING WELL PLEASE H.pdf
BELOW IS MY CODE FOR THIS ASSIGMENT BUT IT NOT WORKING WELL PLEASE H.pdf
aminaENT
 
How Reactive do we need to be
How Reactive do we need to beHow Reactive do we need to be
How Reactive do we need to be
Jana Karceska
 
Fixing Magento Core for Better Performance - Ivan Chepurnyi
Fixing Magento Core for Better Performance - Ivan ChepurnyiFixing Magento Core for Better Performance - Ivan Chepurnyi
Fixing Magento Core for Better Performance - Ivan Chepurnyi
Meet Magento Spain
 
C++ help finish my code Phase 1 - input phase. Main reads the fi.pdf
C++ help finish my code Phase 1 - input phase. Main reads the fi.pdfC++ help finish my code Phase 1 - input phase. Main reads the fi.pdf
C++ help finish my code Phase 1 - input phase. Main reads the fi.pdf
info189835
 
Migrating One of the Most Popular eCommerce Platforms to MongoDB
Migrating One of the Most Popular eCommerce Platforms to MongoDBMigrating One of the Most Popular eCommerce Platforms to MongoDB
Migrating One of the Most Popular eCommerce Platforms to MongoDB
MongoDB
 
Migrating one of the most popular e commerce platforms to mongodb
Migrating one of the most popular e commerce platforms to mongodbMigrating one of the most popular e commerce platforms to mongodb
Migrating one of the most popular e commerce platforms to mongodbMongoDB
 
Enhanced ecommerce tracking
Enhanced ecommerce trackingEnhanced ecommerce tracking
Enhanced ecommerce tracking
Etietop Demas
 
This is a C# project . I am expected to create as this image shows. .pdf
This is a C# project . I am expected to create as this image shows. .pdfThis is a C# project . I am expected to create as this image shows. .pdf
This is a C# project . I am expected to create as this image shows. .pdf
indiaartz
 
Windows Forms For Beginners Part - 3
Windows Forms For Beginners Part - 3Windows Forms For Beginners Part - 3
Windows Forms For Beginners Part - 3
Bhushan Mulmule
 

Similar to I finished most of the program, but having trouble with some key fea.pdf (20)

show code and all classes with full implementation for these Program S.pdf
show code and all classes with full implementation for these Program S.pdfshow code and all classes with full implementation for these Program S.pdf
show code and all classes with full implementation for these Program S.pdf
 
Extracting ui Design - part 4 - transcript.pdf
Extracting ui Design - part 4 - transcript.pdfExtracting ui Design - part 4 - transcript.pdf
Extracting ui Design - part 4 - transcript.pdf
 
Header file for an array-based implementation of the ADT bag. @f.pdf
 Header file for an array-based implementation of the ADT bag. @f.pdf Header file for an array-based implementation of the ADT bag. @f.pdf
Header file for an array-based implementation of the ADT bag. @f.pdf
 
Architecture - Part 2 - Transcript.pdf
Architecture - Part 2 - Transcript.pdfArchitecture - Part 2 - Transcript.pdf
Architecture - Part 2 - Transcript.pdf
 
Amusement Park Programming ProjectProject Outcomes1. Use the Jav.docx
Amusement Park Programming ProjectProject Outcomes1. Use the Jav.docxAmusement Park Programming ProjectProject Outcomes1. Use the Jav.docx
Amusement Park Programming ProjectProject Outcomes1. Use the Jav.docx
 
Program Specifications Develop an inventory management system for an e.docx
Program Specifications Develop an inventory management system for an e.docxProgram Specifications Develop an inventory management system for an e.docx
Program Specifications Develop an inventory management system for an e.docx
 
import entity.Product; 012. import java.util.; 013. 014..pdf
import entity.Product; 012. import java.util.; 013. 014..pdfimport entity.Product; 012. import java.util.; 013. 014..pdf
import entity.Product; 012. import java.util.; 013. 014..pdf
 
Lecture9
Lecture9Lecture9
Lecture9
 
Ajava oep shopping application
Ajava oep shopping applicationAjava oep shopping application
Ajava oep shopping application
 
[FEConf Korea 2017]Angular 컴포넌트 대화법
[FEConf Korea 2017]Angular 컴포넌트 대화법[FEConf Korea 2017]Angular 컴포넌트 대화법
[FEConf Korea 2017]Angular 컴포넌트 대화법
 
I really need help with this Assignment Please in C programming not .pdf
I really need help with this Assignment Please in C programming not .pdfI really need help with this Assignment Please in C programming not .pdf
I really need help with this Assignment Please in C programming not .pdf
 
BELOW IS MY CODE FOR THIS ASSIGMENT BUT IT NOT WORKING WELL PLEASE H.pdf
BELOW IS MY CODE FOR THIS ASSIGMENT BUT IT NOT WORKING WELL PLEASE H.pdfBELOW IS MY CODE FOR THIS ASSIGMENT BUT IT NOT WORKING WELL PLEASE H.pdf
BELOW IS MY CODE FOR THIS ASSIGMENT BUT IT NOT WORKING WELL PLEASE H.pdf
 
How Reactive do we need to be
How Reactive do we need to beHow Reactive do we need to be
How Reactive do we need to be
 
Fixing Magento Core for Better Performance - Ivan Chepurnyi
Fixing Magento Core for Better Performance - Ivan ChepurnyiFixing Magento Core for Better Performance - Ivan Chepurnyi
Fixing Magento Core for Better Performance - Ivan Chepurnyi
 
C++ help finish my code Phase 1 - input phase. Main reads the fi.pdf
C++ help finish my code Phase 1 - input phase. Main reads the fi.pdfC++ help finish my code Phase 1 - input phase. Main reads the fi.pdf
C++ help finish my code Phase 1 - input phase. Main reads the fi.pdf
 
Migrating One of the Most Popular eCommerce Platforms to MongoDB
Migrating One of the Most Popular eCommerce Platforms to MongoDBMigrating One of the Most Popular eCommerce Platforms to MongoDB
Migrating One of the Most Popular eCommerce Platforms to MongoDB
 
Migrating one of the most popular e commerce platforms to mongodb
Migrating one of the most popular e commerce platforms to mongodbMigrating one of the most popular e commerce platforms to mongodb
Migrating one of the most popular e commerce platforms to mongodb
 
Enhanced ecommerce tracking
Enhanced ecommerce trackingEnhanced ecommerce tracking
Enhanced ecommerce tracking
 
This is a C# project . I am expected to create as this image shows. .pdf
This is a C# project . I am expected to create as this image shows. .pdfThis is a C# project . I am expected to create as this image shows. .pdf
This is a C# project . I am expected to create as this image shows. .pdf
 
Windows Forms For Beginners Part - 3
Windows Forms For Beginners Part - 3Windows Forms For Beginners Part - 3
Windows Forms For Beginners Part - 3
 

More from hardjasonoco14599

[Quantum Mechanics] In my class we are talking about the quantum har.pdf
[Quantum Mechanics] In my class we are talking about the quantum har.pdf[Quantum Mechanics] In my class we are talking about the quantum har.pdf
[Quantum Mechanics] In my class we are talking about the quantum har.pdf
hardjasonoco14599
 
Write a function which return a list of all of the n element subset .pdf
Write a function which return a list of all of the n element subset .pdfWrite a function which return a list of all of the n element subset .pdf
Write a function which return a list of all of the n element subset .pdf
hardjasonoco14599
 
what is tax preferenceSolutionTax preferences are measures of .pdf
what is tax preferenceSolutionTax preferences are measures of .pdfwhat is tax preferenceSolutionTax preferences are measures of .pdf
what is tax preferenceSolutionTax preferences are measures of .pdf
hardjasonoco14599
 
Which of the following is true regarding homologous structuresA. .pdf
Which of the following is true regarding homologous structuresA. .pdfWhich of the following is true regarding homologous structuresA. .pdf
Which of the following is true regarding homologous structuresA. .pdf
hardjasonoco14599
 
Why is it reasonable to assume that Venus, Earth, and Mars started w.pdf
Why is it reasonable to assume that Venus, Earth, and Mars started w.pdfWhy is it reasonable to assume that Venus, Earth, and Mars started w.pdf
Why is it reasonable to assume that Venus, Earth, and Mars started w.pdf
hardjasonoco14599
 
Which of the following is NOT a complication in development of an HIV.pdf
Which of the following is NOT a complication in development of an HIV.pdfWhich of the following is NOT a complication in development of an HIV.pdf
Which of the following is NOT a complication in development of an HIV.pdf
hardjasonoco14599
 
Write a C++ program that implements a binary search tree (BST) to man.pdf
Write a C++ program that implements a binary search tree (BST) to man.pdfWrite a C++ program that implements a binary search tree (BST) to man.pdf
Write a C++ program that implements a binary search tree (BST) to man.pdf
hardjasonoco14599
 
Which of the following groups is responsible for the actual developm.pdf
Which of the following groups is responsible for the actual developm.pdfWhich of the following groups is responsible for the actual developm.pdf
Which of the following groups is responsible for the actual developm.pdf
hardjasonoco14599
 
Whats the role of the gastric caeca in a grasshopperSolutionGr.pdf
Whats the role of the gastric caeca in a grasshopperSolutionGr.pdfWhats the role of the gastric caeca in a grasshopperSolutionGr.pdf
Whats the role of the gastric caeca in a grasshopperSolutionGr.pdf
hardjasonoco14599
 
what does it takes to be a living organ What does it take to be a l.pdf
what does it takes to be a living organ What does it take to be a l.pdfwhat does it takes to be a living organ What does it take to be a l.pdf
what does it takes to be a living organ What does it take to be a l.pdf
hardjasonoco14599
 
ve targets. ball and sodket hinge joint condyloid joint saddle jo.pdf
ve targets. ball and sodket hinge joint condyloid joint saddle jo.pdfve targets. ball and sodket hinge joint condyloid joint saddle jo.pdf
ve targets. ball and sodket hinge joint condyloid joint saddle jo.pdf
hardjasonoco14599
 
This one is for you - assume that this pedigree shows the inheritance.pdf
This one is for you - assume that this pedigree shows the inheritance.pdfThis one is for you - assume that this pedigree shows the inheritance.pdf
This one is for you - assume that this pedigree shows the inheritance.pdf
hardjasonoco14599
 
There are 7 people in the elevator in a 10-story building. They are .pdf
There are 7 people in the elevator in a 10-story building. They are .pdfThere are 7 people in the elevator in a 10-story building. They are .pdf
There are 7 people in the elevator in a 10-story building. They are .pdf
hardjasonoco14599
 
safety Construction Safety-Quiz 1 According to OSHA, what must man.pdf
safety Construction Safety-Quiz 1 According to OSHA, what must man.pdfsafety Construction Safety-Quiz 1 According to OSHA, what must man.pdf
safety Construction Safety-Quiz 1 According to OSHA, what must man.pdf
hardjasonoco14599
 
Question 1 A ____________ is an intelligent device that controls the.pdf
Question 1 A ____________ is an intelligent device that controls the.pdfQuestion 1 A ____________ is an intelligent device that controls the.pdf
Question 1 A ____________ is an intelligent device that controls the.pdf
hardjasonoco14599
 
In sliding window protocol the left wall of the sender sliding winod.pdf
In sliding window protocol the left wall of the sender sliding winod.pdfIn sliding window protocol the left wall of the sender sliding winod.pdf
In sliding window protocol the left wall of the sender sliding winod.pdf
hardjasonoco14599
 
In mice, the black allele (B) is dominant to the recessive white all.pdf
In mice, the black allele (B) is dominant to the recessive white all.pdfIn mice, the black allele (B) is dominant to the recessive white all.pdf
In mice, the black allele (B) is dominant to the recessive white all.pdf
hardjasonoco14599
 
How will the rate of diffusion of an interstitial i Impurity atom Inc.pdf
How will the rate of diffusion of an interstitial i Impurity atom Inc.pdfHow will the rate of diffusion of an interstitial i Impurity atom Inc.pdf
How will the rate of diffusion of an interstitial i Impurity atom Inc.pdf
hardjasonoco14599
 
Let R be an integral domain. Prove 1R and -1R are the only units of .pdf
Let R be an integral domain. Prove 1R and -1R are the only units of .pdfLet R be an integral domain. Prove 1R and -1R are the only units of .pdf
Let R be an integral domain. Prove 1R and -1R are the only units of .pdf
hardjasonoco14599
 
Kevin Keller’s aunt’s husband and his girl cousin have died of heart.pdf
Kevin Keller’s aunt’s husband and his girl cousin have died of heart.pdfKevin Keller’s aunt’s husband and his girl cousin have died of heart.pdf
Kevin Keller’s aunt’s husband and his girl cousin have died of heart.pdf
hardjasonoco14599
 

More from hardjasonoco14599 (20)

[Quantum Mechanics] In my class we are talking about the quantum har.pdf
[Quantum Mechanics] In my class we are talking about the quantum har.pdf[Quantum Mechanics] In my class we are talking about the quantum har.pdf
[Quantum Mechanics] In my class we are talking about the quantum har.pdf
 
Write a function which return a list of all of the n element subset .pdf
Write a function which return a list of all of the n element subset .pdfWrite a function which return a list of all of the n element subset .pdf
Write a function which return a list of all of the n element subset .pdf
 
what is tax preferenceSolutionTax preferences are measures of .pdf
what is tax preferenceSolutionTax preferences are measures of .pdfwhat is tax preferenceSolutionTax preferences are measures of .pdf
what is tax preferenceSolutionTax preferences are measures of .pdf
 
Which of the following is true regarding homologous structuresA. .pdf
Which of the following is true regarding homologous structuresA. .pdfWhich of the following is true regarding homologous structuresA. .pdf
Which of the following is true regarding homologous structuresA. .pdf
 
Why is it reasonable to assume that Venus, Earth, and Mars started w.pdf
Why is it reasonable to assume that Venus, Earth, and Mars started w.pdfWhy is it reasonable to assume that Venus, Earth, and Mars started w.pdf
Why is it reasonable to assume that Venus, Earth, and Mars started w.pdf
 
Which of the following is NOT a complication in development of an HIV.pdf
Which of the following is NOT a complication in development of an HIV.pdfWhich of the following is NOT a complication in development of an HIV.pdf
Which of the following is NOT a complication in development of an HIV.pdf
 
Write a C++ program that implements a binary search tree (BST) to man.pdf
Write a C++ program that implements a binary search tree (BST) to man.pdfWrite a C++ program that implements a binary search tree (BST) to man.pdf
Write a C++ program that implements a binary search tree (BST) to man.pdf
 
Which of the following groups is responsible for the actual developm.pdf
Which of the following groups is responsible for the actual developm.pdfWhich of the following groups is responsible for the actual developm.pdf
Which of the following groups is responsible for the actual developm.pdf
 
Whats the role of the gastric caeca in a grasshopperSolutionGr.pdf
Whats the role of the gastric caeca in a grasshopperSolutionGr.pdfWhats the role of the gastric caeca in a grasshopperSolutionGr.pdf
Whats the role of the gastric caeca in a grasshopperSolutionGr.pdf
 
what does it takes to be a living organ What does it take to be a l.pdf
what does it takes to be a living organ What does it take to be a l.pdfwhat does it takes to be a living organ What does it take to be a l.pdf
what does it takes to be a living organ What does it take to be a l.pdf
 
ve targets. ball and sodket hinge joint condyloid joint saddle jo.pdf
ve targets. ball and sodket hinge joint condyloid joint saddle jo.pdfve targets. ball and sodket hinge joint condyloid joint saddle jo.pdf
ve targets. ball and sodket hinge joint condyloid joint saddle jo.pdf
 
This one is for you - assume that this pedigree shows the inheritance.pdf
This one is for you - assume that this pedigree shows the inheritance.pdfThis one is for you - assume that this pedigree shows the inheritance.pdf
This one is for you - assume that this pedigree shows the inheritance.pdf
 
There are 7 people in the elevator in a 10-story building. They are .pdf
There are 7 people in the elevator in a 10-story building. They are .pdfThere are 7 people in the elevator in a 10-story building. They are .pdf
There are 7 people in the elevator in a 10-story building. They are .pdf
 
safety Construction Safety-Quiz 1 According to OSHA, what must man.pdf
safety Construction Safety-Quiz 1 According to OSHA, what must man.pdfsafety Construction Safety-Quiz 1 According to OSHA, what must man.pdf
safety Construction Safety-Quiz 1 According to OSHA, what must man.pdf
 
Question 1 A ____________ is an intelligent device that controls the.pdf
Question 1 A ____________ is an intelligent device that controls the.pdfQuestion 1 A ____________ is an intelligent device that controls the.pdf
Question 1 A ____________ is an intelligent device that controls the.pdf
 
In sliding window protocol the left wall of the sender sliding winod.pdf
In sliding window protocol the left wall of the sender sliding winod.pdfIn sliding window protocol the left wall of the sender sliding winod.pdf
In sliding window protocol the left wall of the sender sliding winod.pdf
 
In mice, the black allele (B) is dominant to the recessive white all.pdf
In mice, the black allele (B) is dominant to the recessive white all.pdfIn mice, the black allele (B) is dominant to the recessive white all.pdf
In mice, the black allele (B) is dominant to the recessive white all.pdf
 
How will the rate of diffusion of an interstitial i Impurity atom Inc.pdf
How will the rate of diffusion of an interstitial i Impurity atom Inc.pdfHow will the rate of diffusion of an interstitial i Impurity atom Inc.pdf
How will the rate of diffusion of an interstitial i Impurity atom Inc.pdf
 
Let R be an integral domain. Prove 1R and -1R are the only units of .pdf
Let R be an integral domain. Prove 1R and -1R are the only units of .pdfLet R be an integral domain. Prove 1R and -1R are the only units of .pdf
Let R be an integral domain. Prove 1R and -1R are the only units of .pdf
 
Kevin Keller’s aunt’s husband and his girl cousin have died of heart.pdf
Kevin Keller’s aunt’s husband and his girl cousin have died of heart.pdfKevin Keller’s aunt’s husband and his girl cousin have died of heart.pdf
Kevin Keller’s aunt’s husband and his girl cousin have died of heart.pdf
 

Recently uploaded

Francesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptxFrancesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptx
EduSkills OECD
 
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdfUnit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Thiyagu K
 
The approach at University of Liverpool.pptx
The approach at University of Liverpool.pptxThe approach at University of Liverpool.pptx
The approach at University of Liverpool.pptx
Jisc
 
Operation Blue Star - Saka Neela Tara
Operation Blue Star   -  Saka Neela TaraOperation Blue Star   -  Saka Neela Tara
Operation Blue Star - Saka Neela Tara
Balvir Singh
 
How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17
Celine George
 
Palestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptxPalestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptx
RaedMohamed3
 
"Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe..."Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe...
SACHIN R KONDAGURI
 
The geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideasThe geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideas
GeoBlogs
 
Polish students' mobility in the Czech Republic
Polish students' mobility in the Czech RepublicPolish students' mobility in the Czech Republic
Polish students' mobility in the Czech Republic
Anna Sz.
 
Home assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdfHome assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdf
Tamralipta Mahavidyalaya
 
CACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdfCACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdf
camakaiclarkmusic
 
The French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free downloadThe French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free download
Vivekanand Anglo Vedic Academy
 
A Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in EducationA Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in Education
Peter Windle
 
Instructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptxInstructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptx
Jheel Barad
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
siemaillard
 
The Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdfThe Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdf
kaushalkr1407
 
Embracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic ImperativeEmbracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic Imperative
Peter Windle
 
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXXPhrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
MIRIAMSALINAS13
 
The Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official PublicationThe Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official Publication
Delapenabediema
 
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdfAdversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Po-Chuan Chen
 

Recently uploaded (20)

Francesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptxFrancesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptx
 
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdfUnit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdf
 
The approach at University of Liverpool.pptx
The approach at University of Liverpool.pptxThe approach at University of Liverpool.pptx
The approach at University of Liverpool.pptx
 
Operation Blue Star - Saka Neela Tara
Operation Blue Star   -  Saka Neela TaraOperation Blue Star   -  Saka Neela Tara
Operation Blue Star - Saka Neela Tara
 
How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17
 
Palestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptxPalestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptx
 
"Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe..."Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe...
 
The geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideasThe geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideas
 
Polish students' mobility in the Czech Republic
Polish students' mobility in the Czech RepublicPolish students' mobility in the Czech Republic
Polish students' mobility in the Czech Republic
 
Home assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdfHome assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdf
 
CACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdfCACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdf
 
The French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free downloadThe French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free download
 
A Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in EducationA Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in Education
 
Instructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptxInstructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptx
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
 
The Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdfThe Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdf
 
Embracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic ImperativeEmbracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic Imperative
 
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXXPhrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
 
The Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official PublicationThe Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official Publication
 
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdfAdversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
 

I finished most of the program, but having trouble with some key fea.pdf

  • 1. I finished most of the program, but having trouble with some key features. I bolded and italicized the parts I can't figure out, and included them below. I included my code at the bottom. Thanks! 1. I can't get my RemoveItem() and ModifyItem() functions to work. 2. GetNumItemsInCart() is returning the wrong value. For example, my cart has 5 chocolate chip cookies, 1 headphone, and 2 sneakers. GetNumItemsInCart() returns 3 instead of 8 when I output my shopping cart. 3. When PrintDescriptions() is called, the first letter of my item description is missing. For example, for the chocolate chip cookies, the description is Semi-sweet. When PrintDescriptions() is called, it returns emi-sweet, with the S gone. 4. Shopping Cart improperly initialized with default constructor , and I don't know why. 12.9 Program: Online shopping cart (continued) (C++) This program extends the earlier "Online shopping cart" 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 SetDescription() mutator & GetDescription() accessor (2 pts) PrintItemCost() - Outputs the item name followed by the quantity, price, and subtotal PrintItemDescription() - Outputs the item name and description Private data members string itemDescription - Initialized in default constructor to "none" Ex. of PrintItemCost() output: Ex. of PrintItemDescription() output: (2) Create three new files: ShoppingCart.h - Class declaration ShoppingCart.cpp - Class definition main.cpp - main() function (Note: main()'s functionality differs from the warm up) 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"
  • 2. string currentDate - Initialized in default constructor to "January 1, 2016" vector < ItemToPurchase > cartItems Public member functions GetCustomerName() accessor (1 pt) GetDate() accessor (1 pt) AddItem() Adds an item to cartItems vector. Has parameter ItemToPurchase. Does not return anything. RemoveItem() 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 cart. Nothing removed. ModifyItem() Modifies an item's description, price, and/or quantity. Has parameter 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. GetNumItemsInCart() (2 pts) Returns quantity of all items in cart. Has no parameters. GetCostOfCart() (2 pts) Determines and returns the total cost of items in cart. Has no parameters. PrintTotal() 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: Ex. of PrintDescriptions() output: (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 ShoppingCart. (1 pt) Ex.
  • 3. (4) Implement the PrintMenu() function. PrintMenu() has a ShoppingCart parameter, and outputs a menu of options to manipulate the shopping cart. Each option is represented by a single character. Build and output the menu within the function. If the an invalid character is entered, continue to prompt for a valid choice. Hint: Implement Quit before implementing other options. Call PrintMenu() in the main() function. Continue to execute the menu until the user enters q to Quit. (3 pts) Ex: (5) Implement Output shopping cart menu option. (3 pts) Ex: (6) Implement Output item's description menu option. (2 pts) Ex. (7) Implement Add item to cart menu option. (3 pts) Ex: (8) Implement remove item menu option. (4 pts) Ex: (9) Implement Change item quantity menu option. Hint: Make new ItemToPurchase object and use ItemToPurchase modifiers before using ModifyItem() function. (5 pts) Ex: My Program: ItemToPurchase.h #ifndef ITEMTOPURCHASE_H #define ITEMTOPURCHASE_H #include #include
  • 4. using namespace std; class ItemToPurchase { public: ItemToPurchase(); ItemToPurchase(string itemName, double itemPrice, int itemQuantity, string itemDescription); void SetName(string itemName); void SetPrice(double itemPrice); void SetQuantity(int itemQuantity); void SetDescription(string itemDescription); string GetName(); double GetPrice(); int GetQuantity(); string GetDescription(); void PrintItemCost(); void PrintItemDescription(); private: string itemName; double itemPrice; int itemQuantity; string itemDescription; }; #endif ItemToPurchase.cpp #include #include #include "ItemToPurchase.h" using namespace std; ItemToPurchase::ItemToPurchase() { itemName = "NoName"; itemPrice = 0.0; itemQuantity = 0;
  • 5. itemDescription = "NoDescription"; return; } ItemToPurchase::ItemToPurchase(string itemName, double itemPrice, int itemQuantity, string itemDescription) { SetName(itemName); SetPrice(itemPrice); SetQuantity(itemQuantity); SetDescription(itemDescription); return; } void ItemToPurchase::SetName(string item_Name) { itemName = item_Name; return; } void ItemToPurchase::SetPrice(double item_Price) { itemPrice = item_Price; return; } void ItemToPurchase::SetQuantity(int item_Quantity) { itemQuantity = item_Quantity; return; } void ItemToPurchase::SetDescription(string item_Description) { itemDescription = item_Description; return; } string ItemToPurchase::GetName() { return itemName; } double ItemToPurchase::GetPrice() { return itemPrice; } int ItemToPurchase::GetQuantity() { return itemQuantity; }
  • 6. string ItemToPurchase::GetDescription() { return itemDescription; } void ItemToPurchase::PrintItemCost() { cout << itemName << " " << itemQuantity << " @ $" << itemPrice << " = $" << itemQuantity * itemPrice << endl; return; } void ItemToPurchase::PrintItemDescription() { cout << itemName << ": " << itemDescription << endl; return; } ShoppingCart.h #include #include #include #include "ItemToPurchase.h" using namespace std; class ShoppingCart { public: ShoppingCart(); ShoppingCart(string customerName, string currentDate ); string GetCustomerName(); string GetDate(); void AddItem(ItemToPurchase); void RemoveItem(string); void ModifyItem(ItemToPurchase); int GetNumItemsInCart(); int GetCostOfCart(); void PrintTotal(); void PrintDescriptions();
  • 7. private: string customerName; string currentDate; vector cartItems; }; #endif ShoppingCart.cpp ShoppingCart::ShoppingCart() { customerName = "NoName"; currentDate = "October 23, 2016"; return; } ShoppingCart::ShoppingCart(string cName, string cDate) { customerName = cName; currentDate = cDate; return; } string ShoppingCart::GetCustomerName(){ return customerName; } string ShoppingCart::GetDate(){ return currentDate ; } void ShoppingCart::AddItem(ItemToPurchase itemToAdd){ cartItems.push_back(itemToAdd); return; } void ShoppingCart::RemoveItem(string itemToRemove){ unsigned int oldsize = cartItems.size(); for (unsigned int i = 0; i < cartItems.size(); ++i){ if (cartItems.at(i).GetName() == itemToRemove) { cartItems.erase(cartItems.begin()+i); } }
  • 8. if(oldsize == cartItems.size()) { cout << "Item not found in cart. Nothing removed." << endl; } return; } void ShoppingCart::ModifyItem(ItemToPurchase itemToChange){ bool itemToModify = false; for (unsigned int i = 0; i < cartItems.size(); ++i){ if (cartItems.at(i).GetName() == itemToChange.GetName()) { cartItems.at(i).SetQuantity(itemToChange.GetQuantity()); itemToModify = true; } } if (itemToModify == false) { cout << "Item not found in cart. Nothing modified."; } return; } int ShoppingCart::GetNumItemsInCart(){ int numItems = cartItems.size(); return numItems; } int ShoppingCart::GetCostOfCart() { int sum = 0; for (unsigned int i = 0; i < cartItems.size(); ++i){ sum = sum + (cartItems.at(i).GetPrice()*cartItems.at(i).GetQuantity()); } return sum; } void ShoppingCart::PrintTotal(){ int total = 0; cout << customerName << "'s Shopping Cart - " << currentDate << endl;
  • 9. if(cartItems.size() == 0){ cout << "Number of Items: " << GetNumItemsInCart() << endl; cout << endl; cout << "SHOPPING CART IS EMPTY" << endl; cout << endl; cout << "Total: $" << total << endl; } else{ cout << "Number of Items: " << GetNumItemsInCart() << endl; cout << endl; for(unsigned int i = 0; i < cartItems.size(); ++i) { cout << cartItems.at(i).GetName() << " " << cartItems.at(i).GetQuantity() << " @ $" << cartItems.at(i).GetPrice() << " = $" << cartItems.at(i).GetPrice()*cartItems.at(i).GetQuantity() << endl; total = total + (cartItems.at(i).GetPrice()*cartItems.at(i).GetQuantity()); } cout << endl; cout << "Total: $" << total << endl; cout << endl; } return; } void ShoppingCart::PrintDescriptions(){ cout << customerName << "'s Shopping Cart - " << currentDate << endl; cout << endl; cout << "Item Descriptions" << endl; for(unsigned int i = 0; i < cartItems.size(); ++i){ cout << cartItems.at(i).GetName() << ": " << cartItems.at(i).GetDescription() << endl; } return; } main.cpp int main() { string customerName;
  • 10. string currentDate; string itemName; double itemPrice; int itemQuantity; string itemDescription; string itemToRemove; int newQuantity; char userOption; cout << "Enter Customer's Name: "; getline(cin, customerName); cout << "Enter Today's Date: "; getline(cin, currentDate); cout << "Customer Name: " << customerName << endl; cout << "Today's Date: " << currentDate << endl; ShoppingCart itemCart(customerName, currentDate); while (userOption != 'q') { cout << endl; cout <<"MENU" << endl; cout << "a - Add item to cart" << endl; cout << "d - Remove item from cart" << endl; cout << "c - Change item quantity" << endl; cout << "i - Output items' descriptions" << endl; cout << "o - Output shopping cart" << endl; cout << "q - Quit" << endl; cout << endl; cout << "Choose an option: "; cin >> userOption; cout << endl; if (userOption == 'a' || userOption == 'A') {
  • 11. cout << "ADD ITEM TO CART" << endl; cout << "Enter the item name: "; cin.ignore(); getline (cin, itemName); cout << "Enter the item description: "; cin.ignore(); getline(cin, itemDescription); cout << "Enter the item price: "; cin >> itemPrice; cout << "Enter the item quantity: "; cin >> itemQuantity; ItemToPurchase itemToAdd(itemName, itemDescription, itemPrice, itemQuantity); itemCart.AddItem(itemToAdd); } if (userOption == 'd' || userOption == 'D'){ cout << "REMOVE ITEM FROM CART" << endl; cout << "Enter name of item to remove: "; getline(cin, itemToRemove); itemCart.RemoveItem(itemToRemove); } if (userOption == 'c' || userOption == 'C') { cout << "CHANGE ITEM QUANTITY" << endl; cout << "Enter the item name: "; cin >> itemName; cout << "Enter the new quantity: "; cin >> newQuantity; //ItemToPurchase itemToChange(newQuantity); //itemCart.ModifyItem(itemToChange); }
  • 12. if (userOption == 'i' || userOption == 'I') { cout << "OUTPUT ITEMS' DESCRIPTIONS" << endl; itemCart.PrintDescriptions(); } if (userOption == 'o' || userOption == 'O') { cout << "OUTPUT SHOPPING CART" << endl; itemCart.PrintTotal(); } } return 0; } Solution Your code seems code good here.No changes As I reviewed your code. void ShoppingCart::RemoveItem(string itemToRemove){ unsigned int oldsize = cartItems.size(); for (unsigned int i = 0; i < cartItems.size(); ++i){ if (cartItems.at(i).GetName() == itemToRemove) { cartItems.erase(cartItems.begin()+i); } } if(oldsize == cartItems.size()) { cout << "Item not found in cart. Nothing removed." << endl; } return; }