725 Chapter 7f Use Cartitem Class Chapter 7e Create Class Described Uml Directions Given Q37106743

7.25 Chapter 7F

Use the CartItem class from Chapter 7E

Create the class described by the UML and directions givenbelow.

Test each method as you you enter it by making a main andcalling the functions

ShoppingCart- cart[]:CartItem
– numDiffItems: int+ShoppingCart()

+putInCart(item: CartItem): void
+putInCart(item: string, price: double, qty: int): void

+getCartItem(index: int): CartItem
+getNumDiffItems(): int

+removeFromCart(index: int): void

+numTotalItemsInCart(): int
+costOfCart(): double

+ displayCart():void

  • at top of .h file, declare a constant MAX CART ITEMS and set itequal to 100
  • when declaring the cart instance variable, make the array thesize of the constant
  • Constructor with no arguments
    • Sets numDiffItems to zero
  • putInCart
    • checks to make sure there is room in the array and then putsthe object into the array
    • for
      OR
      OR

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.