12.13 Program: Online shopping cart (continued) (C not C++) This program extends
ID: 3572758 • Letter: 1
Question
12.13 Program: Online shopping cart (continued) (C not 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 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.
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 (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 (number of items in cart of any quantity)
Related functionsAddItem()
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 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() (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.
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. (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
(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. (3 pts)
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. (3 pts)
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. (2 pts)
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. (3 pts)
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. (4 pts)
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. (5 pts)
Ex:
CHANGE ITEM QUANTITY
Enter the item name: Nike Romaleos
Enter the new quantity: 3
L
Lab Submission
12.13.1: Program: Online shopping cart (continued) (C)
Instructions
Deliverables
main.c
,
ShoppingCart.c
,
ShoppingCart.h
,
ItemToPurchase.h
and
ItemToPurchase.c
We will expect the above file(s) to be submitted
Earlier Program:
/**********************ItemToPurchase.h*********/
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define MAX_NAME_SIZE 256
static int len =2;
/*Structre declarations*/
struct ItemToPurchase{
char itemName[128];
int itemPrice;
int itemQuantity;
};
/*functions declarations and object of structure*/
struct ItemToPurchase item[2];
void MakeItemBlank();
void PrintItemCost();
/****************************ItemToPurchase.c*******************/
#include "ItemToPurchase.h"//including .h file
/*Initially initialising with default values*/
void MakeItemBlank() {
int i;
char temp[10]="none";
for(i=0;i<len;i++) {
strcpy(item[i].itemName,temp);
item[i].itemPrice=0;
item[i].itemQuantity=0;
}
}
/*PrintItemCost method will calculate cost of all item
* printing cost and name and total cost of particular item
* printing Total cost of all items */
void PrintItemCost() {
/*Variable declarations*/
int totalCost=0;
int cost=0;
int i;
printf("TOTAL COST ");
/*for loop for calculating cost*/
for(i=0;i<len;i++) {
cost=(item[i].itemPrice*item[i].itemQuantity);
printf("%s %d @ $%d=$%d ",item[i].itemName,item[i].itemQuantity,item[i].itemPrice,cost);
totalCost+=cost;
cost=0;
}
printf("Total:$%d ",totalCost);
}
/*****************main.c****************/
#include "ItemToPurchase.c"
/*Main function start*/
int main(){
int i;
char name[128];
/*Prompt for user input for number of items*/
printf("Please Enter number of Items ");
scanf("%d",&len);
/*prompt for user inputs*/
for(i=0;i<len;i++) {
printf("Item %d ",(i+1));
printf("Enter the item name:");
scanf(" %[^ ]s", name);
strcpy(item[i].itemName,name);
printf("Enter the item price:");
scanf("%d",&item[i].itemPrice);
printf("Enter the item quantity:");
scanf("%d",&item[i].itemQuantity);
}
PrintItemCost();//calling function for printing total cost
return 0;
}
Instructions
Deliverables
main.c
,
ShoppingCart.c
,
ShoppingCart.h
,
ItemToPurchase.h
and
ItemToPurchase.c
We will expect the above file(s) to be submitted
Explanation / Answer
Hii there,
I have tried to include to ShoppingCart.h and ShoppingCart.c files here.
Hope it may help you out
ShoppingCart.c
ShoppingCart.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.