Question

I need help with this assignment, can someone HELP ? This is the assignment: Online shopping...

I need help with this assignment, can someone HELP ?

This is the assignment:

Online shopping cart (continued) (C++)

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

Bottled Water 10 @ $1 = $10


Ex. of PrintItemDescription() output:

Bottled Water: Deer Park, 12 oz.


(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.


(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.

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

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:


(5) Implement Output shopping cart menu option. (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


(6) Implement Output item's description menu option. (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


(7) Implement Add item to cart menu option. (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


(8) Implement remove item menu option. (4 pts)

Ex:

REMOVE ITEM FROM CART
Enter name of item to remove:
Chocolate Chips


(9) Implement Change item quantity menu option. Hint: Make new ItemToPurchase object and use ItemToPurchase modifiers before using ModifyItem() function. (5 pts)

Ex:

CHANGE ITEM QUANTITY
Enter the item name:
Nike Romaleos
Enter the new quantity:
3

P.S

I am including all files and the code that I have so far.... there has been a few responses to this and all of them are incomplete, that is the challenging part.

the Code is Below: I am trying to compile the code in Ms Visual Studio.  

thanks in advance.

ShoppingCart.h (header file)
#ifndef SHOPPINGCART_H_

#define SHOPPINGCART_H_

#include <string>

#include <vector>

#include "ItemToPurchase.h"

using namespace std;

class ShoppingCart

{

private:

string name;

string date;

vector <ItemToPurchase> item;

public:

ShoppingCart(string name, string date);

virtual ~ShoppingCart();

const string& getDate() const;

void setDate(const string& date);

const string& getName() const;

void setName(const string& name);

void add(ItemToPurchase &item);

void remove(string itemName);

void update(ItemToPurchase &item);

void showDescription();

void showCart();

void showOption();

};

#endif

Shoppingcart.cpp

#include "ShoppingCart.h"

#include <iostream>

#include<string>

using namespace std;

ShoppingCart::ShoppingCart(string name = "none", string date = "January 1, 2016")

{

this->name=name;

this->date=date;

}

const string& ShoppingCart::getDate() const

{

return date;

}

void ShoppingCart::setDate(const string& date)

{

this->date = date;

}

const string& ShoppingCart::getName() const

{

return name;

}

void ShoppingCart::setName(const string& name)

{

this->name = name;

}

void ShoppingCart::add(ItemToPurchase &newItem)

{

int set = 0;

if(newItem.GetName().compare("none") != 0)

{

//vector<ItemToPurchase>::iterator it;

//for (it = item.begin() ; it != item.end(); ++it)

for(int i=0;i<item.size();i++)

{

if(item.at(i).GetName() == newItem.GetName())

{

cout<<"Item is already in cart. Nothing added."<<endl;

set = 1;

break;

}

}

if(set == 0)

item.push_back(newItem);

}

}

void ShoppingCart::remove(string itemName)

{

//vector<ItemToPurchase>::iterator it;

int i=0;

//for (it = item.begin() ; it != item.end(); ++it)

for(int j=0;j<item.size();i++)

{

i++;

if(item.at(j).GetName() == itemName)

{

cout<<"found...removing "<<getName()<<endl;

item.erase (item.begin()+j);

break;

}

}

if(i == 0)

{

cout<<"Shopping cart is empty."<<endl;

cout<<"No item found with name "<<itemName<<endl;

}

}

void ShoppingCart::update(ItemToPurchase &updateItem)

{

///vector<ItemToPurchase>::iterator it;

int i=0;

//for (it = item.begin() ; it != item.end(); ++it)

for(int j=0;j<item.size();i++)

{

i++;

if(item.at(i).GetName() == updateItem.GetName())

{

item.at(i).SetName(updateItem.GetName());

item.at(i).SetDescription(updateItem.GetDescription());

item.at(i).SetPrice(updateItem.GetPrice());

item.at(i).SetQuantity(updateItem.GetQuantity());

break;

}

}

if(i == 0)

{

cout<<"Shopping cart is empty."<<endl;

cout<<"No itemfound with name "<<updateItem.GetName()<<endl;

}

}

ShoppingCart::~ShoppingCart()

{

}

void ShoppingCart::showDescription()

{

vector<ItemToPurchase>::iterator it;

int i=0;

cout<<""<<name<<"'s Shopping Cart - "<<date<<endl;

//for (it = item.begin() ; it != item.end(); ++it)

for(int j=0;j<item.size();i++)

{

cout << item.at(i).GetName() << " : " << item.at(i).GetDescription()<< endl;

i++;

}

if(i == 0)

cout<<"Shopping cart is empty."<<endl;

}

void ShoppingCart::showCart()

{

//vector<ItemToPurchase>::iterator it;

int i = 0;

double tot = 0;

cout<<""<<name<<"'s Shopping Cart - "<<date<<endl;

//for (it = item.begin() ; it != item.end(); ++it)

for(int j=0;j<item.size();i++)

{

cout << item.at(i).GetName() << " " << item.at(i).GetQuantity() << " @ $" << item.at(i).GetPrice() << " = $" << item.at(i).GetPrice() * item.at(i).GetQuantity() << endl;

tot = tot + (item.at(i).GetPrice() *item.at(i). GetQuantity());

i++;

}

if(i == 0)

{

cout<<"Shopping cart is empty."<<endl;

cout<<"Total: $"<<tot<<endl;

}

}

void ShoppingCart::showOption()

{

cout<<"\t\tMenu"<<endl;

cout<<"add - Add item to cart"<<endl;

cout<<"remove - Remove item from cart"<<endl;

cout<<"change - Change item quantity"<<endl;

cout<<"descriptions - Output items' descriptions"<<endl;

cout<<"cart - Output shopping cart"<<endl;

cout<<"options - Print the options menu"<<endl;

cout<<"quit - Quit"<<endl;

}

itemToPurchase.h

#ifndef ItemToPurchase_H_

#define ItemToPurchase_H_

#include <string>

using namespace std;

class ItemToPurchase

{

private:

string itemName;

string itemDescription;

double itemPrice;

int itemQuantity;

public:

ItemToPurchase();

ItemToPurchase(string name, string desc, double price, int quantity);

void SetName(string name);

void SetPrice(double price);

void SetQuantity(int quantity);

string GetName();

double GetPrice();

int GetQuantity();

const string& GetDescription() const;

void SetDescription(const string& itemDescription);

void clean();

};

#endif

itemToPurchase.cpp

#include "ItemToPurchase.h"

ItemToPurchase::ItemToPurchase()

{

itemName = "none";

itemDescription = "none";

itemPrice = 0;

itemQuantity = 0;

}

ItemToPurchase::ItemToPurchase(string name, string desc, double price, int quantity)

{

if(name == "'")

name = "none";

if(desc == "")

desc = "none";

itemName = name;

itemDescription = desc;

itemPrice = price;

itemQuantity = quantity;

}

void ItemToPurchase::SetName(string name)

{

itemName = name;

}

void ItemToPurchase::SetPrice(double price)

{

itemPrice = price;

}

void ItemToPurchase::SetQuantity(int quantity)

{

itemQuantity = quantity;

}

string ItemToPurchase::GetName()

{

return itemName;

}

double ItemToPurchase::GetPrice()

{

return itemPrice;

}

const string& ItemToPurchase::GetDescription() const

{

return itemDescription;

}

void ItemToPurchase::SetDescription(const string& itemDescription)

{

this->itemDescription = itemDescription;

}

int ItemToPurchase::GetQuantity()

{

return itemQuantity;

}

void ItemToPurchase::clean()

{

itemName = "none";

itemDescription = "none";

itemPrice = 0;

itemQuantity = 0;

}

main,cpp

#include <iostream>

#include "ItemToPurchase.h"

#include "ShoppingCart.h"

using namespace std;

int main()

{

ItemToPurchase item;

string name, desc;

double price;

int q;

string custName,date;

string option = "";

cout<<"Enter Customer's Name :";

getline(cin, custName);

cout<<"Enter Today's Date : ";

getline(cin, date);

ShoppingCart sCart(name, date);

sCart.setName(custName);

sCart.setDate(date);

sCart.showOption();

while(option.compare("quit") != 0 )

{

cout<<"Enter option : "<<endl;

getline(cin, option);

if(option.compare("options") == 0)

sCart.showOption();

else if(option.compare("add") == 0)

{

cout << "Enter the item name: ";

getline(cin, name);

cout << "Enter the item description: ";

getline(cin, desc);

cout << "Enter the item price: ";

cin >> price;

cout << "Enter the item quantity: ";

cin >> q;

item.SetName(name);

item.SetDescription(desc);

item.SetPrice(price);

item.SetQuantity(q);

sCart.add(item);

item.clean();

cin.ignore();

}

else if(option.compare("remove") == 0)

{

cout << "Enter the item name: ";

getline(cin, name);

sCart.remove(name);

}

else if(option.compare("change") == 0)

{

cout << "Enter the item name: ";

getline(cin, name);

cout << "Enter the item quantity: ";

cin >> q;

item.SetName(name);

item.SetQuantity(q);

sCart.update(item);

item.clean();

cin.ignore();

}

else if(option.compare("descriptions") == 0)

sCart.showDescription();

else if(option.compare("cart") == 0)

sCart.showCart();

}

cout<<"Program..Terminated..";

return 0;

}

0 0
Add a comment Improve this question Transcribed image text
Answer #1

ANSWER :

void TotalCost(vector<ItemToPurchase> purchaseList, int size)

{

    int i;

    int total = 0, temp;

    cout << "TOTAL COST";

//Iterating over items

    for(i=0; i<size; i++)

    {

//Calculating total cost

        temp = ((purchaseList.at(i)).GetPrice()) * ((purchaseList.at(i)).GetQuantity());

        cout << endl << (purchaseList.at(i)).GetName() << " " << (purchaseList.at(i)).GetQuantity() << " @ $" << (purchaseList.at(i)).GetPrice() << " = $" << temp;

        total += temp;

    }

//Printing total cost

    cout << endl << endl << "Total: $" << total << endl;

    return;

}

//Main

int main()

{

    int size;

    size = 2;

//Vector to hold items

    vector<ItemToPurchase> purchaseList;

//Reading values

    CreatePurchaseList(purchaseList, size);

//Printing total cost

    TotalCost(purchaseList, size);

    return 0;

}

------My ItemToPurchase.cpp

#include <iostream>

#include <string>

#include "ItemToPurchase.h"

using namespace std;

ItemToPurchase::ItemToPurchase() //default constructor

{

    itemName = "none"; //default name

    itemPrice = 0; //default price

    itemQuantity = 0; //default qty

}

//Assigning name

void ItemToPurchase::SetName(string resitemName)

{

    itemName = resitemName;

}

//Returning name

string ItemToPurchase::GetName()

{

    return itemName;

}

//Assigning price

void ItemToPurchase::SetPrice(int resitemPrice)

{

    itemPrice = resitemPrice;

}

//Returning price

int ItemToPurchase::GetPrice()

{

    return itemPrice;

}

//Assigning Quantity

void ItemToPurchase::SetQuantity(int resitemQuantity)

{

    itemQuantity = resitemQuantity;

}

//Returning quantity

int ItemToPurchase::GetQuantity()

{

    return itemQuantity;

}

Add a comment
Know the answer?
Add Answer to:
I need help with this assignment, can someone HELP ? This is the assignment: Online shopping...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • CODES: main.cpp #include <iostream> #include <string> #include "ShoppingCart.h" using namespace std; char PrintMenu() { char answer;...

    CODES: main.cpp #include <iostream> #include <string> #include "ShoppingCart.h" using namespace std; char PrintMenu() { char answer; 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 << endl; while (true) {...

  • 4.18 Ch 7 Program: Online shopping cart (continued) (C++) This program extends the earlier "Online shopping...

    4.18 Ch 7 Program: Online shopping cart (continued) (C++) This program extends the earlier "Online shopping cart" program. (solution from previous lab assignment is provided in Canvas). (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() -...

  • This program extends the earlier "Online shopping cart" program. (Consider first saving your earlier program).

    Ch 7 Program: Online shopping cart (continued) (Java)This program extends the earlier "Online shopping cart" program. (Consider first saving your earlier program).(1) Extend the ItemToPurchase class per the following specifications:Private fieldsstring itemDescription - Initialized in default constructor to "none"Parameterized constructor to assign item name, item description, item price, and item quantity (default values of 0). (1 pt)Public member methodssetDescription() mutator & getDescription() accessor (2 pts)printItemCost() - Outputs the item name followed by the quantity, price, and subtotalprintItemDescription() - Outputs the...

  • Online shopping cart (continued) (Java) Hello, I need help with Java to figure this out. In...

    Online shopping cart (continued) (Java) Hello, I need help with Java to figure this out. In my Shopping Cart Manager Class (Bottom Code), I get "Resource leak: 'sc' is never closed." I have tried multiple things and cannot figure it out. Thank you. Online shopping cart (continued) (Java) Hello, I need help with Java to figure this out. In my Shopping Cart Manager Class (Bottom Code), I get "Resource leak: 'sc' is never closed." I have tried multiple things and...

  • Need three seperate files. ShoppingCartManager.java ShoppingCart.java ItemsToPurchase.java These are from part 1 what do you mean...

    Need three seperate files. ShoppingCartManager.java ShoppingCart.java ItemsToPurchase.java These are from part 1 what do you mean by deep study 7.25 LAB*: Program: Online shopping cart (Part 2) Note: Creating multiple Scanner objects for the same input stream yields unexpected behavior. Thus, good practice is to use a single Scanner object for reading input from System.in. That Scanner object can be passed as an argument to any methods that read input This program extends the earlier Online shopping cart program (Consider...

  • Warm up: Online shopping cart (Part 1)

    8.6 LAB*: Warm up: Online shopping cart (Part 1)(1) Create two files to submit:ItemToPurchase.java - Class definitionShoppingCartPrinter.java - Contains main() methodBuild the ItemToPurchase class with the following specifications:Private fieldsString itemName - Initialized in default constructor to "none"int itemPrice - Initialized in default constructor to 0int itemQuantity - Initialized in default constructor to 0Default constructorPublic member methods (mutators & accessors)setName() & getName() (2 pts)setPrice() & getPrice() (2 pts)setQuantity() & getQuantity() (2 pts)(2) In main(), prompt the user for two items and create...

  • 7.11 LAB: Online shopping cart - Part 2 This program extends the earlier "Online shopping cart" program. (Consid...

    7.11 LAB: Online shopping cart - Part 2 This program extends the earlier "Online shopping cart" program. (Consider first saving your earlier program). (1) Extend the ItemToPurchase namedtuple to contain a new attribute. (2 pts) item_description (string) - Set to "none" in the construct_item() function Implement the following function with an ItemToPurchase as a parameter. print_item_description() - Prints item_name and item_description attribute for an ItemToPurchase namedtuple. Has an ItemToPurchase parameter. Ex. of print_item_description() output: Bottled Water: Deer Park, 12 oz....

  • Zybooks 11.12 LAB*: Program: Online shopping cart (continued) Python 3 is the code needed and this...

    Zybooks 11.12 LAB*: Program: Online shopping cart (continued) Python 3 is the code needed and this is in Zybooks Existing Code # Type code for classes here class ItemToPurchase: def __init__(self, item_name="none", item_price=0, item_quantity=0): self.item_name = item_name self.item_price = item_price self.item_quantity = item_quantity # def __mul__(self): # print_item_cost = (self.item_quantity * self.item_price) # return '{} {} @ ${} = ${}' .format(self_item_name, self.item_quantity, self.item_price, print_item_cost) def print_item_cost(self): self.print_cost = (self.item_quantity * self.item_price) print(('{} {} @ ${} = ${}') .format(self.item_name, self.item_quantity, self.item_price,...

  • 11.12 LAB*: Program: Online shopping cart (continued) This program extends the earlier "Online shopping cart" pr...

    11.12 LAB*: Program: Online shopping cart (continued)This program extends the earlier "Online shopping cart" program. (Consider first saving your earlier program).(1) Extend the ItemToPurchase class to contain a new attribute. (2 pts)item_description (string) - Set to "none" in default constructorImplement the following method for the ItemToPurchase class.print_item_description() - Prints item_description attribute for an ItemToPurchase object. Has an ItemToPurchase parameter.Ex. of print_item_description() output:Bottled Water: Deer Park, 12 oz.(2) Build the ShoppingCart class with the following data attributes and related methods. Note: Some can be method stubs...

  • 8.7 LAB*: Program: Online shopping cart (Part 2)

    8.7 LAB*: Program: Online shopping cart (Part 2)Note: Creating multiple Scanner objects for the same input stream yields unexpected behavior. Thus, good practice is to use a single Scanner object for reading input from System.in. That Scanner object can be passed as an argument to any methods that read input.This program extends the earlier "Online shopping cart" program. (Consider first saving your earlier program).(1) Extend the ItemToPurchase class per the following specifications:Private fieldsstring itemDescription - Initialized in default constructor to "none"Parameterized...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT