Programmer

Tuesday, 29 May 2018

Product Management Project Using Structure in C Programming..! (Add, Display, Search, Delete)





//Product Management Project
#include<stdio.h>
#include<conio.h>
#include<process.h>
#include<string.h>
int size=4;
struct product
{
int id;
char name[20];
int price;
int qun;
long amt;
}s[15]={
{1,"Pen",10,1000,10000},
{2,"Pencil",5,500,2500},
{3,"Eraser",3,670,2010},
{4,"Notebook",30,500,1500}
       };

void entry()
{
clrscr();
printf("Enter Product ID :");
scanf("%d",&s[size].id);
printf("Enter Product Name :");
fflush(stdin);
gets(s[size].name);
printf("Enter Product Price :");
scanf("%d",&s[size].price);
printf("Enter Prodcut Quantity :");
scanf("%d",&s[size].qun);
s[size].amt=s[size].qun*s[size].price;
}

void header()
{
int i;
printf("\tP_ID \t P_Name \t P_Price \t P_Quantity \t P_Amount\n");
for(i=1;i<=80;i++)
printf("*");
}
void display()
{
int i;
clrscr();
header();
for(i=0;i<size;i++)
{
printf("\t%3d\t %7s\t %7d\t %7d %14ld\n",s[i].id,s[i].name,s[i].price,s[i].qun,s[i].amt);
}
}

void search()
{
int id,i,found=0,p;
clrscr();
printf("Enter Product ID to Search :");
scanf("%d",&id);
for(i=0;i<size;i++)
{
if(id==s[i].id)
{
p=i;
found++;
}
}
if(found>0)
{
printf("Product ID : %d\n",s[p].id);
printf("Product Name : %s\n",s[p].name);
printf("Prodcut Price : %d\n",s[p].price);
printf("Product Quantity: %d\n",s[p].qun);
}
else
{
textcolor(RED+BLINK);
printf("Product Not Found..");
textcolor(7);
}
}

void del()
{
char pname[20];
int i,p,found=0;
clrscr();
printf("Enter Product Name to Delete Product :");
fflush(stdin);
gets(pname);
for(i=0;i<size;i++)
{
if(stricmp(pname,s[i].name)==0)
{
p=i;
found++;
}
}
if(found>0)
{
printf("Product ID : %d\n",s[p].id);
printf("Product Name : %s\n",s[p].name);
printf("Prodcut Price : %d\n",s[p].price);
printf("Product Quantity: %d\n\n\n",s[p].qun);

textcolor(GREEN+BLINK);
cprintf("Product Deleted Successfully..!");
textcolor(7);

for(i=0;i<p;i++)
{
s[p]=s[p+1];
}
size--;
}
else
{
textcolor(RED+BLINK);
cprintf("Product Not Found");
textcolor(7);
}
}

void main()
{
int ch;
do
{
clrscr();
printf("\n\n\n\n");
printf("\t\t\t************************\n");
printf("\t\t\t*   MENU        *\n");
printf("\t\t\t************************\n");
printf("\t\t\t* 0. Exit        *\n");
printf("\t\t\t* 1. Add Product       *\n");
printf("\t\t\t* 2. Display Product   *\n");
printf("\t\t\t* 3. Search Product    *\n");
printf("\t\t\t* 4. Delete Produtct   *\n");
printf("\t\t\t************************\n");
printf("\t\t\tEnter Your Choice :");
scanf("%d",&ch);

switch(ch)
{
case 0: exit(0);
break;

case 1: entry();
size++;
break;

case 2: display();
break;

case 3: search();
break;

case 4: del();
break;

default:
textcolor(RED+BLINK);
cprintf("Wrong Input");
textcolor(7);
}
getch();
}while(ch);
}


No comments:

Post a Comment

Program To Print Particular Line From File.

#include<fstream.h> #include<conio.h> #include<stdlib.h> void main() { ifstream fin; int count=0,num,l=1; char ...