Question

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. (2) Build a ShoppingCart namedtuple with the following data attributes and related functions. Note: Some can be function stubs (empty methods) initially, to be completed in later steps. Create a namedtuple named ShoppingCart which has the customer name. date, and cart items as attributes (2 pts) customer_name (string) current_date (string) cart_items (list) Write a function named construct_cart() for ShoppingCart that creates a named tuple with the following specifications: (1 pt) Initializes customer_name = "none", current_date = "January 1, 2016", cart_items to an empty list Functions: add_item() Adds an item to cart_items list. Has parameters ShoppingCart and ItemToPurchase. Does not return anything. remove_item() Removes item from cart_items list. Has a ShoppingCart and a string (an item's name) as parameters. Does not return anything. If item name cannot be found, output this message: Item not found in cart. Nothing removed. modify_item() Modifies an item's description, price, and/or quantity. Has parameters ShoppingCart, and 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. get_num_items_in_cart() (2 pts) Returns quantity of all items in cart. Has a ShoppingCart as a parameter. get_cost_of_cart() (2 pts) Determines and returns the total cost of items in cart. Has a ShoppingCart as a parameter. print_total() Outputs total of objects in cart. Has a ShoppingCart as a parameter. If cart is empty, output this message: SHOPPING CART IS EMPTY print_descriptions() Outputs each item's description. Has a ShoppingCart as a parameter. 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 Hints Use the __main__ statement whenever appropriate. Read section 2.5 - "Importing modules and executing scripts " if you are not familiar with this.

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

#Declare the class ItemT°Purchase 3 class ItemToPurchase: 4 #Parameter Constructor none); item-description = item-price-0,32 #Implement the method print-item-description 34 35 def print item_description(self): 36 string: .format (self.item_name,63 64 65 #prompt the name and description of item,price and Quentity item_name strCinput(Enter the item name:) 67 68 item_de94 95 96 ifCitem.item_name string): del self.cart_items Ci] 97 98 100 101 #set the flag value to true 102 103 104 105 106 107def modify_item(self): 125 126 127 128 129 130 print(InCHANGE ITEM QUANTITY, end-In #Prompt the input item name strCinput156 157 158 159 160 flag-False #IF the value not found if(flag-False): 161 162 163 164 165 166 167 #print the message print(186 def get_cost_of_cart(self): 187 188 189 190 191 total_cost0 cost-0 192 193 194 195 196 197 #Using for-loop to iterate theprint(SHOPPING CART IS EMPTY) 217 218 219 220 221 eLse: output_cartO #Implement the method to print-descriptions 223 224 22248 249 250 251 252 253 tc 0 for item in self.cart.items: print({} {} @ ${} = ${}.forma (item.iten_name, item. item-quantit279 280 281 282 iOutput items\ descriptions\n o - Output shopping cart\n q - Quitln) 283 284 285 command 286 287 #Using310 311 312 313 i f(commanda): #call the method to the add elements to the cart 314 315 316 317 318 319 customer_Cart.add_it340 341 342 343 # Type main section of code here 344 customer_Cart.modify item) 345 #prompt and read the customers name 346 3OUTPUT WILL BE:

Enter customer s name: deepak Enter todays date: 26-05-2019 Customer name: deepak Todays date: 26-05-2019 MENU a - Add item

Add a comment
Know the answer?
Add Answer to:
7.11 LAB: Online shopping cart - Part 2 This program extends the earlier "Online shopping cart" program. (Consid...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Similar Homework Help Questions
  • 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...

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

  • Can someone please help me with this Python code? Thank you in advance, Zybooks keeps giving me e...

    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) item_description (string) - Set to "none" in default constructor Implement the following method for the ItemToPurchase class. print_item_description() - Prints item_description attribute for an ItemToPurchase object. Has an ItemToPurchase parameter. Ex. of...

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

  • 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,...

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

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

  • 11.11 LAB: Warm up: Online shopping cart (1) Build the ItemToPurchase class with the following specifications:...

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

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

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