NO SCREENSHOTS OF CODE PLEASE POST CODE TO COPY
ONLY!
PLEASE TEST CODE TO WORK ! whoeve is posting the same
screenshot that code doesnt work stop replying
Create online shopping cart(continued) (C) , needs to be
in C programming **do not use C++**
please post copy code. original shopping cart code: from part 1:
need the remaining part of the code
new files needed ShoppingCart.h, ShoppingCart.c, Main.c PLEASE
TEST CODE TO WORK !
my code: need to be fixed NO SCREENSHOTS OF CODE
PLEASE POST CODE TO COPY ONLY!
//ItemToPurchase.h
//Include the required header files.
#ifndef ITEM_TO_PURCHASE_H
#define ITEM_TO_PURCHASE_H
#include <stdio.h>
#include <string.h>
// Define the structure to store the required fields of
//the item to purchase.
typedef struct ItemToPurchase_struct
{
char itemName[50];
int itemPrice;
int itemQuantity;
//Newly added field itemDescription.
char itemDescription[50];
} ItemToPurchase;
// Declare required prototype of the functions.
void MakeItemBlank(ItemToPurchase *item);
void PrintItemCost(ItemToPurchase item);
//Newly added function PrintItemDescription()
void PrintItemDescription(ItemToPurchase item);
#endif
//ItemToPurchase.c
// Include required header files.
#include "ItemToPurchase.h"
//Define the function MakeItemBlank().
void MakeItemBlank(ItemToPurchase *item)
{
//Initialize all the required variables of the
//structure.
strcpy((item) ->itemName, "none");
(item)->itemPrice=0;
(item)->itemQuantity=0;
// Set itemDescription to "none".
strcpy((item)->itemDescription, "none");
}
// Define the function PrintItemCost ().
void PrintItemCost(ItemToPurchase item)
{
//Display the item name, quantity, price, and total
//cost.
printf("%s %d @ $%d = $%d\n", item.itemName,
item.itemQuantity,item.itemPrice,
((item.itemPrice) (item.itemQuantity)));
}
// Define the function PrintItemDescription () to display
//the item's description.
void PrintItemDescription(ItemToPurchase item)
{
printf("%s:%s\n", item.itemName,
item.itemDescription);
}
//ShoppingCart.h
//Include the required header files.
#ifndef SHOPPING_CAR_H
#define SHOPPING_CAR_H
#include "ItemToPurchase.h"
//Define the structure to store the required fields of
//the shopping cart.
typedef struct ShoppingCart_struct
{
ItemToPurchase cartItems[10];
char customerName [100];
char currentDate [100];
int cartSize;
}ShoppingCart;
//Declare the prototype of the required functions.
ShoppingCart AddItem(ItemToPurchase itemToAdd,
ShoppingCart sh_cart);
ShoppingCart RemoveItem(char *itemToRemove,
ShoppingCart sh_cart);
ShoppingCart ModifyItem(ItemToPurchase itemToModify,
ShoppingCart sh_cart);
int GetNumItemsInCart(ShoppingCart sh_cart);
int GetCostofCart(ShoppingCart sh_cart);
void PrintTotal(ShoppingCart sh_cart);
void PrintDescriptions(ShoppingCart sh_cart);
#endif
//ShoppingCart.c
#include "ShoppingCart.h"
ShoppingCart AddItem(ItemToPurchase itemToAdd,
ShoppingCart sh_cart)
{
sh_cart.cartItems(sh_cart.cartSize] = itemToAdd;
sh_cart.cartSize++;
return sh_cart;
}
ShoppingCart RemoveItem(char itemToRemove[],
ShoppingCart sh_cart)
{
int found_index = 0;
int index = 0;
int isFound = 0;
int shopping_cart_size = sh_cart.cartSize;
while(found_index < shopping_cart_size)
{
if(strcmp(itemToRemove,
sh_cart.cartItems[found_index].itemName == 0)
{
isFound = 1;
break;
}
found_index++;
}
if(isFound == 0)
{
printf ("Item not found in cart. Nothing removed.\n");
}
else
{
for(index = found index; index <
shopping_cart_size - 1; index++)
{
sh_cart.cartItems[index] =
sh cart.cartItems[index + 1];
}
sh_cart.cartSize--;
}
return sh_cart;
}
ShoppingCart ModifyItem(ItemToPurchase itemToModify,
ShoppingCart sh_cart)
{
int found index = 0;
int index = 0;
int isFound = 0;
int shopping_cart_size = sh_cart.cartSize;
while(found_index < shopping_cart_size)
{
if(strcmp(itemToModify.itemName,
sh_cart.cartItems[found_index].itemname) == 0)
{
isFound = 1;
break;
}
found_index++;
}
if(isFound == 0)
{
printf("Item not found in cart. Nothing mdified.\n");
}
else
{
if(strcmp(itemToModify.itemDescription, "") != 0)
{
strcpy(sh_cart.cartItems
[found_index].itemDescription,
itemToModify.itemDescription);
}
else if(itemToModify.itemPrice != 0)
{
sh_cart.cartItems[found_index].itemPrice =
itemToModify.itemPrice;
}
//main.c
#include "ShoppingCart.h"
// Define the function printMenu() which will return
a
// char value.
char printMenu()
{
//Declare required variables.
char choice;
char ignore;
//Display the menu of choices.
printf("MENU\n");
printf("a - Add item to cart\n");
printf("r - Remove item from cart\n");
printf("C - Change item quantity\n");
printf("i - Output items' descriptions\n");
printf("O - Output shopping cart\n");
printf("q - Quit\n");
//Prompt the user to enter the required choice.
printf("\nChoose an option: ");
scanf("%c", &choice);
// Store the next line character which will come
when
//a character is prompted.
scanf("%c", &ignore);
//Return the choice value.
return choice;
}
//Start the execution of the main() method.
int main()
{
//Declare required variables.
char option;
ShoppingCart sh;
//Prompt the user to enter the customer's name.
printf("Enter Customer's Name:\n");
fgets(sh.customerName, 100, stdin);
sh.customerName[strlen(sh.customerName) - 1] = '\0';
//Prompt the user to enter the today's date.
printf("Enter Today's Date:\n");
fgets(sh.current Date, 100, stdin);
sh.currentDate[strlen(sh.current Date) - 1] = '\0';
//Initialize the size of the cart to 0.
sh.cartSize = 0;
printf("\n");
//Display the customer name and today's date.
printf("Customer Name: %s\n", sh.customerName);
printf("Today's Date: %s\n", sh.current Date);
printf("\n");
ItemToPurchase item;
// Start a while loop.
while(1)
{
// Call the function printMenu() and store the
//returned value into a char varible option.
option = printMenu();
// Start the switch expression over the value
//stored in the variable option.
switch(option)
{
// Define case a.
case 'a':
printf("ADD ITEM TO CART\n");
// Prompt the user to enter the item name.
printf("Enter the item name:\n");
fgets((item.itemName), 50, stdin);
item.itemName[strlen(item.itemName) - 1] = '\0';
// Prompt the user to enter the item description.
printf("Enter the item description:\n");
fgets((item.itemDescription), 50, stdin);
item.itemDescription[strlen
(item.itemDescription) - 1]= '\0';
//Prompt the user to enter the item price.
printf("Enter the item price:\n");
scanf("%d", &item.itemPrice);
// Prompt the user to enter the item quantity.
printf("Enter the item quantity:\n");
scanf("%d",&item.itemQuantity);
scanf("%c", &option);
//Call the function AddItem() by passing the
//required arguments.
sh = AddItem(item, sh);
printf("\n");
break;
// Define the case r.
case 'r':
printf("REMOVE ITEM FROM CART\n");
char remove_item [50];
//Prompt the user to enter an item name which
//needs to be removed.
printf("Enter name of item to remove:\n");
fgets(remove_item, 50, stdin);
remove_item[strlen(remove_items0 -1] = '\0';
//Call the function RemoveItem() by passing the
//required arguments.
sh = RemoveItem(remove_item, sh);
printf("\n");
break;
// Define the case c.
case 'c':
printf("CHANGE ITEM QUANTITY\n");
char update item [50];
int newQuantity;
ItemToPurchase it;
//Prompt the user to enter the item name whose
//property needs to be changed.
printf("Enter the item name:\n");
fgets(update_item, 50, stdin);
update_item(strlen(update item) - 1] = '\0';
//Prompt the user to enter the new quantity
//value.
printf("Enter the new quantity:\n");
scanf("%d", &newQuantity);
strcpy(it.itemName, update_item);
it.itemQuantity = newQuantity;
//Call the function ModifyItem() and pass the
//required arguments.
sh = ModifyItem(it, sh);
scanf("%c", &option);
printf("\n");
break;
case 'i':
printf("OUTPUT ITEMS' DESCRIPTIONS\N");
// call the function Print Descriptions() by
//passing required ShoppingCart structure
//variable.
PrintDescriptions(sh);
printf("\n");
break;
//Define the case i.
case 'o':
printf("OUTPUT SHOPPING CART\n");
// Call the function PrintTotal() by passing
//required Shopping Cart structure variable.
PrintTotal(sh);
printf("\n");
break;
//Define the case 9.
case 'q':
//Terminate the program.
return 0;
//Define the default case, display an
// appropriate message in case of default case.
default:
printf("Invalid Choice!\n\n");
}
}
return 0;
}
11.17 Ch 7 Program: Online shopping cart (continued) (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 item Description() - set to 'none' in Makeltem Blanko Implement the following related functions for the ItemToPurchase struct • Printitem Description • Has an ItemToPurchase parameter. Ex. of Printitem Description() output: Bottled Water: Deer Park, 12 oz. (2) Create three new files: • Shopping Cart.h - struct definition and related function declarations • Shopping Cart.c-related function definitions • main.c- main() function (Note: main('s functionality differs from the warm up) . Build the Shopping Cart 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) o char customerName [] o 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 Shopping Cart Returns Shopping Cart object. o Removeltem • 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 Shopping Cart parameter. Returns Shopping Cart object. • If item name cannot be found output this message: Item not found in cart. Nothing removed. Modifyltem • Modifies an item's description, price, and/or quantity. Has parameters ItemToPurchase and Shopping Cart. Returns Shopping Cart object. GetNumitemsInCart (2 pts) • Returns quantity of all items in cart. Has a Shopping Cart parameter. o GetCostOfCart0 (2 pts) • Determines and returns the total cost of items in cart. Has a Shopping Cart parameter. PrintTotal · Outputs total of objects in cart. Has a Shopping Cart 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 i @ $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 Shopping Cart (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 Shopping Cart 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 0 - Output shopping cart q - Quit a 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 i @ $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 item To Purchase object before using Modifyitem() function. (5 pts) Ex: CHANGE ITEM QUANTITY Enter the item name: Nike Romaleos Enter the new quantity: 3
LAB ACTIVITY 11.17.1: Ch 7 Program: Online shopping cart (continued) (C) 0/30 Submission Instructions Compile command gcc ItemToPurchase.c ShoppingCart.c main.c -Wall -o a.out We will use this command to compile your code lm Upload your files below by dragging and dropping into the area or choosing a file on your hard drive. Shopping Cart.h Drag file here ItemToPurchase.c Drag file here ItemToPurchase.h Drag file here or Choose on hard drive. or or Choose on hard drive Choose on hard drive main.c Shopping Cart.c Drag file here or Choose on hard drive. Drag file here or Choose on hard drive
Failed to compile 1 م ميم مية مية، مع ميه ميه ميه بالمي ItemToPurchase.c: In function PrintItemCost": ItemToPurchase.c:27:7: error: called object is not a function or function pointer 27 | ((item.itemPrice) (item.itemQuantity))); | wwwwwwwwwwwwwww In file included from ShoppingCart.c:3: ShoppingCart.h:12:1: error: unknown type name 'ItemTo' 12 | ItemTo Purchase cartItems [10]; | * * * * * * ShoppingCart.h:12:17: error: expected '',,, "}, }' or _attribute_' before 'cartItems' 12 | ItemTo Purchase cartItems [10]; I ShoppingCart.h:19:23: error: unknown type name 'ItemTo' 19 | ShoppingCart AddItem (ItemTo Purchase itemToAdd, I ShoppingCart.h:20:1: error: unknown type name 'Shopping'; did you mean "ShoppingCart'? 20 | Shopping Cart sh_cart); | Awwwwwww | ShoppingCart ShoppingCart.h:25:26: error: unknown type name 'ItemTo' 25 | ShoppingCart ModifyItem (ItemTo Purchase itemToModify, | Awwwww ShoppingCart.h:26:1: error: unknown type name 'Shopping' ; did you mean 'ShoppingCart' ? 26 | Shopping Cart sh cart); | wwwwwww | ShoppingCart ShoppingCart.h:28:1: warning: parameter names (without types) in function declaration 28 | int GetNum ItemsInCart (Shopping Cart_sh_cart); مع مع بيع بيع بيع های 1 ShoppingCart.c: In function 'AddItem": ShoppingCart.c:8:10: error: "ShoppingCart' (aka 'struct ShoppingCart_struct'} has no member nan 81 sh_cart.cartItems (sh_cart.cart Size] itemToAdd; | ShoppingCart.c:8:29: error: 'ShoppingCart' {aka 'struct ShoppingCart_struct'} has no member nan 81 sh_cart.cartItems (sh_cart.cart Size] itemToAdd; | ShoppingCart.c:8:34: error: expected before 'Size' 81 sh_cart.cartItems (sh_cart.cart Size] itemToAdd; | AMMA | ) ShoppingCart.c: 8:39: error: expected before ']' token 81 sh_cart.cartItems (sh_cart.cart Size] itemToAdd; , ShoppingCart.c:8:39: error: expected statement before ']' token ShoppingCart.c: 8:41: warning: statement with no effect [-Wunused-value] sh_cart.cartItems (sh_cart.cart Size] itemToAdd; | AMMANAM ShoppingCart.c:9:10: error: "ShoppingCart' (aka 'struct ShoppingCart_struct'} has no member nan 91 sh_cart.cartSizett;
NO SCREENSHOTS OF CODE PLEASE POST CODE TO COPY ONLY! PLEASE TEST CODE TO WORK ! whoeve is posting the same screenshot t
-
answerhappygod
- Site Admin
- Posts: 899604
- Joined: Mon Aug 02, 2021 8:13 am
NO SCREENSHOTS OF CODE PLEASE POST CODE TO COPY ONLY! PLEASE TEST CODE TO WORK ! whoeve is posting the same screenshot t
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!