asked 177k views
1 vote
This program extends the earlier "Online shopping cart" program. (Consider first saving your earlier program).

(1) Extend the ItemToPurchase struct to contain a new data member. (2 pt)

char itemDescription[ ] - set to "none" in MakeItemBlank()
Implement the following related functions for the ItemToPurchase struct.

PrintItemDescription()
Has an ItemToPurchase parameter.

(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 (3 pts)
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 of type 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 of type ItemToPurchase and ShoppingCart. Returns ShoppingCart object.
GetNumItemsInCart() (2 pts)
Returns quantity of all items in cart. Has a ShoppingCart parameter.
GetCostOfCart() (2 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 this message: SHOPPING CART IS EMPTY
PrintDescriptions()
Outputs each item's description. Has a ShoppingCart parameter.

(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. (1 pt)

(4) Implement the PrintMenu() function in main.c to print the following menu of options to manipulate the shopping cart. (1 pt)
(5) Implement the ExecuteMenu() function in main.c that takes 2 parameters: a character representing the user's choice and a shopping cart. ExecuteMenu() performs the menu options (described below) according to the user's choice, and returns the shopping cart. (1 pt)


(6) 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() and overwrite the shopping cart with the returned shopping cart. Then, print the menu and prompt for a new option. Continue until the user enters 'q'. Hint: Implement Quit before implementing other options. (1 pt)

(7) Implement the "Output shopping cart" menu option in ExecuteMenu(). (3 pts)
8) Implement the "Output item's description" menu option in ExecuteMenu(). (2 pts)
(9) Implement "Add item to cart" menu option in ExecuteMenu(). (3 pts)
(10) Implement the "Remove item from cart" menu option in ExecuteMenu(). (4 pts)
(11) Implement "Change item quantity" menu option in ExecuteMenu(). Hint: Make new ItemToPurchase object before using ModifyItem() function. (5 pts)

asked
User Amin Y
by
7.8k points

2 Answers

2 votes

Answer:

To create an online shopping cart. You need to do the following:

Update the ItemToPurchase struct to include a new data member called itemDescription.

Create three new files: ShoppingCart.h, ShoppingCart.c, and main.c.

Build the ShoppingCart struct with the following data members: customerName, currentDate, cartItems (which can hold up to 10 items of any quantity), and cartSize.

Implement the AddItem, RemoveItem, ModifyItem, GetNumItemsInCart, GetCostOfCart, PrintTotal, and PrintDescriptions functions for the ShoppingCart struct.

In the main function, prompt the user for a customer's name and today's date, and create an object of type ShoppingCart.

Implement a menu of options to manipulate the shopping cart in the PrintMenu function in main.c.

Implement the ExecuteMenu function in main.c to perform the menu options according to the user's choice.

Implement the "Output shopping cart" menu option in ExecuteMenu.

Implement the "Output item's description" menu option in ExecuteMenu.

Implement the "Add item to cart" menu option in ExecuteMenu.

Implement the "Remove item from cart" menu option in ExecuteMenu.

Implement the "Change item quantity" menu option in ExecuteMenu.

Note: Each step has a point value assigned to it, and some steps have hints provided.

answered
User Keyfer Mathewson
by
7.8k points
7 votes

Final answer:

The student's question involves expanding an online shopping cart program by adding new features and functions in C. This includes implementing a struct for items with descriptions, creating separate files for organization, and allowing the user to manipulate the shopping cart through a menu interface in the main function.

Step-by-step explanation:

An existing programming project on an online shopping cart system. In particular, the student must enhance a struct representing an item in the cart to include a description and create several functions to manipulate a shopping cart struct (e.g., adding and removing items, calculating totals). This will involve using arrays, strings, custom data structures, and functions to create an interactive program in the C programming language. Moreover, the main function should allow users to interface with the shopping cart, providing options to view, add, or remove items, and change their quantities. This expansion of the online shopping cart system illustrates the typical steps of growing a basic program into a more functional and user-interactive application.

Steps to Enhance the Online Shopping Cart Program

  1. Add a new data member 'itemDescription' to the ItemToPurchase struct and implement related functions.
  2. Create separate files for struct definitions, function declarations, and main function logic (ShoppingCart.h, ShoppingCart.c, main.c).
  3. Build the ShoppingCart struct with data members such as customerName, currentDate, cartItems array, and cartSize.
  4. Implement related functions like AddItem, RemoveItem, ModifyItem, GetNumItemsInCart, GetCostOfCart, PrintTotal, PrintDescriptions.
  5. In main.c, collect customer information, create a ShoppingCart object, and provide a menu with options to manage the shopping cart.
  6. Use a loop and a switch or if-else control structure in main to handle user input and call the appropriate functions based on the menu's options.
answered
User Nitasha
by
8.3k points