Answered step by step
Verified Expert Solution
Link Copied!

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 2)5 files (main.c, ShoppingCart.c, ShoppingCart.h, ItemToPurchase.c, ItemtoPurchase.h)
This program extends the earlier "Online shopping cart (Part 1)" program. (Consider first saving your earlier program).
Step 1: Extend the ItemToPurchase struct to contain a new data member. (2 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, 12 oz.
Step 2: Build 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 previous program.)
Build the ShoppingCart struct with the following data members and related functions.
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 a 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 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 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 2 Headphones: Bluetooth headphones
Step 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)
Ex:
Enter customer's name:
John Doe
Enter today's date:
February 1,2016
Customer name: John Doe
Today's date: February 1,2016
Step 4: Implement the following menu functions in main.c
PrintMenu()
Prints the following menu of options to manipulate the shopping cart. (1 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 2 parameters: a character representing the user's choice and a shopping cart. Performs the menu options described below in step 5, according to the user's choice, and returns the shopping cart. (1 pt) Step 5: Implement the menu options
Step 5a: 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'.(1 pt)
Hint: Implement Quit before implementing other options. Ex. of PrintTotal() output:
Step 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)
Ex:
Step 4: Implement the following menu functions in main.c
PrintMenu()
Prints the following menu of options to manipulate the shopping cart. (1 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 2 parameters: a character representing the user's choice and a shopping cart. Performs the menu options described
below in step 5, according to the user's choice, and returns the shopping cart. (1 pt)
image text in transcribed

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Learning PostgreSQL

Authors: Salahaldin Juba, Achim Vannahme, Andrey Volkov

1st Edition

178398919X, 9781783989195

More Books

Students also viewed these Databases questions

Question

what are types of economic and non economic decisions?

Answered: 1 week ago

Question

How should Disney manage their global diversity?

Answered: 1 week ago