Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Program: Online shopping cart ( Part 2 ) 5 files ( main . c , ShoppingCart.c , ShoppingCart.h , ItemToPurchase.c , ItemtoPurchase.h ) This program
Program: Online shopping cart Part files mainc ShoppingCart.c ShoppingCart.h ItemToPurchase.c ItemtoPurchase.h
This program extends the earlier "Online shopping cart Part program. Consider first saving your earlier program
Step : Extend the ItemToPurchase struct to contain a new data member. pts
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, oz
Step : Build three new files:
ShoppingCart.h struct definition and related function declarations
ShoppingCart.c related function definitions
main.c main function Note: mains functionality differs from the previous program.
Build the ShoppingCart struct with the following data members and related functions.
Data members pts
char customerName
char currentDate
ItemToPurchase cartItems has a maximum of slots can hold up to items of any quantity
int cartSize the number of filled slots in array cartItemsnumber of items in cart of any quantity
Related functions
AddItem
Adds an item to cartItems array. Has parameters of type ItemToPurchase and ShoppingCart. Returns ShoppingCart object.
RemoveItem
Removes item from cartItems array does not just set quantity to ; removed item will not take up a slot in array Has a charan item's name and a ShoppingCart parameter. Returns ShoppingCart object.
If item name cannot be found, output a message: Item not found in cart. Nothing removed.
ModifyItem
Modifies an item's description, price, andor quantity. Has parameters of type ItemToPurchase and ShoppingCart. Returns ShoppingCart object.
GetNumItemsInCart pts
Returns quantity of all items in cart. Has a ShoppingCart parameter.
GetCostOfCart pts
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 a message: SHOPPING CART IS EMPTY
PrintDescriptions
Outputs each item's description. Has a ShoppingCart parameter.
If cart is empty, output a message: SHOPPING CART IS EMPTY
Ex of PrintTotal output:
John Doe's Shopping Cart February
Number of Items:
Nike Romaleos @ $ $
Chocolate Chips @ $ $
Powerbeats Headphones @ $ $
Total: $
Ex of PrintDescriptions output:
John Doe's Shopping Cart February
Item Descriptions
Nike Romaleos: Volt color, Weightlifting shoes
Chocolate Chips: Semisweet
Powerbeats Headphones: Bluetooth headphones
Step : 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. pt
Ex:
Enter customer's name:
John Doe
Enter today's date:
February
Customer name: John Doe
Today's date: February
Step : Implement the following menu functions in main.c
PrintMenu
Prints the following menu of options to manipulate the shopping cart. pt
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
ExecuteMenu
Takes parameters: a character representing the user's choice and a shopping cart. Performs the menu options described below in step according to the user's choice, and returns the shopping cart. pt Step : Implement the menu options
Step a: In main call PrintMenu and prompt for the user's choice of menu options. Each option is represented by a single character.
If an invalid character is entered, continue to prompt for a valid choice. When a valid option is entered, execute the option by calling ExecuteMenu Then, print the menu and prompt for a new option. Continue until the user enters q pt
Hint: Implement Quit before implementing other options. Ex of PrintTotal output:
Step : 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. pt
Ex:
Step : Implement the following menu functions in main.c
PrintMenu
Prints the following menu of options to manipulate the shopping cart. pt
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
ExecuteMenu
Takes parameters: a character representing the user's choice and a shopping cart. Performs the menu options described
below in step according to the user's choice, and returns the shopping cart. pt
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