11.11 LAB: Warm up: Online shopping cart
(1) Build the ItemToPurchase class with the following specifications:
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:
Item 1 Enter the item name: Chocolate Chips Enter the item price: 3 Enter the item quantity: 1 Item 2 Enter the item name: Bottled Water Enter the item price: 1 Enter the item quantity: 10
(3) Add the costs of the two items together and output the total
cost. (4 pts)
Ex:
TOTAL COST Chocolate Chips 1 @ $3 = $3 Bottled Water 10 @ $1 = $10 Total: $13
LAB
ACTIVITY
11.11.1: LAB: Warm up: Online shopping cart
Python 3 please
Screenshot of the code:
Sample Output:
Code to copy:
# Define the class ItemToPurchase.
class ItemToPurchase:
# Define its default constructor and initialize the
# class required member variables.
def __init__(self):
self.item_name = "none";
self.item_price = 0;
self.item_quantity = 0;
# Define the method print_item_cost() to display the
# item name, price, quantity, and the item's cost.
def print_item_cost(self):
print(self.item_name + " "
+ str(self.item_quantity)
+ " @ $" + str(self.item_price) + " = $"
+ str(self.item_quantity * self.item_price));
# Define the min() method.
def main():
# Create two objects of the class ItemToPurchase.
item1 = ItemToPurchase();
item2 = ItemToPurchase();
# Prompt the user to input the information of two
# items.
print("Item 1");
print("Enter the item name:")
item1.item_name = input();
print("Enter the item price:")
item1.item_price = int(input());
print("Enter the item quantity:")
item1.item_quantity = int(input());
print("\nItem 2");
print("Enter the item name:")
item2.item_name = input();
print("Enter the item price:")
item2.item_price = int(input());
print("Enter the item quantity:")
item2.item_quantity = int(input());
# Display the item cost along with its name, quantity,
# and price by calling the method print_item_cost()
# over each ItemToPurchase class objects.
print("\nTOTAL COST");
item1.print_item_cost();
item2.print_item_cost();
# Calculate the cost of both items.
item1Cost = item1.item_quantity * item1.item_price;
item2Cost = item2.item_quantity * item2.item_price;
# Add the cost of both items to get the total cost.
total_cost = item1Cost + item2Cost;
# Display the total cost of the items.
print("\nTotal: $" + str(total_cost));
# Call the function main() to start the execution of the
# program.
main()
11.11 LAB: Warm up: Online shopping cart (1) Build the ItemToPurchase class with the following specifications:...
(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: Item 1 Enter the item name: Chocolate...
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,...
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...
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...
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...
*Urgent* I've tried getting help with this a couple times, but nobody has answered my questions, and it's been several days. #################################################################################### This needs to be Python that works in a Zybooks programming window. 1. Build an ItemToPurchase class with the following specifications: Attributes (3 pts) item_name (string) item_price (float) item_quantity (int) Default constructor (1 pt) Initializes item's name = "none", item's price = 0, item's quantity = 0 Method print_item_cost() Example of print_item_cost() output: Bottled Water 10 @ $1...
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....
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() -...
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...