Thursday, November 27, 2014

C program using function subprogram to process the inventory information

/*………………………………………………………………………………………………
File Name: rec23.c
Program : A menu driven program using function subprogram to process the inventory information
(Like inserting, displaying, searching, list the item details whose prices lies between a ranges etc.) Of items
Author : sujithbaby440@gmail.com
Date : 23-11-2014
………………………………………………………………………………………………*/
#include<stdio.h>
#include<stdlib.h>
typedef struct InventType{
int item_id;
int item_price;
int item_qty;
char item_name[30];
}INVENTORY;
INVENTORY inv[20];
int n,i;
void FnMenu(int *choice);
void FnInsert();
void FnDisplay();
void FnSearch();
void FnListing();
main()
{
int choice;
system("clear");
printf("Menu Driven program to process Inventory Information");
FnMenu(&choice);
while(choice){
switch(choice){
case 1:FnInsert();
FnMenu(&choice);
break;
case 2:FnDisplay();
FnMenu(&choice);
FnMenu(&choice);
break;
case 4:FnListing();
FnMenu(&choice);
break;
case 5:exit(1);
break;
default:printf("Invalid Choice\n");
FnMenu(&choice);
break;
}
}
}
/*...................Function Definition....................*/
void FnMenu(int *choice)
{
printf("\n\t\tMENU\n");
printf("\n1.Inserting item details\n");
printf("2. Displaying the item details\n");
printf("3. Search for items\n");
printf("4. List the items within range\n");
printf("5. Exit\n\n");
printf("Enter your choice:");
scanf("%d",choice);
}
void FnInsert()
{
printf("Program to process inventory information\n");
printf("Enter the number of items:");
scanf("%d",&n);
for(i=1;i<=n;i++){
printf("Enter the item id:");
scanf("%d",&inv[i].item_id);
printf("Enter the item name:");
scanf("%s",inv[i].item_name);
printf("Enter the item price:");
scanf("%d",&inv[i].item_price);
printf("Enter the item Quantity:");
scanf("%d",&inv[i].item_qty);
}
}
void FnDisplay()
{
printf("\t\tINVENTORY\n");
printf("Item Id\tItem Name\tItem Price\tQty\n");
for(i=1;i<=n;i++){
printf("%d\t%s\t\t%d\t\t%d\n",inv[i].item_id,inv[i].item_name,inv[i].item_price,inv[i].item_qty);
}
}
void FnSearch()
{
int new,flag=0;
printf("Enter the item id: ");
scanf("%d",&new);
for(i=1;i<=n;i++){
if(inv[i].item_id==new)
flag=1;
if(flag==1){
printf("\nItem Id:%d\n",inv[i].item_id);
printf("Item Name:%s\n",inv[i].item_name);
printf("Item Price:%d\n",inv[i].item_price);
printf("Item Quantity:%d\n",inv[i].item_qty);
break;
}
}
if(flag==0){
printf("Invalid item id\n");
}
}
void FnListing()
{
int r1,r2;
printf("Enter the price range:");
scanf("%d%d",&r1,&r2);
printf("\n****INVENTORY****\n");
printf("Item Id\tItem Name\tItem Price\tQty\n");
for(i=1;i<=n;i++){
if(inv[i].item_price>=r1&&inv[i].item_price<=r2){
printf("%d\t%s\t\t%d\t\t%d\n",inv[i].item_id,inv[i].item_name,inv[i].item_price,inv[i].item_qty);
}
}
}
MENU
1.Inserting item details
2. Displaying the item details
3. Search for items
4. List the items within range
5. Exit
Enter your choice:1
Program to process inventory information
Enter the number of items:2
Enter the item id:1
Enter the item name:book
Enter the item price:100
Enter the item Quantity:2
Enter the item id:2
Enter the item name:pen
Enter the item price:50
Enter the item Quantity:10
MENU
1.Inserting item details
2. Displaying the item details
3. Search for items
4. List the items within range
5. Exit
Enter your choice:2
INVENTORY
Item Id Item Name Item Price Qty
1 book 100 2
2 pen 50 10
MENU
1.Inserting item details
2. Displaying the item details
3. Search for items
4. List the items within range
5. Exit
Enter your choice: 4
MENU
1.Inserting item details
2. Displaying the item details
3. Search for items
4. List the items within range
5. Exit
Enter your choice:4
Enter the price range:60
120
****INVENTORY****
Item Id Item Name Item Price Qty
1 book 100 2
MENU
1.Inserting item details
2. Displaying the item details
3. Search for items
4. List the items within range
5. Exit
Enter your choice:5
[141740@localhost ~]$

No comments:

Post a Comment