超市管理系统程序.docx
《超市管理系统程序.docx》由会员分享,可在线阅读,更多相关《超市管理系统程序.docx(20页珍藏版)》请在冰豆网上搜索。
![超市管理系统程序.docx](https://file1.bdocx.com/fileroot1/2023-1/7/5f5f9613-14dd-4a99-8fb2-36af0f426b2e/5f5f9613-14dd-4a99-8fb2-36af0f426b2e1.gif)
超市管理系统程序
/********超市管理系统程序*******/
/*董能相*/
#include
#include
#defineMAX20
#defineN3
#definePAGE2
#definePRINT1printf("-----------------------\n");
#definePRINT2printf("商品号--商品名称--商品种类--销售价格--生产日期(年-月-日)--保质期\n");
#definePRINT3printf("%4d%8s%8s%8d%15d%15d%15-2%d-2%d%10d\n",goods[i].num,goods[i].name,goods[i].kind,goods[i].in_price,goods[i].out_price,goods[i].pro_time,goods[i].save_day)
intsum;/*用来记录商品数目*/
/*日期结构体类型*/
structdate
{intyear;
intmonth;
intdate;
};
/*商品结构体类型*/
structgoods_type
{intnum;/*商品数量*/
charname[10];/*商品名称*/
charkind[10];/*商品种类*/
intamount;/*商品总量*/
intleft_amount;/*商品剩余数量*/
inttotal_price;/*商品总价格*/
intgoods_up;/*商品上限*/
intgoods_down;/*商品下限*/
intin_price;/*进货价格*/
intout_price;/*销售价格*/
intin_num;/*进货数量*/
intout_num;/*售出数量*/
structdatein_time;/*进货日期*/
structdatepro_time;/*生产日期*/
charfactory[10];/*生产厂家*/
intsave_day;/*保质期*/
intprofit;/*获得利润*/
}goods[MAX];/*存放[MAX]种商品记录的结构体数组*/
/*保存信息*/
save_message(intsum)
{FILE*fp;
inti;
if((fp=fopen("supermarket.txt","wb"))==NULL)
{printf("读文件错误!
\n");
return;
}
for(i=0;iif(fwrite(&goods[i],sizeof(structgoods_type),1,fp)!
=1)
printf("写文件错误!
\n");
fclose(fp);
}
/*输入模块*/
input_message()
{inti=0,s=MAX;
clrscr();
printf("\n\n录入商品信息(最多%d种)\n",s);
printf("--------------------------------\n");
do
{printf("\ngood%d",i+1);
printf("\nnum:
");
scanf("%d",&goods[i].num);
printf("\nname:
");
scanf("%s",&goods[i].name);
printf("\nkind:
");
scanf("%s",&goods[i].kind);
printf("\namount:
");
scanf("%d",&goods[i].amount);
printf("\ngoods_up:
");
scanf("%d",&goods[i].goods_up);
printf("\ngoods_down:
");
scanf("%d",&goods[i].goods_down);
printf("\nin_price:
");
scanf("%d",&goods[i].in_price);
printf("\nout_price:
");
scanf("%d",&goods[i].out_price);
printf("\nin_num:
");
scanf("%d",&goods[i].in_num);
printf("\nin_date(yyyy-mm-dd):
");
scanf("%d-%d-%d",&goods[i].in_time.year,&goods[i].in_time.month,&goods[i].in_time.date);
printf("\npro_date(yyyy-mm-dd):
");
scanf("%d-%d-%d",&goods[i].pro_time.year,&goods[i].pro_time.month,&goods[i].pro_time.date);
printf("\nfactory:
");
scanf("%s",&goods[i].factory);
printf("\nsave_day:
");
scanf("%d",&goods[i].save_day);
i++;
}while(iprintf("\n--%d种商品信息输入完毕!
--\n",i);
sum=i;
printf("\npressanykeyreturnmenu!
");
bioskey(0);
}
/*读取信息*/
intread_message()
{FILE*fp;
inti=0;
if((fp=fopen("supermarket.txt","rb"))==NULL)
{printf("\n\n**暂时还没有任何库存信息,按任意键进入主菜单选择基本信息的录入!
**\n");
return;
}while(feof(fp)!
=1)
{fread(&goods[i],sizeof(structgoods_type),1,fp);
if(goods[i].num==0)break;
elsei++;
}
fclose(fp);
return(i);
}
/*输出模块*/
voidoutput_message()
{inti=0,j=0,count,page=1;
clrscr();
printf("\n\n----%d\n\n",page);
PRINT2;
PRINT1;
do
{if(goods[i].num!
=0)
{j++;
if(j%PAGE!
=0)
{PRINT3;
PRINT1;
}
else
{PRINT3;
PRINT1;
if(goods[i+1].num!
=0);
{printf("按任意键继续!
");
bioskey(0);
clrscr();
printf("\n\n--商品信息表--第%d页\n\n",++page);
PRINT2;
PRINT1;
}
}
}
i++;
}while(goods[i].num!
=0);
printf("pressanykeyreturnmenu!
");
bioskey(0);
}
/*添加商品信息*/
insert_message()
{inti=sum,j,flag=0;
charchoice;
clrscr();
printf("\n\n添加一种新商品\n");
printf("--------------\n");
do
{goods[i].num=++sum;
printf("newnum:
%d",goods[i].num);
printf("\nname:
");
scanf("%s",goods[i].name);
printf("\nkind:
");
scanf("%s",goods[i].kind);
printf("\namount:
");
scanf("%d",goods[i].amount);
printf("\ngoods_up:
");
scanf("%d",goods[i].goods_up);
printf("\ngoods_down:
");
scanf("%d",goods[i].goods_down);
printf("\nin_price:
");
scanf("%d",goods[i].in_price);
printf("\nout_price:
");
scanf("%d",goods[i].out_price);
printf("\nin_num:
");
scanf("%d",goods[i].num);
printf("\nin_time:
");
scanf("%d%d%d",goods[i].in_time.year,goods[i].in_time.month,goods[i].in_time.date);
printf("\npro_time:
");
scanf("%d%d%d",goods[i].pro_time.year,
goods[i].pro_time.month,
goods[i].pro_time.date);
printf("\nfactory:
");
scanf("%s",goods[i].factory);
printf("\nsave_day:
");
scanf("%d",goods[i].save_day);
printf("要继续吗?
(Y/N)");
choice=getch();
if(choice=='Y'||choice=='y')
{printf("\n继续!
\n");
i++;
flag=1;
}
elseflag=0;
}while(flag==1);
printf("\npressanykeyreturnmenu!
");
bioskey(0);
}
/*删除商品信息*/
del_message()
{inti=sum,j,flag=0;
charchoice;
clrscr();
printf("\n\n\n");
printf("------------------\n");
do
{goods[i].num=--sum;
printf("\nnum:
");
printf("\nname:
");
scanf("%s",goods[i].name);
printf("\nkind:
");
scanf("%s",goods[i].kind);
printf("\nleft_amount:
");
scanf("%d",goods[i].left_amount);
printf("\ntotal_price:
");
scanf("%d",goods[i].total_price);
printf("\n要继续吗?
(Y/N)");
choice=getch();
if(choice=='Y'||choice=='y');
{printf("\n继续!
\n");
i++;
flag=1;}
}while(flag==1);
printf("\npressanykeyenterthemenu!
");
bioskey(0);
}
/*修改模块*/
revise_message()
{inti=0,choice,revise_num,flag;
do
{clrscr();
printf("\ninputthenumberofthegood:
");
scanf("%d",&revise_num);
for(i=0;iif(goods[i].num==revise_num)
{printf("\n----\n");
PRINT1;
PRINT2;
PRINT3;
printf("\n您要修改哪一项?
\n");
printf("\n1.name\n");
printf("\n2.kind\n");
printf("\n3.out_price\n");
printf("\n4.pro_time\n");
printf("\n5.save_day\n");
printf("\npleasemakeyourchoice(1-5):
");
scanf("%d",&choice);
switch(choice)
{case1:
printf("\nname:
");
scanf("%s",&goods[i].name);break;
case2:
printf("\nkind:
");
scanf("%s",&goods[i].kind);break;
case3:
printf("\nout_price:
");
scanf("%d",&goods[i].out_price);break;
case4:
printf("\npro_time:
");
scanf("%d%d%d",&goods[i].pro_time.year,&goods[i].pro_time.month,
&goods[i].pro_time.date);break;
case5:
printf("\nsave_day:
");
scanf("%d",&goods[i].save_day);break;
}
PRINT1;
PRINT2;
PRINT3;
break;
}
if(i==sum)
{printf("\n该商品不存在!
");
bioskey(0);
}
printf("\n\n要继续吗?
(Y/N)");
choice=getch();
if(choice=='Y'||choice=='y')
{flag=1;
printf("\n继续!
\n");
}
elseflag=0;
}while(flag==1);
printf("\npressanykeyreturnmenu!
");
bioskey(0);
}
/*更新模块*/
renew_message()
{intchoice;
do
{clrscr();
printf("\n\n\n*******更新商品信息*********\n\n");
printf("1.insert_message\n\n");
printf("2.del_message\n\n");
printf("3.revise_message\n\n");
printf("0.returnmenu\n\n");
printf("pleasemakeyourchoice(0-3):
");
scanf("%d",&choice);
switch(choice)
{case1:
insert_message();break;
case2:
del_message();break;
case3:
revise_message();break;
case0:
break;
}
}while(choice!
=0);
}
/*按名称查询*/
inquire_name()
{inti,choice,j=0,inquire_in_price;
charinquire_name[10];
clrscr();
printf("\ninputthenameofthegood:
");
scanf("%s",inquire_name);
for(i=0;iif(strcmp(goods[i].name,inquire_name)==0&&goods[i].num!
=0)
{printf("\n--商品信息--\n");
PRINT1;
PRINT2;
PRINT3;
}
elsej++;
if(j==sum)printf("\n该商品不存在!
");
bioskey(0);
}
/*按类别查询*/
inquire_kind()
{inti=0,choice,j=0,inquire_in_price;
charinquire_kind[10];
clrscr();
printf("\ninputthekindofthegood:
");
scanf("%s",inquire_kind);
if(strcmp(goods[i].kind,inquire_kind)==0&&goods[i].num==!
0);
{printf("\n--商品信息--\n");
PRINT1;
PRINT2;
PRINT3;
}
if(j==sum)printf("\n该商品不存在!
");
bioskey(0);
}
/*按进货时间查询*/
inquire_in_time()
{inti,choice,j=0,inquire_in_price;
structdatein_time;
clrscr();
printf("\ninputtheintimeofthegood:
");
scanf("%d",inquire_in_time);
for(i=0;iif(goods[i].num!
=0)
{printf("\n--商品信息--\n");
PRINT1;
PRINT2;
PRINT3;
}
elsej++;
if(j==sum)printf("该商品不存在!
\n");
bioskey(0);
}
/*按进货量查询*/
inquire_in_num()
{inti,choice,j=0,inquire_in_price;
intinquire_in_num;
clrscr();
printf("\ninputtheinnumberofthegood:
");
scanf("%d",inquire_in_time);
for(i=0;iif(goods[i].num!
=0)
{printf("\n--商品信息--\n");
PRINT1;
PRINT2;
PRINT3;
}
elsej++;
if(j==sum)printf("该商品不存在!
\n");
bioskey(0);
}
/*查询模块*/
inquire_message()
{intchoice;
do
{clrscr();
printf("\n\n\n*****查询商品信息*******\n\n");
printf("1.inquire_name\n\n");
printf("2.inquire_kind\n\n");
printf("3.inquire_in_time\n\n");
printf("4.inquire_in_num\n\n");
printf("0.returnmenu\n\n");
printf("pleasemakeyourchoice(0-4):
");
scanf("%d",&choice);
switch(choice)
{case1:
inquire_name();break;
case2:
inquire_kind();break;
case3:
inquire_in_time();break;
case4:
inquire_in_num();break;
case0:
break;
}
}while(choice!
=0);
}
/*统计利润*/
count_profit()
{inti,choice,j=0,count_num,profit;
charinquire_name[10];
clrscr();
printf("\ninputthenumberofthegood:
");
scanf("%d",&count_num);
for(i=0;iif(goods[i].num==count_num)
{profit=goods[i].out_price-goods[i].in_price;
printf("\nprofit:
");
printf("\n-----------------------------------\n");
printf("\nnumprofit");
printf("\n%25d%13d\n",goods[i].num,profit);
}
elsej++;
if(j==sum)printf("\n该商品不存在!
");
bioskey(0);
}
/*统计进货量*/
count_in_num()
{inti,choice,j=0,count_num,in_num;
charinquire_name[10];
clrscr();
printf("\ninputtheamountofthegood:
");
scanf("%d",&count_in_num);
for(i=0;iif(goods[i].in_num!
=0)
printf("\n%d\n",in_num);
elsej++;
if(j==sum)printf("\n该商品不存在!
");
bioskey(0);
}
/*统计库存量*/
count_full()
{inti,choic,j=0,count_num,full;
intin_num;
intout_num;
charinquire_name[10];
clrscr();
printf("\ninputthenumberofthegood:
");
scanf("%d",&count_full);
for(i=0;iif(goods[i].num!
=0)
{full=goods[i].in_num-goods[i].out_num;
printf("\nfull:
");
printf("\n-----------------------------------\n");
printf("\nnumfull");
printf("\n%25d%13d\n",goods[i].num,full);
}
elsej++;
if(j==sum)printf("