7.7 Ch 7 Program: Online shopping cart (continued) (C)
This program extends the earlier \"Online shopping cart\" program.(Consider first saving your earlier program).
(1) Extend the ItemToPurchase struct to contain a new datamember. (2 pt)
- char itemDescription[ ] - set to \"none\" in MakeItemBlank()
Implement the following related functions for the ItemToPurchasestruct.
- PrintItemDescription()
- Has an ItemToPurchase parameter.
Ex. of PrintItemDescription() output:
Bottled Water: Deer Park, 12 oz.
(2) Create three new files:
- ShoppingCart.h - struct definition and related functiondeclarations
- ShoppingCart.c - related function definitions
- main.c - main() function (Note: main()'s functionality differsfrom the warm up)
Build the ShoppingCart struct with the following data membersand related functions. Note: Some can be function stubs (emptyfunctions) initially, to be completed in later steps.
- Data members (3 pts)
- char customerName [ ]
- char currentDate [ ]
- ItemToPurchase cartItems [ ] - has a maximum of 10 slots (canhold up to 10 items of any quantity)
- int cartSize - the number of filled slots in array (number ofitems in cart of any quantity)
- Related functions
- AddItem()
- Adds an item to cartItems array. Has parameters ItemToPurchaseand ShoppingCart. Returns ShoppingCart object.
- RemoveItem()
- Removes item from cartItems array (does not just set quantityto 0; removed item will not take up a slot in array). Has a char[](an item's name) and a ShoppingCart parameter. ReturnsShoppingCart object.
- If item name cannot be found, output this message: Item notfound in cart. Nothing removed.
- ModifyItem()
- Modifies an item's description, price, and/or quantity. Hasparameters ItemToPurchase and ShoppingCart. Returns ShoppingCartobject.
- GetNumItemsInCart() (2 pts)
- Returns quantity of all items in cart. Has a ShoppingCartparameter.
- GetCostOfCart() (2 pts)
- Determines and returns the total cost of items in cart. Has aShoppingCart parameter.
- PrintTotal()
- Outputs total of objects in cart. Has a ShoppingCartparameter.
- If cart is empty, output this message: SHOPPING CART ISEMPTY
- PrintDescriptions()
- Outputs each item's description. Has a ShoppingCartparameter.
Ex. of PrintTotal() output:
John Doe's Shopping Cart - February 1, 2016Number of Items: 8Nike Romaleos 2 @ $189 = $378Chocolate Chips 5 @ $3 = $15Powerbeats 2 Headphones 1 @ $128 = $128Total: $521
Ex. of PrintDescriptions() output:
John Doe's Shopping Cart - February 1, 2016Item DescriptionsNike Romaleos: Volt color, Weightlifting shoesChocolate Chips: Semi-sweetPowerbeats Headphones: Bluetooth headphones
(3) In main(), prompt the user for a customer's name and today'sdate. Output the name and date. Create an object of typeShoppingCart. (1 pt)
Ex.
Enter Customer's Name:John DoeEnter Today's Date:February 1, 2016Customer Name: John DoeToday's Date: February 1, 2016
(4) Implement the PrintMenu() function. PrintMenu() has aShoppingCart parameter, and outputs a menu of options to manipulatethe shopping cart. Each option is represented by a singlecharacter. Build and output the menu within the function.
If the an invalid character is entered, continue to prompt for avalid choice. Hint: Implement Quit before implementing otheroptions. Call PrintMenu() in the main() function. Continue toexecute the menu until the user enters q to Quit. (3 pts)
Ex:
MENUa - Add item to cartr - Remove item from cartc - Change item quantityi - Output items' descriptionso - Output shopping cartq - QuitChoose an option:
(5) Implement the \"Output shopping cart\" menu option. (3 pts)
Ex:
OUTPUT SHOPPING CARTJohn Doe's Shopping Cart - February 1, 2016Number of Items: 8Nike Romaleos 2 @ $189 = $378Chocolate Chips 5 @ $3 = $15Powerbeats Headphones 1 @ $128 = $128Total: $521
(6) Implement the \"Output item's description\" menu option. (2pts)
Ex.
OUTPUT ITEMS' DESCRIPTIONSJohn Doe's Shopping Cart - February 1, 2016Item DescriptionsNike Romaleos: Volt color, Weightlifting shoesChocolate Chips: Semi-sweetPowerbeats Headphones: Bluetooth headphones
(7) Implement \"Add item to cart\" menu option. (3 pts)
Ex:
ADD ITEM TO CARTEnter the item name:Nike RomaleosEnter the item description:Volt color, Weightlifting shoesEnter the item price:189Enter the item quantity:2
(8) Implement the \"Remove item from cart\" menu option. (4pts)
Ex:
REMOVE ITEM FROM CARTEnter name of item to remove:Chocolate Chips
(9) Implement \"Change item quantity\" menu option. Hint: Makenew ItemToPurchase object before using ModifyItem() function.(5 pts)
Ex:
CHANGE ITEM QUANTITYEnter the item name:Nike RomaleosEnter the new quantity:3