,

[SOLVED] CS 17700 – Lab 07

$25

File Name: CS_17700___Lab_07.zip
File Size: 160.14 KB

Categories: , Tags: , ,
5/5 - (1 vote)
q4ZWMheBVBFa-README

Fall 2024 CS 17700 — Lab 07

Submission files: lab07.py

Submission deadline: Monday November 25 @ 11:59 PM

Late deadline: Thursday November 28 @ 11:59 PM (–20% penalty)

Attempts: 10

All times are local to the Purdue West Lafayette campus (Eastern Time)

Objectives:

  • Read formatted data from a file

  • Implement classes based on design criteria

    Description: As part of a new corporate acquisition, you are now tasked with writing software that will help manage the inventory (stock) of several major grocery stores. This includes adding and removing items from the stock, adjusting prices, and calculating what to charge customers when they checkout.

    Task 1: Taking stock (20% of grade)

    • Create a class called Store.

    • The constructor should accept one required positional parameter: stock_file (str).

      • Use the open() function and a for loop to read the contents of the stock_file line- by-line.

      • The file is in comma-separated value format (CSV):

        Item name,Quantity in stock,Price per unit str ,int ,float

      • The constructor should save this data into a dictionary attribute of the class named

        stock with the following format:

        {Item name (str): [Quantity in stock (int), Price per unit (float)], }

      • Warning: you are not permitted to import the csv library; this will earn a score of zero.

    • Your workarea in Vocareum contains several CSV files which will be used to test your program. An example execution with one of the files is shown below.

      Example execution 1:

      >>> kroger = Store(“s_kroger.csv”)

      >>> kroger.stock

      {‘Apple juice’: [7, 2.49],

      ‘Peanut butter’: [9, 1.99],

      ‘Ranch’: [17, 2.29],

      ‘Sour cream’: [14, 2.79],

      ‘Ketchup’: [20, 2.49],

      ‘Mayo’: [18, 3.99],

      ‘Litter’: [0, 11.49],

      ‘Cat food’: [5, 4.29],

      ‘Bread’: [20, 1.79],

      ‘Milk’: [6, 2.79],

      ‘Paper towels’: [15, 9.99],

      ‘Pizza’: [10, 8.99]}

      Task 2: Doing business (20% of grade)

    • Create a Store method named restock which accepts two required positional parameters:

      item (str) and quantity (int).

      • This will adjust the quantity of item in the Store’s stock dictionary.

      • The price is left unchanged.

      • If item did not already exist in the Store’s stock dictionary, then it is added with a

        price of 0.0.

    • Create a Store method named reprice which accepts two required positional parameters:

      item (str) and price (float).

      • This will adjust the price of item in the Store’s stock dictionary.

      • The quantity is left unchanged.

      • If item did not already exist in the Store’s stock dictionary, then it is added with a

        quantity of 0.

    • Some example executions are provided below. The auto-grader may perform additional tests with other data.

      Example execution 2:

      >>> kroger = Store(“s_kroger.csv”)

      >>> kroger.restock(“Apple juice”, 0) # sold out

      >>> kroger.restock(“Popsicles”, 4) # new item: price assumed to be 0.0

      >>> kroger.reprice(“Ranch”, 2.10) # discount

      >>> kroger.reprice(“Ice cream”, 2.99) # new item: quantity assumed to be 0

      (changes from example execution 1 highlighted based on code executed above)

      >>> kroger.stock

      {‘Apple juice’: [0, 2.49],

      ‘Peanut butter’: [9, 1.99],

      ‘Ranch’: [17, 2.1],

      ‘Sour cream’: [14, 2.79],

      ‘Ketchup’: [20, 2.49],

      ‘Mayo’: [18, 3.99],

      ‘Litter’: [0, 11.49],

      ‘Cat food’: [5, 4.29],

      ‘Bread’: [20, 1.79],

      ‘Milk’: [6, 2.79],

      ‘Paper towels’: [15, 9.99],

      ‘Pizza’: [10, 8.99],

      ‘Popsicles’: [4, 0.0],

      ‘Ice cream’: [0, 2.99]}

      Task 3: Welcome valued customer (25% of grade)

    • Create a Store method named cost which accepts one required positional parameter named

      cart (dict) and one optional parameter named checkout (bool, default False). o The cart parameter will be a dictionary of the following form:

      {Item name (str): Purchase quantity (int), …}

      • This method will sum and return the total price (starting from 0.0) of the cart, rounded to two decimal places.

      • Hint: use the built-in round(…, 2) function to perform this rounding.

      • Hint: the customer cannot purchase more items than there are in stock. If the desired purchase quantity exceeds the quantity in stock for an item, then the customer buys all available stock. Likewise, if the customer wants to purchase an item that is not in stock or completely unknown, skip it and move on to the next item.

      • If checkout is True, then update the Store’s stock dictionary to decrease the quantity in stock of each item the customer has bought. Otherwise, no changes to the stock dictionary are made.

    • Some example executions are provided below. The auto-grader may perform additional tests with other data.

      Example execution 3:

      >>> kroger = Store(“s_kroger.csv”)

      >>> kroger.cost({}) # empty cart 0.0

      >>> kroger.cost({“Litter”: 2, “Bread”: 2, “Pizza”: 1, “Toothpicks”: 10})

      12.57

      >>> kroger.stock[“Bread”] == [20, 1.79] # quantity did not change True

      >>> kroger.stock[“Pizza”] == [10, 8.99] # likewise True

      >>> kroger.cost({“Litter”: 2, “Bread”: 2, “Pizza”: 1, “Toothpicks”: 10},

      … checkout=True) 12.57

      (changes from example execution 1 highlighted based on code executed above)

      >>> kroger.stock

      {‘Apple juice’: [7, 2.49],

      ‘Peanut butter’: [9, 1.99],

      ‘Ranch’: [17, 2.29],

      ‘Sour cream’: [14, 2.79],

      ‘Ketchup’: [20, 2.49],

      ‘Mayo’: [18, 3.99],

      ‘Litter’: [0, 11.49],

      ‘Cat food’: [5, 4.29],

      ‘Bread’: [18, 1.79],

      ‘Milk’: [6, 2.79],

      ‘Paper towels’: [15, 9.99],

      ‘Pizza’: [9, 8.99]}

      Task 4: Competition (35% of grade)

    • Create a Store subclass named Costco.

    • The class constructor should accept two required positional parameters: stock_file (str) and discount (float).

      • Hint: add the following line of code to your new constructor to reuse the constructor from the parent (super) class Store:

        super().  init  (stock_file)

      • The value of the discount parameter should be saved as an attribute for use below.

    • Create a Costco method named cost which accepts one required positional parameter named

      cart (dict) and one optional parameter named checkout (bool, default False).

      • This method will work the same as the Store.cost method, but the total price will be reduced by the discount passed to the constructor. For example, if

        discount == 0.2, then a 20% discount is applied to the entire cart (i.e. the total price will be 80% of what it would be at a generic Store).

      • Hint: use the following piece of code in your new method to reuse the method from the parent (super) class Store:

        super().cost(cart, checkout)

      • Hint: as in Task 3, use the built-in round(…, 2) function to round the return value.

    • Some example executions are provided below. The auto-grader may perform additional tests with other data.

      Example execution 4:

      >>> costco = Costco(“s_kroger.csv”, 0.02)

      >>> costco.discount 0.02

      >>> costco.cost(

      … {“Litter”: 2, “Bread”: 2, “Pizza”: 1, “Toothpicks”: 10},

      … checkout=True) 12.32

      >>> costco.stock

      {‘Apple juice’: [7, 2.49],

      ‘Peanut butter’: [9, 1.99],

      ‘Ranch’: [17, 2.29],

      ‘Sour cream’: [14, 2.79],

      ‘Ketchup’: [20, 2.49],

      ‘Mayo’: [18, 3.99],

      ‘Litter’: [0, 11.49],

      ‘Cat food’: [5, 4.29],

      ‘Bread’: [18, 1.79],

      ‘Milk’: [6, 2.79],

      ‘Paper towels’: [15, 9.99],

      ‘Pizza’: [9, 8.99]}

      Policies:

  • Review the syllabus for policies regarding extensions and academic integrity.

  • All submissions must be made through Vocareum. No work will be accepted via any other method.

  • Your code must be placed into a file named lab07.py inside of the work/ folder in Vocareum. No variation is permitted.

  • You may make up to 10 submissions. Each submission will produce feedback from the auto-grader.

  • NEW: For this assignment, your final score in Vocareum will be the maximum (best) score you obtained on any submission you made, regardless of whether it was the final submission or not.

  • You may make a private post on Ed if you believe your assignment was incorrectly scored by the auto- grader. This must be done within 5 days of the score entering the Brightspace gradebook.

    Unit testing: Please refer to the Lab 04 handout for more information on how your work will be graded.

  • DO NOT CALL input() or print() ANYWHERE except inside the   main  block (if any).

Notes on CSV files: Please refer to the Lab 06 handout.

Shopping Cart
[SOLVED] CS 17700 - Lab 07[SOLVED] CS 17700 – Lab 07
$25