超市管理系统源程序.docx
- 文档编号:24188603
- 上传时间:2023-05-25
- 格式:DOCX
- 页数:18
- 大小:17.28KB
超市管理系统源程序.docx
《超市管理系统源程序.docx》由会员分享,可在线阅读,更多相关《超市管理系统源程序.docx(18页珍藏版)》请在冰豆网上搜索。
超市管理系统源程序
超市管理系统源程序
#include
#include
#defineMAX20
#defineN3
#definePAGE2
#definePRINT1printf("---------------------\n")
#definePRINT2printf("商品号--商品名称--商品种类--销售价格--生产日期(年-月-日)--保质期\n")
#definePRINT3printf("%4d%s%s%8d%15%-%2d-%2d%10d\n",goods[i].num,goods[i].name,goods[i].kind,goods[i].out_price,goods[i].pro_time.year,goods[i].pro_time.month,goods[i].pro_time.date,goods[i].save_day)
intsum;/*记录商品数目*/
structdate/*日期结构体类型*/
{
intyear;
intmonth;
intdate;
}
structgoods_type/*商品结构体类型*/
{
intsum;
charname[10];
charkind[10];
intamount;
intgoods_up;
intgoods_down;
intin_price;
intout_price;
intin_num;
structdatein_time;
structdatepro_time;
charfactory[10];
intsave_day;
intprofit;
}goods[MAX];/*存放MAX种商品记录的结构体数据*/
save_message(jinsum)/*保存信息*/
{
FILE*fp;
inti;
if((fp=fopen("supermarket.txt","wb"))==NULL)
{
printf("读文件错误!
\n");
return;
}
for(i=0;i if(fwrite(&goods[i],sizeof(structgoods_type),1,fp)! =1) printf("写文件错误! \n"); fclose(fp): } inputmessage()/*输入模块*/ { inti=0,s=MAX; clrscr(); printf("\n\n录入商品信息(最多%d种)\n",s); printf("-------------------------\n"); do { printf("\n第%d种商品",i+1); printf("\n商品号: "); scanf("%d",&goods[i].num); if(goods[i].num==0)break; printf("\n商品名称: "); scanf("%s",goods[i].name); printf("\n商品类别: "); scanf("%s",goods[i].kind); printf("\n商品总量: "); scanf("%s",&goods[i].amout); printf("\n商品上限: "); scanf("%s",&goods[i].goods_up); printf("\n商品下限: "); scanf("%s",&goods[i].goods_down); printf("\n进货价格: "); scanf("%s",&goods[i].in_price); printf("\n销售价格: "); scanf("%s",&goods[i].out_price); printf("\n进货数量: "); scanf("%s",&goods[i].in_num); printf("\n进货日期(yyyy-mm-dd): "); scanf("%d-%d-%d",&goods[i].in_time.year,&goods[i].in_time.month,&goods[i].in_time.date); printf("\n商品名称: "); printf("\n生产日期(yyyy-mm-dd): "); scanf("%d-%d-%d",&goods[i].pro_time.year,&goods[i].pro_time.month,&goods[i].pro_time.date); printf("\n生产厂家: "); scanf("%s",goods[i].factory); printf("\n保质期: "); scanf("%s",goods[i].save_day); i++; }while(i printf("\n--%d种商品信息输入完毕! --\n",i); sum=i; printf("\n按任意键返回主菜单! "); 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); } output_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("按任意键返回主菜单! "); bioskey(0); } insert_message()/*添加商品信息*/ { inti=sum,j,flag=0; charchoice; clrscr(); printf("\n\n添加一种新商品\n"); printf("--------------------\n"); do { goods[i].num=++sum; printf("\n新商品号: %d",goods[i].num); printf("\n商品名称: "); scanf("%s",goods[i].name); printf("\n商品类别: "); scanf("%s",goods[i].kind); printf("\n商品总量: "); scanf("%s",&goods[i].amout); printf("\n商品上限: "); scanf("%s",&goods[i].goods_up); printf("\n商品下限: "); scanf("%s",&goods[i].goods_down); printf("\n进货价格: "); scanf("%s",&goods[i].in_price); printf("\n销售价格: "); scanf("%s",&goods[i].out_price); printf("\n进货数量: "); scanf("%s",&goods[i].in_num); printf("\n进货日期(yyyy-mm-dd): "); scanf("%d-%d-%d",&goods[i].in_time.year,&goods[i].in_time.month,&goods[i].in_time.date); printf("\n商品名称: "); printf("\n生产日期(yyyy-mm-dd): "); scanf("%d-%d-%d",&goods[i].pro_time.year,&goods[i].pro_time.month,&goods[i].pro_time.date); printf("\n生产厂家: "); scanf("%s",goods[i].factory); printf("\n保质期: "); scanf("%s",goods[i].save_day); printf("\n要继续吗? (Y/N)"); choice=getch(); if(choice=='y'||choice=='Y') { printf("\n继续! \n"); i++; flag=1; } elseflag=0; }while(flag==1); printf("\n按任意键返回主菜单! "); bioskey(0); } del_message()/*删除商品信息*/ {;} revise_message()/*修改模块*/ { inti=0,choice,revise_num,flag; do { clrscr(); printf("\n输入要修改的商品号: "); scanf("%d",&revise_num); for(i=0;i if(goods[i].num==revise_num) { printf("\n--商品信息--\n"); PRINT1; PRINT2; PRINT3; printf("\n您要修改那一项? \n"); printf("\n1.名称\n"); printf("\n2.种类\n"); printf("\n3.销售价格\n"); printf("\n4.生产日期\n"); printf("\n5.保质期\n"); printf("\n请选择(1-5)\n"); scanf("%d",&choice); switch(choice) { case1;printf("\n输入修改后的名称: "); scanf("%s",&goods[i].name);break; case2;printf("\n输入修改后的种类: "); scanf("%s",&goods[i].kind);break; case3;printf("\n输入修改后的销售价格: "); scanf("%s",&goods[i].out_price);break; case4;printf("\n输入修改后的生产日期: "); scanf("%d-%d-%d",&goods[i].pro_time.year,&goods[i].pro_time.month,&goods[i].pro_time.date);break; case5;printf("\n输入修改后的保质期: "); scanf("%s",&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("\n按任意键返回主菜单! "); bioskey(0); } renew_message()/*更新模块*/ { intchoice; do { clrscr(); printf("\n\n\n********更新商品信息*******\n\n"); printf("1.添加商品信息\n\n"); printf("2.删除商品信息\n\n"); printf("3.修改商品信息\n\n"); printf("0.返回主菜单\n\n"); printf("请选择(0-3): \n\n"); 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,choixe,j=0,inquire_in_price; charinquire_name[10]; clrscr(); printf("\n输入要查询的商品名称: "); scanf("%s",inquire_name); for(i=0;i if(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()/*按类别查询*/ {;} inquire_count_time() {;} inquire_message()/*查询模块*/ { intchoice; do { clrscr(); printf("\n\n\n*****查询商品信息*******\n\n"); printf("1.按商品名称查询\n\n"); printf("2.按商品类别查询\n\n"); printf("3.按进货量和进货价格查询\n\n"); printf("0.返回主菜单\n\n"); printf("请选择(0-3)"); scanf("%d",&choice); switch(choice) { case1: inquire_name();;break; case2: inquire_kind();;break; case3: inquire_count_time();;break; case0: break; } }while(choice! =0); } count_profit()/*统计利润*/ { inti,choice,j=0,count_num,profit; charinquire_name[10]; clrscr(); printf("\n输入要统计的商品号: "); scanf("%d",&count_num); for(i=0;i if(goods[i].num==count_num) { profit=goods[i].out_price-goods[i].in_price; printf("\n商品利润"); printf("\n-------------------\n"); printf("\n商品号利润"); printf("\n%25d%13d\n",goods[i].num,profit); } elsej++; if(j==sum) printf("\n该商品不存在! "); bioskey(0); } count_in_amount()/*统计进货量*/ {;} count_full()/*统计库存量*/ {;} count_message()/*统计模块*/ { intchoice; do { clrscr(); printf("\n\n\n********统计商品信息*******\n\n"); printf("1.统计某商品的利润\n\n"); printf("2.统计某商品的进货量\n\n"); printf("3.统计同种名称不同货号商品库存量\n\n"); printf("0.返回主菜单\n\n"); printf("请选择(0-3): "); scanf("%d",&choice); switch(choice) { case1: count_profit();break; case2: count_in_amount();break; case3: count_full();break; case0: break; } }while(choice! =0); } sort_amount()/*库存排行*/ { structgoods_type*p,*q[MAX]; inti,j,k; clrscr(); printf("库存排行\n"); printf("----------------------------\n"); printf("\n排名商品号商品名称商品类别库存量\n"); p=goods; for(i=0;i q[i]=p++; for(i=0;i { k=i; for(j=i;j if(q[k]->amount k=j; if(k! =i) { p=q[i];q[i]=q[k];q[k]=p; } } for(i=0;i printf("\n%18d%6d%8d%11s%10d\n",i+1,q[i]->name,q[i]->kind,q[i]->amount); bioskey(0); } sort_profit()/*利润排行*/ {;} sort_out_amount()/*销售量排行*/ {;} sort_message()/*排行模块*/ { intchoice; do { clrscr(); printf("\n\n\n********商品排行信息********\n\n"); printf("1.库存量排行\n\n"); printf("2.利润排行\n\n"); printf("3.销售量排行\n\n"); printf("0.返回主菜单\n\n"); printf("请选择(0-3)\n\n"); scanf("%d",&choice); switch(choice) { case1: sort_amount();;break; case2: sort_profit();;break; case3: sort_out_amount();;break; case0: break; } }while(choice! =0); } main()/*主程序*/ { intchoice; sum=read_message(); bioskey(0); do { clrscr(); printf("\n\n\n*********超市管理系统********\n\n"); printf("1.录入商品信息\n\n"); printf("2.打印商品信息\n\n"); printf("3.更新商品信息\n\n"); printf("4.查询商品信息\n\n"); printf("5.统计商品信息\n\n"); printf("6.商品排行信息\n\n"); printf("请选择(0-6)"); scanf("%d",&choice); switch(choice) { case1: input_message();break; case2: output_message();break; case3: renew_message();break; case4: inquire_message();break; case5: count_message();break; case6: sort_message();break; case0: break; } }while(choice! =0); save_message(sum); printf("\n-以上商品信息已保存! --(文件名: supermarket.txt)\n"); }amount)
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 超市 管理 系统 源程序
![提示](https://static.bdocx.com/images/bang_tan.gif)