当前位置:文档之家› 超市管理系统-C语言

超市管理系统-C语言

西安邮电大学高级语言课程设计报告题目:超市管理系统院系名称:理学院专业名称:应用物理学班级:1301学生姓名:王松学号(8位):07132022指导教师:王西龙设计起止时间:2014年06月19日~2014年06月27日1:程序模型2:原函数概况1:创建函数void start(); /*启动界面*/void input(); /*商品数据信息输入函数*/void change(); /*商品数据信息修改函数*/void dele(); /*给定指定商品名称,删除商品信息*/ void output(); /*商品信息输出*/void search(); /*商品信息查找*/void mima();/*密码程序*/void colour();//颜色选择void huanying();2:商品信息录入input()3:商品信息的修改Change()4:商品信息的删除Dele()5:商品信息的查询Seaerch()6:系统颜色选择Colour()7:退出系统3:详细设计过程1:结构体变量的定义struct MarketGoods /*存数商品信息的结构体*/{char goods_id[30]; /*商品编号*/char goods_name[30]; /*商品名称*/double goods_price; /*商品价格*/double goods_discount;/*商品折扣*/int goods_amount;/*商品总数目*/int goods_remain;/*商品剩余数目*/}goods[COUNT];int count=0; /*全局变量,用于保存实际上有多少个商品*/2:欢迎界面void huanying(){printf("\t\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\n");printf("\t\3 欢迎使用\3\n");printf("\t\3 \3\n");printf("\t\3 \3\n");printf("\t\3 超市管理系统\3\n");printf("\t\3 \3\n");printf("\t\3 \3\n");printf("\t\3 \4\4\4\4\4\4 \3\n");printf("\t\3 \3\n");printf("\t\3 \5\5\5\5\5\5\5\5\5 \3\n");printf("\t\3 \3\n");printf("\t\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\n");}3:密码登陆void mima(){// char pass[6]={'1','2','3','4','5','6'};/*假设密码长度是6*/char pass[]={"123456"};/*假设密码长度是6*/char str[6],ch;int i=0;int flag=0;printf(" 请输入密码:");fflush(stdin);for(i=0;i<6;i++){ch=getch(); /*读取字符,不显示*/str[i]=ch;putchar('*');}for(i=0;i<6;i++){if(str[i]!=pass[i]){flag=1;break;}}if(flag){printf("\n密码错误,登录失败!请重新登录\n");mima();}else printf("\n登录成功\n");getch();system("cls");start();}4:系统选择界面void start() /*启动菜单*/{int chi;printf(" 超市商品管理系统\n");printf("********************************************\n");printf("********************************************\n");printf(" 1.商品信息的录入:\n");printf(" 2.商品信息的修改:\n");printf(" 3.删除某个商品信息:\n");printf(" 4.查找商品信息:\n");printf(" 5.颜色选择:\n");printf(" 0.退出程序\n");printf("********************************************\n");printf("********************************************\n");printf(" 输入你的选择: ");scanf("%d",&chi); /*根据你的选择执行相应的函数*/if(chi==1) input();elseif(chi==2) change();else if(chi==3) dele();else if(chi==4) search();else if(chi==5) colour();else if(chi==0){printf("你已经退出超市商品管理系统!谢谢您的使用,再见\n");exit(0);}else{printf(" You Enter The Choice Is Not valid ! \n");getch();system("cls");start();}}void huanying(){printf("\t\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\n");printf("\t\3 欢迎使用\3\n");printf("\t\3 \3\n");printf("\t\3 \3\n");printf("\t\3 超市管理系统\3\n");printf("\t\3 \3\n");printf("\t\3 \3\n");printf("\t\3 \4\4\4\4\4\4 \3\n");printf("\t\3 \3\n");printf("\t\3 \5\5\5\5\5\5\5\5\5 \3\n");printf("\t\3 \3\n");printf("\t\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\n");}5:商品信息的录入void input() /*数据录入*/{FILE *fp;char flag[20];fp=fopen("e:/student.txt","wt");do{printf("请输入你的商品信息:\n"); /*录入商品的信息*/printf("商品编号:");scanf("%s",goods[count].goods_id);printf("商品名字:");scanf("%s",goods[count].goods_name);printf("商品价格:");scanf("%lf",&goods[count].goods_price);printf("商品折扣:");scanf("%lf",&goods[count].goods_discount);printf("商品总数目:");scanf("%d",&goods[count].goods_amount);printf("商品剩余数目:");scanf("%d",&goods[count].goods_remain);count++; /*存数的商品数加一*/printf("是否继续输入数据y是n否: "); /*是否还想继续输入数据*/scanf("%s",flag);}while(strcmp(flag,"y")==0||strcmp(flag,"Y")==0);fwrite(&goods,sizeof(struct MarketGoods),count,fp);fclose(fp);output(); /*调用显示商品数据*/getch();system("cls");start();}6:商品信息的修改void change() /*数据修改*/{FILE *fp;int i,m=0;char ch[20],a[20];fp=fopen("e:/student.txt","rt");while(fread(&goods[m],sizeof(struct MarketGoods),1,fp)!=NULL){m++;}fclose(fp);printf("\nyou sure want change goodsInfor y/n): "); /*根据商品的id来修改数据*/scanf("%s",ch);if(strcmp(ch,"y")==0||strcmp(ch,"Y")==0){printf("\nenter you want change goods_id:");scanf("%s",a);for(i=0;i<count;i++){if(strcmp(goods[i].goods_id,a)==0){printf("\nyou sure want change goods name(y/n): ");scanf("%s",ch);if(strcmp(ch,"y")==0||strcmp(ch,"Y")==0){printf("\nname:");scanf("%s",goods[i].goods_name);}printf("\nyou sure want change goods price(y/n): ");scanf("%s",ch);if(strcmp(ch,"y")==0||strcmp(ch,"Y")==0){printf("\nprice");scanf("%lf",&goods[i].goods_price);}printf("\nyou sure want goods discount(y/n): ");scanf("%s",ch);if(strcmp(ch,"y")==0||strcmp(ch,"Y")==0){printf("\ndiscount");scanf("%lf",&goods[i].goods_discount);}printf("\nyou sure want goods amount(y/n): ");scanf("%s",ch);if(strcmp(ch,"y")==0||strcmp(ch,"Y")==0){printf("\namount");scanf("%d",&goods[i].goods_amount);}printf("\nyou sure want goods remain(y/n): ");scanf("%s",ch);if(strcmp(ch,"y")==0||strcmp(ch,"Y")==0){printf("\nremain"); scanf("%d",&goods[i].goods_remain);}}}}fwrite(&goods,sizeof(struct MarketGoods),count,fp);fclose(fp);output();getch();system("cls");start();}7:商品信息的删除void dele() /*数据删除*/{FILE *fp;int i,m=0,j;char ch[20],c[20];fp=fopen("e:/student.txt","rt");while(fread(&goods[m],sizeof(struct MarketGoods),1,fp)!=NULL){printf("%s",goods[m].goods_id);m++;}fclose(fp);printf("\nenter you want delete name :\n"); /*根据商品的名称来删除数据*/ printf("name:");scanf("%s",c);for(i=0;i<count;i++){if(strcmp(c,goods[i].goods_name)==0)break; /*找到,即跳出循环*/for(j=i;j<count-1;j++)goods[j]=goods[j+1];}printf("\t\t\tyou had delete %s\n",c);count--;fp=fopen("e:/student.txt","wt");fwrite(&goods,sizeof(struct MarketGoods),count,fp);fclose(fp);output();getch();system("cls");start();}8:商品信息查询void search() /*数据查找*/{FILE *fp;int i,m=0;char a[20];fp=fopen("e:/student.txt","rt");while(fread(&goods[m],sizeof(struct MarketGoods),1,fp)!=NULL){printf("%s",goods[m].goods_name);m++;}printf("\nenter you want look name:"); /*根据商品的名称来查找数据*/scanf("%s",a);for(i=0;i<m;i++){if(strcmp(goods[i].goods_name,a)==0)printf("%s %s %lf %lf %d %d \n",goods[i].goods_id,goods[i].goods_name,goods[i].goods_price,goods[i].goods_dis count,goods[i].goods_amount,goods[i].goods_remain);}getch();system("cls");start();}9:系统颜色选择void colour(){int a;printf("\n\n\t\t选择以下方案\n");printf("\n\n\t\t1**********红底黑字\n");printf("\n\n\t\t2**********白底黑子");printf("\n\n\t\t3**********黑底红字");printf("\n\n\t\t4**********绿底蓝字");printf("\n\n\t\t5**********黄底蓝字");printf("\n\n\t\t6**********系统默认");printf("\n\n\t\t\t\t请挑选您喜欢的颜色<1-6>....");scanf("%d",&a);switch(a){case 1:system("color 40"); break;case 2:system("color 70"); break;case 3:system("color 04"); break;case 4:system("color 21"); break;case 5:system("color 65"); break;case 6:system("color la"); break;default:printf("\n\n\t\t\t\t输入无效");{getch();colour();}}start();}10:商品信息输出void output() /*数据输出*/{ FILE *fp;int i,m=0;fp=fopen("e:/student.txt","rt");while(fread(&goods[m],sizeof(struct MarketGoods),1,fp)!=NULL){m++;}fclose(fp);printf(" 编号名称价格折扣总数目剩余数目\n");for(i=0;i<m;i++){printf("%s %s %lf %lf %10d %10d \n",goods[i].goods_id,goods[i].goods_name,goods[i].goods_price,goods[i].goods_discount,goods[i].goods_amount,goods[i].goods_remain);}getch();system("cls");start();}11:退出系统void start() /*启动菜单*/{int chi;printf(" 超市商品管理系统\n");printf("********************************************\n");printf("********************************************\n");printf(" 1.商品信息的录入:\n");printf(" 2.商品信息的修改:\n");printf(" 3.删除某个商品信息:\n");printf(" 4.查找商品信息:\n");printf(" 5.颜色选择:\n");printf(" 0.退出程序\n");printf("********************************************\n");printf("********************************************\n");printf(" 输入你的选择: ");scanf("%d",&chi); /*根据你的选择执行相应的函数*/if(chi==1) input();elseif(chi==2) change();else if(chi==3) dele();else if(chi==4) search();else if(chi==5) colour();else if(chi==0){printf("你已经退出超市商品管理系统!谢谢您的使用,再见\n");exit(0);4:调试分析调试过程中,会有很多的错误。

相关主题