You are to write a program to produce an inventory report for a local company. Your input will be item name, item number, quantity, price per item, safe stock value. The following shows which columns the input will be in:
item name item number quantity price safe stock
20 chars 5 char 3 char 6 chars 3 chars
Output will be as follows:
item number item name quantity price price*quantity %ofStock flag
You will put a symbol in the flag field it he inventory quantity is less than the safe stock value.
This tells the company that they are getting too low on this item and need to build up the stock.
Print the report in sorted ordered, sorted on item number.
Indicate the total value of the stock.
Indicate the percentage of total inventory value to the total value of the highest single item in inventory. Print the item and its information. (Print this item again at the end of the table.)
You must use the struct data structure and functions.
Use ‘typedef’ for array declarations.
Your input file will be found in invt.dat
The input looks like this:
Wong Batts 98723 243 6.45 200
Widgets No Two 83209 970 17.50 800
HumpBack Whale Songs 74329 42 23.70 50
Frozen Ice Cubes 73922 100 0.15 250
Plastic Ice Cubes 10044 450 0.60 540
Canned Solar Winds 23923 12 550.00 5
Sented Toe Jamm 18492 14 0.50 20
UnSented Toe Jam 18499 23 .74 20
Backwards Left Turns 87293 5 34.95 12
El Slick Slider 38324 15 225.00 18
Meals for Up Chuck 62042 20 16.50 24
Super House Cleaner 71083 14 69.85 18
Stars Dancing Shoes 23934 80 22.50 75
LowRider Briches 98744 138 45.95 125
HighRider Shoes 12283 372 35.95 400
Colored Pie Charts 51121 60 1.50 30
LensLess Saftey Glas 44433 22 2.10 35
Used Boat Anchors 73277 6 17.50 7
main.c
#include <stdio.h>
#include <stdlib.h>
typedef struct node{
char name[20];
int itemNumber;
int quantity;
int price;
int safelock;
struct node *ptr;
} node;
/*
* This function is used to insert a node in the linked list.
* Node will be added in sorted order on basis of item number
*/
node* insert(node* head, char *name, int itemNumber, int quantity,
int price, int safelock) {
node *temp, *prev, *next;
// create a temporary node
temp = (node*)malloc(sizeof(node));
// populate the node with information
strcpy(temp->name, "");
strcpy(temp->name, name);
temp->itemNumber = itemNumber;
temp->quantity = quantity;
temp->price = price;
temp->safelock = safelock;
temp->ptr = NULL;
// add the node to proper location in linked list
if(!head){
head=temp;
} else{
prev = NULL;
next = head;
while(next && next->itemNumber<=itemNumber){
prev = next;
next = next->ptr;
}
if(!next){
prev->ptr = temp;
} else{
if(prev) {
temp->ptr = prev->ptr;
prev-> ptr = temp;
} else {
temp->ptr = head;
head = temp;
}
}
}
return head;
}
/*
* function used to cleanup the linked list after use
*/
void free_list(node *head) {
node *prev = head;
node *cur = head;
while(cur) {
prev = cur;
cur = prev->ptr;
free(prev);
}
}
/*
* Driver function to test
*/
int main(){
FILE *inptr;
node *head, *p;
head = NULL;
// try getting input file stream
inptr =
fopen("C:\\Users\\ykgupta\\Documents\\df\\SD\\invt.dat","r");
// in case if there is some issue in opening files
if(inptr == NULL) {
printf("Error!");
exit(1);
}
// to read the line
char c[500];
while(fgets(c, 500, inptr)!=NULL) {
char *array[10];
int i=0;
array[i] = strtok(c," ");
while(array[i]!=NULL)
{
array[++i] = strtok(NULL," ");
}
i--;
int safelock = atoi(array[i--]);
int price = atoi(array[i--]);
int quantity = atoi(array[i--]);
int itemNum = atoi(array[i--]);
char name[300];
strcpy(name,"");
int j=0;
for(j=0; j<=i; j++) {
strcat(name, array[j]);
strcat(name, " ");
}
head = insert(head, name, itemNum, quantity, price,
safelock);
/* printf("%s\n", name);
printf("%d\n", itemNum);
printf("%d\n", quantity);
printf("%d\n", price);
printf("%d\n", safelock); */
}
// find the highest value among all records
p =head;
double highestVal = 0;
while(p) {
if(p->quantity * p->price > highestVal) {
highestVal = p->quantity * p->price;
}
p = p->ptr;
}
// printing the records
printf("\nThe records with more than safelock::\n");
p =head;
while(p) {
if(p->quantity < p->safelock) {
char c[100];
printf("%s\t\t\t", p->name);
printf("%d\t", p->itemNumber);
printf("%d\t", p->quantity);
printf("%d\t", p->price);
printf("%d\t", p->quantity * p->price);
printf("%.2f %%\n", p->quantity * p->price * 100/highestVal
);
}
p = p->ptr;
}
printf("Highest values is %.2f", highestVal);
free_list(head);
return 0;
}
invt.bat
Wong Batts 98723 243 6.45 200
Widgets No Two 83209 970 17.50 800
HumpBack Whale Songs 74329 42 23.70 50
Frozen Ice Cubes 73922 100 0.15 250
Plastic Ice Cubes 10044 450 0.60 540
Canned Solar Winds 23923 12 550.00 5
Sented Toe Jamm 18492 14 0.50 20
UnSented Toe Jam 18499 23 .74 20
Backwards Left Turns 87293 5 34.95 12
El Slick Slider 38324 15 225.00 18
Meals for Up Chuck 62042 20 16.50 24
Super House Cleaner 71083 14 69.85 18
Stars Dancing Shoes 23934 80 22.50 75
LowRider Briches 98744 138 45.95 125
HighRider Shoes 12283 372 35.95 400
Colored Pie Charts 51121 60 1.50 30
LensLess Saftey Glas 44433 22 2.10 35
Used Boat Anchors 73277 6 17.50 7
Ouput:
Get Answers For Free
Most questions answered within 1 hours.