Given main(), build a struct called Product that will manage product inventory. Product struct has three data members: a product code (string), the product's price (double), and the number count of product in inventory (int). Assume product code has a maximum length of 20.

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

Given main(), build a struct called Product that will manage product inventory. Product struct has three data members: a product code (string), the product's price (double), and the number count of product in inventory (int). Assume product code has a maximum length of 20.

1 #include <stdio.h>
2 #include <string.h>
4 #include "Product.h"
5
6/* Type your code here */
Current file: Product.c
1 #ifndef PRODUCT_H_
2 #define PRODUCT_H_
3
4 //TODO: Create Product struct
5
6
7 /* Type your code here */
8
9
10
11 #endif
Current file: Product.h
Transcribed Image Text:1 #include <stdio.h> 2 #include <string.h> 4 #include "Product.h" 5 6/* Type your code here */ Current file: Product.c 1 #ifndef PRODUCT_H_ 2 #define PRODUCT_H_ 3 4 //TODO: Create Product struct 5 6 7 /* Type your code here */ 8 9 10 11 #endif Current file: Product.h
Given main(), build a struct called Product that will manage product inventory. Product struct has three data members: a product code
(string), the product's price (double), and the number count of product in inventory (int). Assume product code has a maximum length of 20.
Implement the Product struct and related function declarations in Product.h, and implement the related function definitions in Product.c as
listed below:
• Product InitProduct(char *code, double price, int count) - set the data members using the three parameters
• Product SetCode(char *code, Product product) - set the product code (i.e. SKU234) to parameter code
• void GetCode(char *productCode, Product product) - return the product code in product Code
• Product SetPrice(double price, Product product) - set the price to parameter product
• double GetPrice(Product product) - return the price
• Product SetCount(int count, Product product) - set the number of items in inventory to parameter num
• int GetCount(Product product) - return the count
• Product AddInventory(int amt, Product product) - increase inventory by parameter amt
• Product SellInventory(int amt, Product product) - decrease inventory by parameter amt
Ex. If a new Product struct is created with code set to "Apple", price set to 0.40, and the count set to 3, the output is:
Name: Apple
Price: 0.40
Count: 3
Ex. If 10 apples are added to the Product struct's inventory, but then 5 are sold, the output is:
Name: Apple
Price: 0.40
Count: 8
Ex. If the Product struct's code is set to "Golden Delicious", price is set to 0.55, and count is set to 4, the output is:
Name: Golden Delicious
Price: 0.55
Count: 4
1 #include <stdio.h>
2 #include <string.h>
3
4 #include "Product.h"
5
6 int main() {
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43 }
char code [20];
char product Code [20];
strcpy(code, "Apple");
double price = 0.40;
int num= 3;
Product product = InitProduct (code, price, num);
// Test 1 - Are instance variables set/returned properly?
GetCode (product Code, product);
printf("Name: %s\n", product Code);
printf("Price: %.21f\n", GetPrice (product));
printf("Count: %d\n\n", GetCount (product));
// Test 2 - Are instance variables set/returned properly after adding and selling?
num = 10;
product = AddInventory (num, product);
num = 5;
product = Sell Inventory (num, product);
GetCode (product Code, product);
printf("Name: %s\n", product Code);
printf("Price: %.21f\n", GetPrice (product));
printf("Count: %d\n\n", GetCount (product));
// Test 3 - Do setters work properly?
strcpy(code, "Golden Delicious");
product SetCode (code, product);
price = 0.55;
product = SetPrice (price, product);
num = 4;
product = SetCount (num, product);
GetCode (product Code, product);
printf("Name: %s\n", product Code);
printf("Price: %.21f\n", GetPrice (product));
printf("Count: %d\n", GetCount (product));
return 0;
Transcribed Image Text:Given main(), build a struct called Product that will manage product inventory. Product struct has three data members: a product code (string), the product's price (double), and the number count of product in inventory (int). Assume product code has a maximum length of 20. Implement the Product struct and related function declarations in Product.h, and implement the related function definitions in Product.c as listed below: • Product InitProduct(char *code, double price, int count) - set the data members using the three parameters • Product SetCode(char *code, Product product) - set the product code (i.e. SKU234) to parameter code • void GetCode(char *productCode, Product product) - return the product code in product Code • Product SetPrice(double price, Product product) - set the price to parameter product • double GetPrice(Product product) - return the price • Product SetCount(int count, Product product) - set the number of items in inventory to parameter num • int GetCount(Product product) - return the count • Product AddInventory(int amt, Product product) - increase inventory by parameter amt • Product SellInventory(int amt, Product product) - decrease inventory by parameter amt Ex. If a new Product struct is created with code set to "Apple", price set to 0.40, and the count set to 3, the output is: Name: Apple Price: 0.40 Count: 3 Ex. If 10 apples are added to the Product struct's inventory, but then 5 are sold, the output is: Name: Apple Price: 0.40 Count: 8 Ex. If the Product struct's code is set to "Golden Delicious", price is set to 0.55, and count is set to 4, the output is: Name: Golden Delicious Price: 0.55 Count: 4 1 #include <stdio.h> 2 #include <string.h> 3 4 #include "Product.h" 5 6 int main() { 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 } char code [20]; char product Code [20]; strcpy(code, "Apple"); double price = 0.40; int num= 3; Product product = InitProduct (code, price, num); // Test 1 - Are instance variables set/returned properly? GetCode (product Code, product); printf("Name: %s\n", product Code); printf("Price: %.21f\n", GetPrice (product)); printf("Count: %d\n\n", GetCount (product)); // Test 2 - Are instance variables set/returned properly after adding and selling? num = 10; product = AddInventory (num, product); num = 5; product = Sell Inventory (num, product); GetCode (product Code, product); printf("Name: %s\n", product Code); printf("Price: %.21f\n", GetPrice (product)); printf("Count: %d\n\n", GetCount (product)); // Test 3 - Do setters work properly? strcpy(code, "Golden Delicious"); product SetCode (code, product); price = 0.55; product = SetPrice (price, product); num = 4; product = SetCount (num, product); GetCode (product Code, product); printf("Name: %s\n", product Code); printf("Price: %.21f\n", GetPrice (product)); printf("Count: %d\n", GetCount (product)); return 0;
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 5 steps with 4 images

Blurred answer
Knowledge Booster
User Defined DataType
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education