Question

Please use C Programming language (Not C++)

7.6 LAB*: Warm up: Online shopping cart (Part 1) (1) Create three files to submit: • Item ToPurchase.h - Struct definition an

0 0
Add a comment Improve this question Transcribed image text
Answer #1

ItemToPurchase.h

#ifndef ITEM_TO_PURCHASE_H

#define ITEM_TO_PURCHASE_H

typedef struct ItemToPurchase_struct{

char itemName[50];

int itemPrice;

int itemQuantity;

} ItemToPurchase;

void MakeItemBlank(struct ItemToPurchase_struct item);

void PrintItemCost(struct ItemToPurchase_struct item);

#endif

-----------------------------------------------------------------------------------

ItemToPurchase.c

#include <stdio.h>

#include <stdio.h>

#include<string.h>

#include "ItemToPurchase.h"

void makeItemBlank(struct ItemToPurchase_struct *item){

strcpy((item)->itemName, "None");

(item)->itemPrice=0;

(item)->itemQuantity=0;

}

void printItemCost(struct ItemToPurchase_struct item){

printf("%s %d @ $%d = $%d\n", item.itemName,

item.itemQuantity,item.itemPrice,

((item.itemPrice) * (item.itemQuantity)));

}

#include <stdio.h>

#include <string.h>

#include "ItemToPurchase.h"

int main() {

int total;

ItemToPurchase item1;

ItemToPurchase item2;

printf("Item 1\n");

printf("Enter the item name:\n");

scanf("%[^\t\n]s",item1.itemName);

printf("Enter the item price:\n");

scanf("%d", &(item1.itemPrice));

printf("Enter the item quantity:\n");

scanf("%d", &(item1.itemQuantity));

printf("\n");

printf("Item 2\n");

printf("Enter the item name:\n");

scanf(" %[^\t\n]s",item2.itemName);

printf("Enter the item price:\n");

scanf("%d", &(item2.itemPrice));

printf("Enter the item quantity:\n");

scanf("%d", &(item2.itemQuantity));

printf("\n");

total = (item1.itemPrice * item1.itemQuantity)+ (item2.itemPrice * item2.itemQuantity);

printf("TOTAL COST\n");

printItemCost(item1);

printItemCost(item2);

printf("\nTotal: $%d", total);

return 0;

}

---------------------------------------------------------------------------------------------------------------------------------------------------------

SEE OUTPUT

saved main.c Files http:://ActualMenacingCosmos.rahulkumar29 24 printT Enter the item name:\n; scanf(%[^\t\n] s, item1.item

PLEASE COMMENT if there is any concern.

==========================================

saved main.c Files #include <stdio.h> 1 main.c #include <stdio.h> 2 #include<string.h> #include ItemTo Pu rchase.h void mak

ItemToPurchase.h saved Files #ifndef ITEM_TO_PURCHASE_H 1 main.c #define ITEM_TO_PURCHAS E_H typedef struct ItemToPurchase_st

Add a comment
Know the answer?
Add Answer to:
Please use C Programming language (Not C++) 7.6 LAB*: Warm up: Online shopping cart (Part 1)...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Warm up: Online shopping cart (Part 1)

    8.6 LAB*: Warm up: Online shopping cart (Part 1)(1) Create two files to submit:ItemToPurchase.java - Class definitionShoppingCartPrinter.java - Contains main() methodBuild the ItemToPurchase class with the following specifications:Private fieldsString itemName - Initialized in default constructor to "none"int itemPrice - Initialized in default constructor to 0int itemQuantity - Initialized in default constructor to 0Default constructorPublic member methods (mutators & accessors)setName() & getName() (2 pts)setPrice() & getPrice() (2 pts)setQuantity() & getQuantity() (2 pts)(2) In main(), prompt the user for two items and create...

  • 11.11 LAB: Warm up: Online shopping cart (1) Build the ItemToPurchase class with the following specifications:...

    11.11 LAB: Warm up: Online shopping cart (1) Build the ItemToPurchase class with the following specifications: Attributes (6 pts) item_name (string) item_price (float) item_quantity (int) Default constructor (2 pt) Initializes item's name = "none", item's price = 0, item's quantity = 0 Method print_item_cost() Ex. of print_item_cost() output: Bottled Water 10 @ $1 = $10 (2) In the main section of your code, prompt the user for two items and create two objects of the ItemToPurchase class. (4 pts) Ex:...

  • 4.18 Ch 7 Program: Online shopping cart (continued) (C++) This program extends the earlier "Online shopping...

    4.18 Ch 7 Program: Online shopping cart (continued) (C++) This program extends the earlier "Online shopping cart" program. (solution from previous lab assignment is provided in Canvas). (1) Extend the ItemToPurchase class per the following specifications: Parameterized constructor to assign item name, item description, item price, and item quantity (default values of 0). (1 pt) Public member functions SetDescription() mutator & GetDescription() accessor (2 pts) PrintItemCost() - Outputs the item name followed by the quantity, price, and subtotal PrintItemDescription() -...

  • This program extends the earlier "Online shopping cart" program. (Consider first saving your earlier program).

    Ch 7 Program: Online shopping cart (continued) (Java)This program extends the earlier "Online shopping cart" program. (Consider first saving your earlier program).(1) Extend the ItemToPurchase class per the following specifications:Private fieldsstring itemDescription - Initialized in default constructor to "none"Parameterized constructor to assign item name, item description, item price, and item quantity (default values of 0). (1 pt)Public member methodssetDescription() mutator & getDescription() accessor (2 pts)printItemCost() - Outputs the item name followed by the quantity, price, and subtotalprintItemDescription() - Outputs the...

  • 8.7 LAB*: Program: Online shopping cart (Part 2)

    8.7 LAB*: Program: Online shopping cart (Part 2)Note: Creating multiple Scanner objects for the same input stream yields unexpected behavior. Thus, good practice is to use a single Scanner object for reading input from System.in. That Scanner object can be passed as an argument to any methods that read input.This program extends the earlier "Online shopping cart" program. (Consider first saving your earlier program).(1) Extend the ItemToPurchase class per the following specifications:Private fieldsstring itemDescription - Initialized in default constructor to "none"Parameterized...

  • 7.11 LAB: Online shopping cart - Part 2 This program extends the earlier "Online shopping cart" program. (Consid...

    7.11 LAB: Online shopping cart - Part 2 This program extends the earlier "Online shopping cart" program. (Consider first saving your earlier program). (1) Extend the ItemToPurchase namedtuple to contain a new attribute. (2 pts) item_description (string) - Set to "none" in the construct_item() function Implement the following function with an ItemToPurchase as a parameter. print_item_description() - Prints item_name and item_description attribute for an ItemToPurchase namedtuple. Has an ItemToPurchase parameter. Ex. of print_item_description() output: Bottled Water: Deer Park, 12 oz....

  • 11.12 LAB*: Program: Online shopping cart (continued) This program extends the earlier "Online shopping cart" pr...

    11.12 LAB*: Program: Online shopping cart (continued)This program extends the earlier "Online shopping cart" program. (Consider first saving your earlier program).(1) Extend the ItemToPurchase class to contain a new attribute. (2 pts)item_description (string) - Set to "none" in default constructorImplement the following method for the ItemToPurchase class.print_item_description() - Prints item_description attribute for an ItemToPurchase object. Has an ItemToPurchase parameter.Ex. of print_item_description() output:Bottled Water: Deer Park, 12 oz.(2) Build the ShoppingCart class with the following data attributes and related methods. Note: Some can be method stubs...

  • (1) Build the ItemToPurchase class with the following specifications: Attributes (6 pts) item_name (string) item_price (float)...

    (1) Build the ItemToPurchase class with the following specifications: Attributes (6 pts) item_name (string) item_price (float) item_quantity (int) Default constructor (2 pt) Initializes item's name = "none", item's price = 0, item's quantity = 0 Method print_item_cost() Ex. of print_item_cost() output: Bottled Water 10 @ $1 = $10 (2) In the main section of your code, prompt the user for two items and create two objects of the ItemToPurchase class. (4 pts) Ex: Item 1 Enter the item name: Chocolate...

  • I need help with this assignment, can someone HELP ? This is the assignment: Online shopping...

    I need help with this assignment, can someone HELP ? This is the assignment: Online shopping cart (continued) (C++) This program extends the earlier "Online shopping cart" program. (Consider first saving your earlier program). (1) Extend the ItemToPurchase class per the following specifications: Parameterized constructor to assign item name, item description, item price, and item quantity (default values of 0). (1 pt) Public member functions SetDescription() mutator & GetDescription() accessor (2 pts) PrintItemCost() - Outputs the item name followed by...

  • Need three seperate files. ShoppingCartManager.java ShoppingCart.java ItemsToPurchase.java These are from part 1 what do you mean...

    Need three seperate files. ShoppingCartManager.java ShoppingCart.java ItemsToPurchase.java These are from part 1 what do you mean by deep study 7.25 LAB*: Program: Online shopping cart (Part 2) Note: Creating multiple Scanner objects for the same input stream yields unexpected behavior. Thus, good practice is to use a single Scanner object for reading input from System.in. That Scanner object can be passed as an argument to any methods that read input This program extends the earlier Online shopping cart program (Consider...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT