badge

C Program to implement DEPARTMENTAL STORE SYSTEM

Program in c for DEPARTMENTAL STORE SYSTEM....


OUTPUT OF THE PROGRAM:





SOURCE CODE:


#include<stdio.h>
#include<conio.h>
#include<string.h>
#include<stdlib.h>
void main()
{
FILE *fp,*ft;
char another,choice,itemcode[20];
struct store
{
char item_code[20];
char item_name[30];
int per_case_qty;
int case_qty;
int total_qty;
float per_unit_price;
float transport;
float vat;
float profit;
float octory;
float retail_price;
};
struct store s;
int a;
while(1)
{
clrscr();
gotoxy(10,10);
printf("1...Add Records");
gotoxy(10,12);
printf("2...Show Records");
gotoxy(10,14);
printf("3...Modify Records");
gotoxy(10,16);
printf("4...Delete Records");
gotoxy(10,18);
printf("0...EXIT\nENTER UR CHOICE");
fflush(stdin);
choice=getche();
switch(choice)
{
case '1':
fp=fopen("store.txt","w+");
if(fp==NULL)
{
puts("cannot open files");
exit(1);
}

fseek(fp,0,2);
another='y';       /*add*/
while(another =='y')
{
fseek(fp,0,2);
printf("\n Enter the item_code.....");
scanf("%s",&s.item_code);
printf("\n Enter the item_name.....");
scanf("%s",&s.item_name);
printf("\n Enter the per_case_qty.....");
scanf("%d",&s.per_case_qty);
printf("\n Enter the case_qty.....");
scanf("%d",&s.case_qty);
printf("\n Enter the total_qty.....");
s.total_qty=s.per_case_qty * s.case_qty;
printf("%d",s.total_qty);
printf("\n\n Enter the per_unit_price.....");
scanf("%f",&s.per_unit_price);
printf("\n Enter the transport.....");
scanf("%f",&s.transport);
printf("\n Enter the profit.....");
scanf("%f",&s.profit);
printf("\n Enter the vat.....");
scanf("%f",&s.vat);
printf("\n Enter the octory.....");
scanf("%f",&s.octory);
printf("\n Enter retail price.....");
s.retail_price=s.per_unit_price + s.transport + s.profit + s.vat + s.octory;
printf("%f",s.retail_price);
fwrite(&s,sizeof(s),1,fp);
fclose(fp);
printf("add another record (y/n)");
fflush(stdin);
another=getche();
}

break;

case '2':
fp=fopen("store.txt","r");
fseek(fp,0,0);
rewind(fp);
while(fread(&s,sizeof(s),1,fp)==1)
printf("\n itemcode" );
printf(" item_name");
//printf("\n per_case_qty");
//printf("\n case_qty");
printf(" total_qty");
//printf("\n per_unit_price");
printf(" transport");
printf(" profit");
printf("      vat");
//printf("\n octory");
printf("   retail_price");
a=fread(&s,sizeof(s),1,fp);
do
{
printf("\n %s",s.item_code);
printf("        %s",s.item_name);
//printf(" %d",s.per_case_qty);
//printf(" %d",s.case_qty);
printf("        %d",s.total_qty);
//printf(" %f",s.per_unit_price);
printf("       %f",s.transport);
printf("  %f",s.profit);
printf("  %f",s.vat);
//printf(" %f",s.octory);
printf("  %f",s.retail_price);

a=fread(&s,sizeof(s),1,fp);
}
while(a>0);
fclose(fp);
getch();
break;

case '3':
fp=fopen("store.txt","a+");
another='y';
while(another=='y')
{
printf("\n Enter the item_code of item to modify...");
scanf("%s",&itemcode);
rewind(fp);
while(fread(&s,sizeof(s),1,fp)==1)
{
if(strcmp(s.item_code,itemcode)==0)
{
printf("\n item_code....%s",s.item_code);
//scanf("%s",&s.item_code);
printf("\n item_name...%s",s.item_name);
//scanf("%s",&s.item_name);
printf("\n per_case_qty....");
scanf("%d",&s.per_case_qty);
printf("\n case_qty....");
scanf("%d",&s.case_qty);
printf("\n total_qty....");
s.total_qty=s.per_case_qty * s.case_qty;
printf("%d",s.total_qty);
printf("\n per_unit_price.....");
scanf("%f",&s.per_unit_price);
printf("\n transport.....");
scanf("%f",&s.transport);
printf("\n profit.....");
scanf("%f",&s.profit);
printf("\n vat.....");
scanf("%f",&s.vat);
printf("\n octory.....");
scanf("%f",&s.octory);
printf("\n retail price.....");
s.retail_price=s.per_unit_price + s.transport + s.profit + s.vat + s.octory;
printf("%f",s.retail_price);
fwrite(&s,sizeof(s),1,fp);
fclose(fp);
}
else
{
printf(" Record not found");
}
}
printf("\n Modify another records(Y/N)");
fflush(stdin);
another=getch();
}
break;
case '4':
fp=fopen("store.txt","r+");
another='y';
while(another=='y')
{
printf("\n Enter item_code of item to delete");
scanf("%s",&itemcode);
ft=fopen("temp.txt","w+");
rewind(fp);
while(fread(&s,sizeof(s),1,fp)==1)
{
if(strcmp(s.item_code,itemcode)==0)
fwrite(&s,sizeof(s),1,ft);
}
fclose(fp);
fclose(ft);
remove("STORE.txt");
rename("temp.txt","STORE.txt");
fp=fopen("STORE.txt","r+");
printf("delete another record(Y/N)");
fflush(stdin);
another=getche();
}
break;
case '0':
fclose(fp);
exit(0);
}
}
}


/* IF U FOUND ANY PROBLEM IN THIS PROGRAM  OR IF YOU HAVE ANY QUERY RELATED THIS PROGRAM THEN PLEASE COMMENT IN THIS POST OR YOU CAN DIRECTLY MAIL ME ON piyushkhandelwal029@gmail.com . */


THANKU.



SHARE

Admin

  • Image
  • Image
  • Image
  • Image
  • Image
    Blogger Comment
    Facebook Comment

0 comments: