您好,欢迎访问三七文档
/********超市管理系统程序*******//*董能相*/#includestdio.h#includestring.h#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;isum;i++)if(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(iMAX);printf(\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;isum;i++)if(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);}pr
本文标题:超市管理系统程序
链接地址:https://www.777doc.com/doc-1410067 .html