Question
Final Project 1 (C Programming) Warm up: Online shopping cart (C) (1) Create three files to submit: ItemToPurchase.h - Struct definition and related function declarations
Final Project 1 (C Programming)
Warm up: Online shopping cart (C)
(1) Create three files to submit:
- ItemToPurchase.h - Struct definition and related function declarations
- ItemToPurchase.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
- MakeItemBlank() (2 pts)
- Has a pointer to an ItemToPurchase parameter.
- Sets item's name = "none", item's price = 0, item's quantity = 0
- PrintItemCost()
- Has an ItemToPurchase parameter.
Ex. of PrintItemCost() output:
Bottled Water 10 @ $1 = $10
(2) In main(), prompt the user for two items and create two objects of the ItemToPurchase struct. Before prompting for the second item, enter the following code to allow the user to input a new string. c is declared as a char. (2 pts)
c = getchar();
while(c != ' ' && c != EOF) {
c = getchar();
}
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. (2 pts) Ex:
TOTAL COST
Chocolate Chips 1 @ $3 = $3
Bottled Water 10 @ $1 = $10
Total: $13
Project Problem:
Program: Online shopping cart (continued) (C)
This program extends the earlier "Online shopping cart" program covered in class. (Consider first saving your earlier program).
(1) Extend the ItemToPurchase struct to contain a new data member.
- char itemDescription[ ] - set to "none" in MakeItemBlank()
Implement the following related functions for the ItemToPurchase struct.
- 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 function declarations
- ShoppingCart.c - related function definitions
- main.c - main() function (Note: main()'s functionality differs from the warm up)
Build the ShoppingCart struct with the following data members and related functions. Note: Some can be function stubs (empty functions) initially, to be completed in later steps.
- Data members
- char customerName [ ]
- char currentDate [ ]
- ItemToPurchase cartItems [ ] - has a maximum of 10 slots (can hold up to 10 items of any quantity)
- int cartSize - the number of filled slots in array cartItems [ ] (number of items in cart of any quantity)
- Related functions
- AddItem()
- Adds an item to cartItems array. Has parameters ItemToPurchase and ShoppingCart. Returns ShoppingCart object.
- RemoveItem()
- Removes item from cartItems array (does not just set quantity to 0; removed item will not take up a slot in array). Has a char[ ](an item's name) and a ShoppingCart parameter. Returns ShoppingCart object.
- If item name cannot be found, output this message: Item not found in cart. Nothing removed.
- ModifyItem()
- Modifies an item's description, price, and/or quantity. Has parameters ItemToPurchase and ShoppingCart. Returns ShoppingCart object.
- GetNumItemsInCart()
- Returns quantity of all items in cart. Has a ShoppingCart parameter.
- GetCostOfCart()
- Determines and returns the total cost of items in cart. Has a ShoppingCart parameter.
- PrintTotal()
- Outputs total of objects in cart. Has a ShoppingCart parameter.
- If cart is empty, output this message: SHOPPING CART IS EMPTY
- PrintDescriptions()
- Outputs each item's description. Has a ShoppingCart parameter.
Ex. of PrintTotal() output:
John Doe's Shopping Cart - February 1, 2016
Number of Items: 8
Nike Romaleos 2 @ $189 = $378
Chocolate Chips 5 @ $3 = $15
Powerbeats 2 Headphones 1 @ $128 = $128
Total: $521
Ex. of PrintDescriptions() output:
John Doe's Shopping Cart - February 1, 2016
Item Descriptions
Nike Romaleos: Volt color, Weightlifting shoes
Chocolate Chips: Semi-sweet
Powerbeats Headphones: Bluetooth headphones
(3) In main(), prompt the user for a customer's name and today's date. Output the name and date. Create an object of type ShoppingCart. Ex.
Enter Customer's Name:
John Doe
Enter Today's Date:
February 1, 2016
Customer Name: John Doe
Today's Date: February 1, 2016
(4) Implement the PrintMenu() function. PrintMenu() has a ShoppingCart parameter, and outputs a menu of options to manipulate the shopping cart. Each option is represented by a single character. Build and output the menu within the function.
If the an invalid character is entered, continue to prompt for a valid choice. Hint: Implement Quit before implementing other options. Call PrintMenu() in the main() function. Continue to execute the menu until the user enters q to Quit. Ex:
MENU
a - Add item to cart
r - Remove item from cart
c - Change item quantity
i - Output items' descriptions
o - Output shopping cart
q - Quit
Choose an option:
(5) Implement the "Output shopping cart" menu option. Ex:
OUTPUT SHOPPING CART
John Doe's Shopping Cart - February 1, 2016
Number of Items: 8
Nike Romaleos 2 @ $189 = $378
Chocolate Chips 5 @ $3 = $15
Powerbeats Headphones 1 @ $128 = $128
Total: $521
(6) Implement the "Output item's description" menu option. Ex.
OUTPUT ITEMS' DESCRIPTIONS
John Doe's Shopping Cart - February 1, 2016
Item Descriptions
Nike Romaleos: Volt color, Weightlifting shoes
Chocolate Chips: Semi-sweet
Powerbeats Headphones: Bluetooth headphones
(7) Implement "Add item to cart" menu option. Ex:
ADD ITEM TO CART
Enter the item name:
Nike Romaleos
Enter the item description:
Volt color, Weightlifting shoes
Enter the item price:
189
Enter the item quantity:
2
(8) Implement the "Remove item from cart" menu option. Ex:
REMOVE ITEM FROM CART
Enter name of item to remove:
Chocolate Chips
(9) Implement "Change item quantity" menu option. Hint: Make new ItemToPurchase object before using ModifyItem() function. Ex:
CHANGE ITEM QUANTITY
Enter the item name:
Nike Romaleos
Enter the new quantity:
3
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started