Implement in C Programing 7.10.1: LAB: Product struct 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 productCode 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 Product.c   #include #include #include "Product.h" /* Type your code here */ Product.h #ifndef PRODUCT_H_ #define PRODUCT_H_ //TODO: Create Product struct /* Type your code here */   #endif main.c   #include #include   #include "Product.h"   int main() { char code[20]; char productCode[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(productCode, product); printf("Name: %s\n", productCode); printf("Price: %.2lf\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 = SellInventory(num, product); GetCode(productCode, product); printf("Name: %s\n", productCode); printf("Price: %.2lf\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(productCode, product); printf("Name: %s\n", productCode); printf("Price: %.2lf\n", GetPrice(product)); printf("Count: %d\n", GetCount(product));   return 0; }

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
100%

Implement in C Programing

7.10.1: LAB: Product struct

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 productCode
  • 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

Product.c

 

#include <stdio.h>
#include <string.h>

#include "Product.h"

/* Type your code here */

Product.h

#ifndef PRODUCT_H_
#define PRODUCT_H_

//TODO: Create Product struct


/* Type your code here */

 

#endif

main.c

 

#include <stdio.h>
#include <string.h>
 
#include "Product.h"
 
int main() {
char code[20];
char productCode[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(productCode, product);
printf("Name: %s\n", productCode);
printf("Price: %.2lf\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 = SellInventory(num, product);
GetCode(productCode, product);
printf("Name: %s\n", productCode);
printf("Price: %.2lf\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(productCode, product);
printf("Name: %s\n", productCode);
printf("Price: %.2lf\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 3 steps with 4 images

Blurred answer
Knowledge Booster
Linked List Representation
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