Programming Project 9.22.6: •••. Reimplement the CashRegister class so that it keeps track of the price of each added item in a vector. Remove the item_count and total_price data members. Reimplement the clear, add_item, get_total, and get_count member functions. Add a member function display_all that displays the prices of all items in the current sale.

Report
Question

Please briefly explain why you feel this question should be reported.

Report
Cancel

Programming Project 9.22.6: •••. Reimplement the CashRegister class so that it keeps track of the price of each added item in a vector<double>. Remove the item_count and total_price data members. Reimplement the clear, add_item, get_total, and get_count member functions. Add a member function display_all that displays the prices of all items in the current sale.

MathJax Example

Answer ( 1 )

  1. Please briefly explain why you feel this answer should be reported.

    Report
    Cancel
    /* # A simulated cash register that tracks the list of items prices 
    class CashRegister :
        # Constructs a cash register with list of item prices
        def __init__(self) :
            self._prices = []
        
        # Adds an item to this cash register.
        def addItem(self, price) :
            self._prices.append(price)
    
        # Gets the price of all items in the current sale.
        def getTotal(self) :
            total = 0
            for price in self._prices:
                total = total + price
            return total 
    
        # Gets the number of items in the current sale.
        def getCount(self) :
            return len(self._prices)
    
        # Clears the list of item prices
        def clear(self) :
            self._prices = []
    
        # displays all item prices
        def displayAll(self):
            for price in self._prices:
                print(price)
    
    # testing
    
    register1 = CashRegister()
    register1.addItem(3.95)
    register1.addItem(19.95)
    print(register1.getCount()) # prints 2
    print("%.2f" % register1.getTotal()) # prints 23.90 */

Leave an answer

Browse

By answering, you agree to the Terms of Service and Privacy Policy.