In thisworkshop you are going to use a C structuretype to re
In thisworkshop, you are going to use a C structuretype to represent anItemof an inventory. Apersonis able to viewthe inventory, add an item to the inventory, and check prices for items in the inventory. Here is the C structure type that should be used in this workshop:
structItem{
intsku_;
floatprice_;
intquantity_;
};
sku_: Stock Keeping Unit number for an item.
price_: Price for an item.
quantity_: Quantity of an item.
Also, use constor #define directivesto define the following number:
MAX_ITEMS: the maximum number of items that exists in an inventory. Assume MAX_ITEMSis 10.
In your main function, implement the following steps:
1. Define the following variables in your main program:
structItem item[MAX_ITEMS]; //An array of Item representing the inventory
intsize=0; //Number of items in the inventory. The inventory is initially empty.
2. Display awelcome massage:
Welcome to the Shop
===================
3. Display the following menu, and prompt the user to select anoption from the menu.
Please select from the following options:
1) Display the inventory.
2) Add to the inventory.
0)Exit.
4.You must verify that the input integer is between zero and two inclusive.If the input number is not between zero and two, you must display a warning and prompt the user again. You can assume the user will only enter numbers.The program only exits when the user selects 0 (Exit) on the menu screen (looping required).
5. Depending on the user’s input, one of the following scenarios happens.
Add to the inventory:
Prompt the user to input the SKU number and the quantity of an item that one wants to add to the inventory.
Search through the inventory (the item array) to find if the item exists in the array.
If the item is found in the inventory, do the following:
Update the quantity of the item by adding the quantity read to the quantity of the item in array.
Display a message that the item quantity is successfully updated.
If the item is not found in the inventory, do the following:
If the inventory is full (size== MAX_ITEMS), display the inventory is full.
If the inventory is not full, the function prompts the user to input item price. Then, update the inventory. Hint: Use the inventory array, and size as its index, and assign sku, price and quantity. Increment size.
Display the inventory:
Display the inventory in an informative format. See sample output.
Exit:
Display a goodbye message:
Goodbye!
Your program is complete if your output matches the following output. Red numbers show the user’s input.
Welcome to the Shop Please select from the following options: 1) Display the inventory 2) Add to shop 0) Exit Select8 Invalid input, try again: Please select from the following options: 1) Display the inventory 2) Add to shop 0) Exit. Select2 Please input a SKU number 2341 Quantity3 Price:1xi The item is successfully added to the inventory Please select from the following options: 1) Display the inventory 2) Add to shop. 0) Exit. Select Please input a SKU number 4567 Quantity: Price 98x2 The item is successfully added to the inventory Please select from the following options: 1) Display the inventory 2) Add to shop. 0) Exit. Select;Solution
/*
* C program to display the inventory of items in a store / shop
* The inventory maintains details such as name, price, quantity
* and manufacturing date of each item.
*/
#include <stdio.h>
void main()
{
struct date
{
int day;
int month;
int year;
};
struct details
{
char name[20];
int price;
int code;
int qty;
struct date mfg;
};
struct details item[50];
int n, i;
printf(\"Enter number of items:\");
scanf(\"%d\", &n);
fflush(stdin);
for (i = 0; i < n; i++)
{
fflush(stdin);
printf(\"Item name: \ \");
scanf(\"%s\", item[i].name);
fflush(stdin);
printf(\"Item code: \ \");
scanf(\"%d\", &item[i].code);
fflush(stdin);
printf(\"Quantity: \ \");
scanf(\"%d\", &item[i].qty);
fflush(stdin);
printf(\"price: \ \");
scanf(\"%d\", &item[i].price);
fflush(stdin);
printf(\"Manufacturing date(dd-mm-yyyy): \ \");
scanf(\"%d-%d-%d\", &item[i].mfg.day,
&item[i].mfg.month, &item[i].mfg.year);
}
printf(\" ***** INVENTORY ***** \ \");
printf(\"---------------------------------------------------------
---------\ \");
printf(\"S.N.| NAME | CODE | QUANTITY | PRICE
| MFG.DATE \ \");
printf(\"---------------------------------------------------------
---------\ \");
for (i = 0; i < n; i++)
printf(\"%d %-15s %-d %-5d %-5d
%d/%d/%d \ \", i + 1, item[i].name, item[i].code, item[i].qty,
item[i].price, item[i].mfg.day, item[i].mfg.month,
item[i].mfg.year);
printf(\"---------------------------------------------------------
---------\ \");
}


