Can someone please help me with this Python code? Thank you in advance, Zybooks keeps giving me errors. Thanks in advance!!
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)
Implement the following method for the ItemToPurchase class.
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 (empty methods) initially, to be completed in later steps.
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 print_descriptions() 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 section of your code, 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 print_menu() function. print_menu() 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 print_menu() 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 r - 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 before using ModifyItem() method. (5
pts)
Ex:
CHANGE ITEM QUANTITY Enter the item name: Nike Romaleos Enter the new quantity: 3
IF YOU HAVE ANY DOUBTS COMMENT BELOW I WILL BE THERE TO HELP YOU
RATE THUMBSUP PLEASE
ANSWER:
EXPLANATION:
CODE:
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 check = 0; //for (it = item.begin() ; it != item.end(); ++it) for(int i=0;i<item.size();i++) if(item.at(i).GetName() == itemName) cout<<"found...removing "<< item.at(i).GetName() << endl; item.erase(item.begin()+i); } } if(check == 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(i=0;i<item.size();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() { int j=0; //for (it = item.begin() ; it != item.end(); ++it) for(j=0;j<item.size();j++) { cout << item.at(j).GetName() << ": " << item.at(j).GetDescription()<< endl; } if(j == 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(i=0;i<item.size();i++) { cout << item.at(i).GetName() << " "
<< item.at(i).GetQuantity() tot = tot + (item.at(i).GetPrice() * item.at(i).GetQuantity()); } if(i == 0) { cout<<"Shopping cart is empty."<<endl; } } void ShoppingCart::showOption() { cout<<"MENU"<<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;
|
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); cout << endl; cout << "Customer's name: " << custName
<< endl; sCart.setName(custName); sCart.setDate(date); sCart.showOption(); while(option.compare("q") != 0 ) { cout<<"Choose an option: "; getline(cin, option);
{ cout << "Enter the item name: "; getline(cin, name); cout << "Enter the item description: "; getline(cin, desc); cout << "Enter the item price: "; item.SetDescription(desc); item.SetPrice(price); item.SetQuantity(q); sCart.add(item); item.clean(); cin.ignore(); } else if(option.compare("d") == 0) cout << "Enter the item name: "; getline(cin, name); sCart.remove(name); } else if(option.compare("c") == 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("i") == 0) sCart.showDescription(); else if(option.compare("o") == 0) sCart.showCart(); else cout << endl; } cout<<"Program Terminated..."; return 0; } |
RATE THUMBSUP PLEASE
THANKS
Can someone please help me with this Python code? Thank you in advance, Zybooks keeps giving me e...
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...
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 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,...
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...
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() -...
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...
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...
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...
11.11 LAB: Warm up: Online shopping cart (1) Build the ItemToPurchase class with the following specifications: Attributes (6 pts) item_name (string) item_price (float) item_quantity (int) Default constructor (2 pt) Initializes item's name = "none", item's price = 0, item's quantity = 0 Method print_item_cost() Ex. of print_item_cost() output: Bottled Water 10 @ $1 = $10 (2) In the main section of your code, prompt the user for two items and create two objects of the ItemToPurchase class. (4 pts) Ex:...
Please use C Programming language (Not C++)
7.6 LAB*: Warm up: Online shopping cart (Part 1) (1) Create three files to submit: • Item ToPurchase.h - Struct definition and related function declarations • Item ToPurchase.c-Related function definitions • main.c-main function Build the ItemToPurchase struct with the following specifications: • Data members (3 pts) • char itemName • int itemPrice • int itemQuantity • Related functions • MakeltemBlank0 (2 pts) Has a pointer to an item To Purchase parameter. Sets item's...