超市管理系统-C语言
(完整word版)c语言程序设计超市管理系统

实验题目:超市管理系统一、实验目的1.熟悉 c 语言的编译连接和运行过程。
2.掌握 c 语言的数据类型,熟悉整型、实型、字符型变量的定义方式及如何给它们赋值。
3.掌握if 语句及switch 语句的运用方法及嵌套应用方法。
4.掌握实现循环结构的三种语句while 、do-while. 、for 的使用。
5.掌握函数的定义方法和调用方法。
6.能够采用模块化思想调试程序。
二.实验内容1.编写程序并进行调试运行。
2.输入商品资料,并保存于文件。
每件商品包含信息如:商品号、商品名、商品类别、商品总量、商品上限和下限、商品价格、进货日期、生产日期、保质期等。
3.对已存入的商品信息进行更新操作,包括添加一件商品信息、删除某件商品信息和修改商品信息。
4.通过按商品名、商品种类、商品进货量的方式查询商品信息。
5.输入某商品号后对其利润进行统计、对进货价格相同的商品进行统计。
6 对商品的库存量和利润进行排序。
7.最后输出商品信息,供需要时打印。
二、需求分析1.该程序可用于对商品的基本信息的存储、更新、查询、输出、统计、排序等操作,以实现管理者对商品的管理和消费者对商品的了解。
2.其中更新功能包括:添加信息、删除信息、修改信息、可根据需要添加一个或多件商品信息,也可对个别商品信息进行适当的删除或修改。
以便随时更新商品信息。
3.程序中设计的查询功能可根据需要从若干数据中查询某件商品信息,并且可根据三种不同的方法查询:按商品名查询、按商品种类查询和按商品进货量查询。
以满足不同的需要。
四、概要设计1、方案设计对系统进行分析,给出结构图分析:系统要求实现许多的功能,因此遵循结构化程序设计思想来进行本系统的设计—自顶向下、逐步细化,将系统设计任务分解出许多子功能模块进行设计结构图如下:超市管理管理系统查询模块排序模块退出系统退出系统查询模块排序模块统计模块*更新模块*输出信息¥录入信息按商品名查询利润排行库存量排行退出系统第二类商品第一类商品退出系统2 •功能模块说明:对各个模块进行功能的描述(1).输入模块:录入需要管理的商品信息并将信息保存于文件中,以方便日后进行打印、读取、更新等操作。
超市商品管理系统C语言源代码

超市商品管理系统C语言源代码SANY GROUP system office room 【SANYUA16H-SANYHUASANYUA8Q8-#include <stdio.h>#include <math.h>#include <string.h>#include<conio.h>#include<stdio.h>#include<string.h>#define MAX 20#define PRINT1 printf("---------------------------------------------------------\n")#define PRINT2 printf("商品号--商品名称--商品种类--销售价格--生产日期(年-月-日)--保质期\n")#define PRINT3 printf("M%8s%8s崓----M\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.day,goods[i].s ave_day)int sum;struct date{int year;int month;int day;};struct goods_type /*定义结构体*/{int num;char name[10];char kind[10];int amount;int in_price;int out_price;struct date pro_time;int save_day;int profit;}goods[MAX];Save_Message(int sum); /*函数声明*/void Inquire_message(void);void Inquire_goodskind(void);void Inquire_goodsname(void);int Read_Message(void);void Renew_Messahe(void);void Revise_Message(void);void Delete_Message(void);void Insert_Message();void Show_Message(void);int Input_Message(void);void Count_Message();long Count_Profit();long Count_Amount();void Sort_amount(void);void Sort_Message(void);void Sort_Message(void){int choice;do{clrscr();printf("\n\n\n *******商品信息排行********\n\n");printf(" 1:按库存量排行\n\n");printf(" 0:返回主菜单\n\n");printf(" 请选择(0-1): ");scanf("%d",&choice);switch(choice){case 1:Sort_amount();break;case 0:break;}}while(choice!=0);}void Sort_amount(void) /*库存量排序*/{struct goods_type *p,*q[MAX];int i,j,k;clrscr();printf(" 库存排行");PRINT1;printf("\n\n排名商品号商品名称商品类别库存量\n\n"); p=goods;for(i=0;i<sum;i )q[i]=p ;for(i=0;i<sum;i ){k=i;for(j=i 1;j<sum;j )if(q[k]->amount<q[j]->amount)k=j;if(k!=i){p=q[i];q[i]=q[k];q[k]=p;}}for(i=0;i<sum;i ){printf(" %d ",i 1);printf(" %d ",q[i]->num);printf(" %s ",q[i]->name);printf(" %s ",q[i]->kind);printf(" %d \n ",q[i]->amount);}bioskey(0);}long Count_Amount() /*统计库存量*/ {int i,j=0,choice,count_num,Amount;char inquire_name[10];clrscr();printf("\n 请输入想要统计的商品号: "); scanf("%d",&count_num);for(i=0;i<sum;i )if(goods[i].num==count_num){Amount=goods[i].amount;printf("-------------------------"); printf(" 商品号库存量");printf("\n崓",goods[i].num,Amount); }elsej ;if(j==sum)printf("该商品信息不存在!!!");bioskey(0);}long Count_Profit() /*统计利润模块*/{int i,choice,j=0,count_num,profit;clrscr();printf("\n 请输入想要统计的商品号: ");scanf("%d",&count_num);for(i=0;i<sum;i )if(goods[i].num==count_num){profit=goods[i].out_price-goods[i].in_price;printf("\n 商品利润");printf("\n -------------------------------");printf("\n 商品号利润");printf("\n 崓\n",&goods[i].num,&profit);}elsej ;if(j==sum)printf("\n 该商品不存在!!!");printf("\n 按任意键返回主菜单!!");bioskey(0);}void Count_Message(void) /*统计模块*/{int choice;do{clrscr();printf("**************统计商品信息*************\n\n\n");printf("******* 1:统计库存量 ************\n\n\n"); printf("******* 2:统计利润 ************\n\n\n");printf("******* 0:返回主菜单 ************\n\n\n");printf("******* 请选择(0-2): ************\n\n\n");scanf("%d",&choice);switch(choice){case 1:Count_Amount();break;case 2:Count_Profit();break;case 0:break;}}while(choice!=0);}int Input_Message(void) /*输入模块*/{int i=0,s=MAX;char bd;clrscr();printf("开始输入商品信息.\n");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 ("%d",&goods[i].amount);printf("\n 进货价格: ");scanf ("%d",&goods[i].in_price);printf("\n 销售价格: ");scanf ("%d",&goods[i].out_price);printf("\n 生产日期(yyyy-mm-dd): ");scanf ("%d-%d-%d",&goods[i].pro_time.year,&goods[i].pro_time.month,&goods[i].pro_time. day);printf("\n 保质期: ");scanf ("%d",&goods[i].save_day);printf("继续输入信息,y or n ??");fflush(stdin);scanf("%c",&bd);if(bd=='y')i ;elsebreak;}while(i<MAX);printf("\n--%d 所有商品录入完毕!--\n\n\n",i 1);getch();printf(" 按任意键返回主菜单.");sum=i;printf("输入回车返回主菜单!!!");bioskey(0);}void Show_Message(void) /*显示输出模块*/{int i=0,j=0,count,page=7;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);}void Insert_Message(void)/*添加商品信息模块*/{int i=sum,j,flag=0;char choice;clrscr();printf("\n\n 添加一种新商品\n\n ");printf("\n-------------------------------------------------\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("%d",&goods[i].amount);printf("\n 进价: ");scanf("%d",&goods[i].in_price);printf("\n 售价: ");scanf("%d",&goods[i].out_price);printf("\n 生产日期(yyyy-mm-dd): ");scanf("%d-%d-%d",&goods[i].pro_time.year,&goods[i].pro_time.month,&goods[i].pro_time. day);printf("\n 保质期: ");scanf("%d",&goods[i].save_day);i ;printf("\n\n 想继续添加商品吗?(Y/N)");fflush(stdin);choice=getch();if(choice=='y'||choice=='Y'){printf("继续");flag=1;}elseflag=0;}while(flag==1);printf("\n\n\n 按任意键返回主菜单.........");bioskey(0);}void Delete_Message(void)/*删除商品信息模块*/ {int i,j,numberkey,flag=0;char choice;printf("开始删除......\n\n");do{clrscr();printf("请输入你要删除的商品号: \n");scanf("%d",&numberkey);for(i=0;i<sum;i ){if(goods[i].num==numberkey){for(j=i;j<sum;j )goods[j]=goods[j 1];sum--;flag=1;printf("删除成功!!\n\n\n");break;}}if(flag==0){printf("不存在该商品信息!!!"); bioskey(0);}printf("\n\n是否继续输入(y/n)?\n");getchar();scanf("%c",&choice);}while(choice=='y'||choice=='Y');printf("\n按任意键返回");bioskey(0);}void Revise_Message(void)/*修改商品信息模块*/ {int i,j,flag,choice,revise_num;char ch;do{clrscr();printf("\n\n 开始修改...");printf("\n\n 请输入你想输入的商品号:\n");scanf("%d",&revise_num);for(i=0;i<sum;i ){if(goods[i].num==revise_num){printf("确定修改此商品信息吗?(y/n)");PRINT1;PRINT2;PRINT3;getchar();ch=getchar();if(ch='y'){printf("\n\n\n修改商品信息的哪一项?");printf("\n\n 1:商品名称");printf("\n\n 2:商品类型");printf("\n\n 3:销售价格");printf("\n\n 4:生产日期");printf("\n\n 5:保质期");printf("\n\n 请选择(0-5)\n");scanf("\n %d",&choice);switch(choice){case 1:printf("请输入修改后的商品名\n");scanf("%s",&goods[i].name);break;case 2:printf("请输入修改后的商品类型\n");scanf("%s",&goods[i].kind);break;case 3:printf("请输入修改后的商品销售价格\n"); scanf("%d",&goods[i].out_price);break; case 4:printf("请输入修改后的商品生产日期\n"); scanf("%d-%d-%d",&goods[i].pro_time.year,&goods[i].pro_time.month,&goods[i].pro_time. day);break;case 5:printf("请输入修改后的商品保质期\n");scanf("%d",&goods[i].save_day);break;case 0:break;}printf("修改商品信息:\n");PRINT2;PRINT3;}elsebreak;}elsej ;if(j==sum)printf("不存在该商品信息..");}printf("\n\n 继续修改商品信息吗(y/n)?");getchar();ch=getchar();if(ch=='y'){printf("继续.\n");flag=1;}elseflag=0;}while(flag==1);printf("修改完成!!\n\n");getch();}void Renew_Message(void) /*更新商品信息模块*/{int choice;do{clrscr();printf("\n\n*********更新商品信息*********"); printf("\n\n 1:添加商品信息.\n\n");printf("\n\n 2:删除商品信息.\n\n");printf("\n\n 3:修改商品信息.\n\n");printf("\n\n 0:返回上一级.\n\n");printf("\n\n 请选择(0-3): ");scanf("%d",&choice);switch(choice)case 1:Insert_Message();break;case 2:Delete_Message();break;case 3:Revise_Message();break;case 0:break;}}while(choice!=0);}int Read_Message(void) /*读取信息模块*/{FILE *fp;int i=0;if((fp=fopen("999.txt","rb"))==NULL){printf("\n\t 现在还没有保存全部信息,按回车键回到主菜单输入商品信息!!");printf("\n\t 按任意键返回!!!!\n");getch();return;}while(feof(fp)!=1){fread(&goods[i],sizeof(struct goods_type),1,fp);if(goods[i].num==0)break;elsei ;}fclose(fp);return(i);}void Inquire_goodsname(void)/*按商品名称查询*/{int i,j,choice;char namekey[10];j=0;printf("开始查询...");printf("请输入你要查询的商品号:\n");scanf("%s",namekey);for(i=0;i<sum;i )if(strcmp(goods[i].name,namekey)==0&&goods[i].num!=0)printf(" ---商品信息----");PRINT1;PRINT2;PRINT3;}elsej ;if(j==sum)printf("该商品不存在!");printf("按任意键返回主菜单.");getch();}void Inquire_goodskind(void)/*按商品类型查询*/{int i,j,choice;char kindkey[10];j=0;printf("开始查询...");printf("请输入你要查询的商品种类:\n");scanf("%s",kindkey);for(i=0;i<sum;i )if(strcmp(goods[i].kind,kindkey)==0&&goods[i].num!=0) {printf(" ---商品信息----");PRINT1;PRINT2;PRINT3;}elsej ;if(j==sum)printf("该商品不存在!");printf("按任意键返回主菜单.");getch();}void Inquire_Message(void) /*查询模块*/{int choice;do{printf("\n *****查询商品信息 ***** \n");printf("\n *****1:按商品名称.***** \n");printf("\n *****2:按商品种类.***** \n");printf("\n *****0:返回上一级.***** \n");printf("\n 请选择(0-2): ***** \n");scanf("%d",&choice);switch(choice){case 1:Inquire_goodsname();break;case 2:Inquire_goodskind();break;case 0:break;}}while(choice!=0);}Save_Message(int sum) /*保存模块*/{FILE *fp;int i;if((fp=fopen("999.txt","wb"))==NULL){printf("\n\n不能打开文件!\n\n");exit();}for(i=0;i<=sum;i )if(fwrite(&goods[i],sizeof(struct goods_type),1,fp)!=1) printf("写文件出错!");fclose(fp);}void main(void) /*主函数*/{int choice;clrscr();sum=Read_Message();bioskey(0);do{clrscr();printf("***************************************************\n");printf(" ************ 超市商品管理系统**************\n");printf(" ************\n");printf(" ************\n");printf(" ************\n");printf(" ****** 欢迎登陆******\n");printf(" ************\n");printf(" ************\n");printf(" ************\n");printf("***************************************************\n");printf("***************************************************\n");getchar ();clrscr();printf(" ***************超市商品管理系统***********\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:退出系统 *****\n\n"); printf(" ***** 请选择(0-6): *****\n"); scanf("%d",&choice);switch(choice){case 1:Input_Message();break;case 2:Show_Message();break;case 3:Renew_Message();break;case 4:Inquire_Message();break;case 5:Count_Message();break;case 6:Sort_Message();break;case 0:break;}}while(choice!=0);Save_Message(sum);printf("\n-信息已经保存!-(file name:999.txt)\n");。
超市管理系统c实现

超市管理系统c实现#include<stdio.h>#include<malloc.h>#include<string.h>typedef struct goods{char Name[10];char num[10];char prd_date[10];char sf_date[10];float price;char unit[20];char number[3];struct goods *next;}goods;void Lulu(int i,goods *t,goods *q);void shuchu(goods *t);void xiugai(char *ch,goods *t);void chaxun(char *ch,goods *t);void add(goods *t);void shanchu(goods *t);void main(){goods head,*p,*q;int i,t,m;char num[10];head.next=NULL;i=0;printf("1录入商品的信息\n");printf("请输入要录入商品的个数:\n");scanf("%d",&t);while(i<t){q=&head;p=(goods*)malloc(sizeof(goods));p->next=NULL;Lulu(i,p,q);while(q->next)q=q->next;q->next=p;i++;}printf("请选择您所需要的功能:\n");printf("2查看所有商品\n");printf("3修改商品信息\n");printf("4查询信商品信息\n");printf("5增加新商品信息\n");printf("6删除商品信息\n");printf("0退出程序\n");scanf("%d",&m);while(m!=0){q=&head;if(m==2){while(q->next){q=q->next;shuchu(q);}printf("请选择您所需要的功能:\n"); printf("2查看所有商品\n");printf("3修改商品信息\n");printf("4查询信商品信息\n");printf("5增加新商品信息\n");printf("6删除商品信息\n");printf("0退出程序\n");}if(m==3){printf("请输入要修改商品的编号:\n");scanf("%s",&num);xiugai(num,q);}if(m==4){printf("请输入要查询商品的编号:\n");scanf("%s",num);chaxun(num,q);}if(m==5){add(q);}if(m==6){shanchu(q);}scanf("%d",&m);}}void Lulu(int i,goods *t,goods *q){int flag;goods* l;printf("请输入第%d个商品的编号:\n",i+1);while(1){l=q;flag=0;scanf("%s",t->num);while(l){if(!strcmp(l->num,t->num)){printf("输入的编号已存在,请重新输入\n");flag=1;break;}l=l->next;}if(!flag) break;}printf("请输入第%d个商品的名称:\n",i+1);scanf("%s",t->Name);printf("请输入第%d个商品的生产日期:\n",i+1);scanf("%s",t->prd_date);printf("请输入第%d个商品的保质期:\n",i+1);scanf("%s",t->sf_date);printf("请输入第%d个商品的价格:\n",i+1);scanf("%f",&t->price);printf("请输入第%d个商品的单位:\n",i+1);scanf("%s",t->unit);printf("请输入第%d个商品的所属柜组:\n",i+1);scanf("%s",t->number);}void shuchu(goods *t){printf("商品的编号:%s\n",t->num);printf("商品的名称:%s\n",t->Name);printf("商品的生产日期:%s\n",t->prd_date);printf("商品的保质期:%s\n",t->sf_date);printf("商品的价格:%.2f元\n",t->price);printf("商品的单位:%s\n",t->unit);printf("商品所属柜组:%s\n",t->number);printf("\n\n");}void xiugai(char *ch,goods *t){int i,m,flag=1;t=t->next;while(t){if(strcmp(t->num,ch)==0){flag=0;break;}elset=t->next;}if(flag==1){printf("编号不存在,请选择0退出修改重新选择修改商品信息,重新输入编号");}while(1){printf("请选择要修改的商品的信息\n");printf("1修改商品的编号\n");printf("2修改商品的名称\n");printf("3.修改商品的价格\n");printf("4.修改商品的单位\n");printf("5.修改商品所属柜组\n");printf("输入0结束修改\n");scanf("%d",&m);i=m;if(i==1){printf("请输入商品的新编号:\n");scanf("%s",t->num);}if(i==2){printf("请输入商品的新名称:\n");scanf("%s",t->Name);}if(i==3){printf("请输入商品的新价格:\n");scanf("%f",&t->price);}if(i==4){printf("请输入商品的新单位:\n");scanf("%s",t->unit);}if(i==5){printf("请输入商品所属的新柜组:\n");scanf("%s",t->number);}if(i==0)break;}printf("请选择您所需要的功能:\n");printf("2查看所有商品\n");printf("3修改商品信息\n");printf("4查询信商品信息\n");printf("5增加新商品信息\n");printf("6删除商品信息\n");printf("0退出程序\n");}void chaxun(char *ch,goods *t){int flag=1;t=t->next;while(t){if(strcmp(t->num,ch)==0){flag=0;break;}t=t->next;}if(flag==1){printf("编号不存在,重新输入编号");}elseshuchu(t);printf("请选择您所需要的功能:\n");printf("2查看所有商品\n");printf("3修改商品信息\n");printf("4查询信商品信息\n");printf("5增加新商品信息\n");printf("6删除商品信息\n");printf("0退出程序\n");}void add(goods *t){goods *q,*p;int flag,word=1;q=(goods*)malloc(sizeof(goods));while(word){p=t;flag=0;printf("请输入要增加的商品的编号:\n");scanf("%s",q->num);while(p->next){if(strcmp(p->next->num,q->num)==0){flag=1;break;}p=p->next;}if(flag==1){printf("商品编号有重复,请重新输入商品的编号\n");continue;}elseword=0;printf("请输入商品的名称:\n");scanf("%s",q->Name);printf("请输入商品的生产日期:\n");scanf("%s",q->prd_date);printf("请输入商品的保质期:\n");scanf("%s",q->sf_date);printf("请输入商品的价格:\n");scanf("%f",&q->price);printf("请输入商品的单位:\n");scanf("%s",q->unit);printf("请输入商品所属柜组:\n");scanf("%s",q->number);}p=t;while(p->next){if(strcmp(p->next->num,t->num)>0)break;elsep=p->next;}q->next=p->next;p->next=q;printf("请选择您所需要的功能:\n");printf("2查看所有商品\n");printf("3修改商品信息\n");printf("4查询信商品信息\n");printf("5增加新商品信息\n");printf("6删除商品信息\n");printf("0退出程序\n");}void shanchu(goods *p){goods *q,*t;char num[10];q=p;printf("请输入要删除的商品编号:\n");scanf("%s",num);while(q->next)if(strcmp(q->next->num,num)==0)break;else q=q->next;if(q->next){t=q->next;q->next=q->next->next;free(t);}elseprintf("没有该编号的商品");printf("请选择您所需要的功能:\n");printf("2查看所有商品\n");printf("3修改商品信息\n");printf("4查询信商品信息\n");printf("5增加新商品信息\n");printf("6删除商品信息\n");printf("0退出程序\n");}。
C语言超市收银管理系统实现

C语言超市收银管理系统实现引言:随着社会经济的发展,超市作为一种新型的购物场所,逐渐取代了传统市场的地位,成为人们购物的首选。
超市管理面临诸多的挑战,因此,使用计算机技术来实现超市收银管理系统具有重要意义。
本文将介绍如何使用C语言实现超市收银管理系统。
1.系统需求分析:超市收银管理系统的主要功能包括商品信息管理、销售管理、库存管理和报表管理等。
这些功能对于超市管理人员来说是非常重要的,因此,我们需要分析每个功能所需的具体要求。
(1)商品信息管理:记录商品的信息,包括商品编号、商品名称、商品数量、商品价格等。
这些信息可以使用文件来存储和读取。
(2)销售管理:记录每次销售的详细信息,包括销售时间、销售员、商品名称、销售数量和销售金额等。
此外,还需要实时更新商品的库存信息。
(3)库存管理:根据销售信息实时更新商品的库存数量,当库存数量低于设定的预警值时,系统应发出警报。
(4)报表管理:生成各种销售报表,包括每日销售额、每月销售额、每类商品的销售情况等。
这些报表可以帮助管理人员了解超市的销售情况并进行分析。
2.系统设计:(1)数据结构设计:根据系统需求,我们需要设计一些数据结构来存储不同的数据,比如商品信息、销售信息和库存信息等。
可以使用结构体来表示每个数据项,同时可以使用链表或数组来保存多个数据项。
(2)功能模块设计:根据系统需求,我们可以把系统功能分为不同的模块,比如商品信息管理模块、销售管理模块、库存管理模块和报表管理模块等。
每个模块可以对应一个函数来实现相应的功能。
(3)界面设计:为了方便用户使用,我们可以设计一个简单的控制台界面,用户通过输入相应的命令来调用功能模块。
比如用户输入"add"可以调用商品信息管理模块来添加商品信息。
3.系统实现:(1)商品信息管理模块:实现商品信息的添加、删除、修改和查询功能。
可以使用文件来存储商品信息。
(2)销售管理模块:实现销售信息的记录和销售金额的计算功能。
C语言课程设计-超市管理系统

3.设计结果与分析
在VC 6.0环境中输入源程序,在没有提示错误的情况下编译,生成.exe可执行文件。
①运行程序,会看到如图6所示界面。
运行主函数时,首先调用函数main
图6 程序主界面
这个界面是运行函数后首先出现的界面,运行函数时,该函数是一个菜单函数,用switch 语句来实现各功能模块的转移,出来该页面后用户可根据提示输入信息,从而实现各种目的。
②键盘输入1,进入商品详细目录用以显示全部商品详细信息
图7 显示信息界面
该页面用printf输出,在利用指针读出链表中数据并利用合理计算计算出净利润等数据,再用while语句进行循环输出部数据
图8 买卖信息界面
用scanf输入数据,用if语句和while语句来实现循环每一次修改的数据④输入3按回车会进入商品登陆页面,此页面用来登陆商品。
如图9所示
图9 登录信息界面
将数据登陆入链表个变量中
图10修改信息界面
6输入5按回车进入商品删除模块如图11所示
使用printf()函数和scanf( )函数,并且利用指针从而实现各种功能。
其中用到了while 循环语句,实现对链表中个数据的重写功能。
运行完后退出该函数
图11删除信息界面。
c语言超市管理系统报告书

1 需求分析:随着现代生活质量的提高,超市这种便利的效劳开始走进我们的生活,同时随着超市涌入我们的生活,如何更便利的对超市进行系统和有序的操作,成为了我们需要考虑的问题,本程序运用C语言程序设计了一个超市管理系统。
关系系统的的功能主要有新购物品入库、物品信息删除、物品信息修改、物品信息查询、物品信息浏览功能,在相应的硬盘上面进行存盘以防止局部数据的丧失。
为了更加人性化使用此管理系统,还在MENU选项总添加了系统颜色设置功能,使用户可以根据自己的喜好修改操作界面。
2 概要设计(1)数据结构依据给定的物品信息和数据形式,数组必须用结构体实现。
结构类型的层次结构:struct ima{int id;char name[20];char produce[30];int number;float price;};(2)模块划分依据程序的结构反和功能,遵照“自顶而下〞的原那么,描述该程序的层次结构图一显示了该程序的层次结构,共5层:如下列图:图一图一的层次结构1、void chushihua()2、增加物品Tianjia();3、删除物品信息Shanchu();4、Xiugai();Chazhao();6、Liulan();7、yanseshezhi();8、应用程序退出Jieshu();3 运行环境:Win2003, WinXP, Win2000, NT, WinME, Win9X4 开发工具和编程语言:编程语言:C语言开发工具:microsoft visual C++ 6.05 详细设计:1、结构体变量的定义:struct ima{int id;char name[20];char produce[30];int number;float price;};3、void chushihua(){FILE *fp;struct ima i={1,"花生牛奶","湖北武汉",1200,2.5};fp=fopen("ima.dat","w");if(fp==NULL){printf("\t\t\t系统错误,请重试........");exit(0);}fwrite(&i,sizeof(struct ima),1,fp);fclose(fp);}4、void main(){printf("\n\n");system("color 1a");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 \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 按任意键继续\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 \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 \3");getch();system("cls");menu();chushihua();menu();}5、选择菜单void menu(){int choice;printf("\n∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞【超市库存管理系统】∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞\n");printf("--------------------------------系统菜单显示如下--------------------------------");printf("\n\t①=====================【新购物品入库】\n");printf("\n\t②=====================【物品信息删除】\n");printf("\n\t③=====================【物品信息修改】\n");printf("\n\t④=====================【物品信息查询】\n");printf("\n\t⑤=====================【物品信息浏览】\n");printf("\n\t⑥=====================【系统颜色设置】\n");printf("\n\t⑦=====================【应用程序退出】\n");printf("\n\t请输入您要选择的菜单......");scanf("%d",&choice);switch(choice){case 1:Tianjia();break;case 2:Shanchu();break;case 3:Xiugai();break;case 4:Chazhao();break;case 5:Liulan();break;case 6:yanseshezhi();break;case 7:Jieshu();break;default:printf("\n\t\t\t\t\t输入无效,请您重新输入......");getch();system("cls");menu();}}6、int panduanID(int id){FILE *fp;struct ima i;fp=fopen("ima.date","r");if(fp==NULL){printf("\t\t\t系统错误,请您重试........");exit(0);}fread(&i,sizeof(struct ima),1,fp);while(!feof(fp)){if(i.id==id){fclose(fp);return 1;break;}fread(&i,sizeof(struct ima),1,fp);}fclose(fp);return 0;}{ struct ima i;char choice;FILE *fp;fp=fopen("ima.date","ab");if(fp==NULL){printf("\t\t\t系统错误,请您重试........");exit(0);}labID:printf("\n\t请您输入要入库物品的信息...\n");scanf("%d",&i.id);if(panduanID(i.id)==1){goto labID;}printf("\t\t\t\t 物品的名称:");scanf("%s",);printf("\t\t\t\t 物品的生产地:");scanf("%s",i.produce);printf("\t\t\t\t 物品的数量:");scanf("%d",&i.number);printf("\t\t\t\t 物品的单价:");scanf("%f",&i.price);fwrite(&i,sizeof(struct ima),1,fp);printf("\t\t\t\t\t\t 物品信息已入库成功!!!\n");printf("\n您想继续吗?(y/n)");scanf(" %c",&choice);if(choice=='Y'||choice=='y'){Tianjia();}else{system("cls");menu();}}7、void Shanchu(){ struct ima i[1000];struct ima temp;int delID;char choice;int index=0;int j=0;FILE *fp;fp=fopen("ima.date","r");if(fp==NULL){printf("\t\t\t系统错误,请您重试........");exit(0);fread(&temp,sizeof(struct ima),1,fp);while(!feof(fp)){i[index]=temp;index++;fread(&temp,sizeof(struct ima),1,fp);}fclose(fp);scanf("%d",&delID);fopen("f:\\ima.date","w");if(fp==NULL){printf("\t\t\t系统错误,请您重试........");exit(0);}for( j=0;j<index;j++){if(i[j].id!=delID){fwrite(&i[j],sizeof(struct ima),1,fp);}}fclose(fp);printf("\t\t\t\t\t物品信息已去除!!!\n");printf("\n您想继续吗?(y/n)");scanf(" %c",&choice);if(choice=='Y'||choice=='y'){Shanchu();}else{system("cls");menu();}}8、void Xiugai(){ int index=0;int ID,j;char choice;struct ima i[1000];struct ima temp;FILE *fp;fp=fopen("ima.dat","r");if(fp==NULL){printf("\t\t\t系统错误,请您重试........");exit(0);}fread(&temp,sizeof(struct ima),1,fp);while(!feof(fp)){i[index]=temp;index++;fread(&temp,sizeof(struct ima),1,fp);}fclose(fp);fp=fopen("ima.dat","w");if(fp==NULL){printf("\\t\t\t系统错误,请您重试........");exit(0);}scanf("%d",&ID);for(j=0;j<=index-1;j++){if(i[j].id!=ID){fwrite(&i[j],sizeof(struct ima),1,fp);}else{printf("\t\t物品名称修改为:");scanf("%s",i[j].name);printf("\t\t物品生产地修改为:");scanf("%s",i[j].produce);printf("\t\t物品数量修改为:");scanf("%d",&i[j].number);printf("\t\t物品单价修改为:");scanf("%f",&i[j].price);}}fclose(fp);printf("\t\t\t\t物品信息已修改......");printf("\n您想继续吗?(y/n)");scanf(" %c",&choice);if(choice=='Y'||choice=='y'){Xiugai();}else{system("cls");menu();}}9、void Chazhao(){FILE *fp;int findID;char choice;struct ima i;fp=fopen("ima.date","r");if(fp==NULL){printf("\t\t\t系统错误,请你重试........");exit(0);}finID:scanf("%d",&findID);fread(&i,sizeof(struct ima),1,fp);while(!feof(fp)){if(i.id==findID){printf("\n\n\t***************物品信息******************");printf("\n\t-----------------------------------------");printf("\n\t物品名称...%30s\n",);printf("\n\t-----------------------------------------");printf("\n\t生产厂家...%30s\n",i.produce);printf("\n\t-----------------------------------------");printf("\n\t进口数量...%30d\n",i.number);printf("\n\t-----------------------------------------");printf("\n\t批发价格...%30.3f\n",i.price);printf("\n\t-----------------------------------------");printf("\n您想继续吗?(y/n)");scanf(" %c",&choice);if(choice=='Y'||choice=='y'){Chazhao();}else{system("cls");menu();}}fread(&i,sizeof(struct ima),1,fp);}fclose(fp);goto finID;}10、void Liulan(){ struct ima i;int index=0;char choice;FILE *fp;fp=fopen("ima.date","r");if(fp==NULL){printf("\t\t\t系统错误,请你重试........");exit(0);}fread(&i,sizeof(struct ima),1,fp);while(!feof(fp)){index++;printf("\n\n\t****************物品信息%d*****************",index);printf("\n\t-----------------------------------------");printf("\n\t物品名称...%30s\n",);printf("\n\t-----------------------------------------");printf("\n\t生产厂家...%30s\n",i.produce);printf("\n\t-----------------------------------------");printf("\n\t进口数量...%30d\n",i.number);printf("\n\t-----------------------------------------");printf("\n\t批发价格...%30.3f\n",i.price);printf("\n\t-----------------------------------------");getch();fread(&i,sizeof(struct ima),1,fp);}fclose(fp);printf("\n您想继续吗?(y/n)");scanf(" %c",&choice);if(choice=='Y'||choice=='y'){Liulan();}else{system("cls");menu();}}11、void yanseshezhi(){ int a;char choice;system("cls");printf("\n\n\t\t选择以下方案\n");printf("\n\n\t\t1**************红底黑字\n");printf("\n\n\t\t2**************白底黑字\n");printf("\n\n\t\t3**************黑底红字\n");printf("\n\n\t\t4**************绿底蓝字\n");printf("\n\n\t\t5**************黄底紫字\n");printf("\n\n\t\t6**************系统默认\n");printf("\n\n\t\t\t\t\t请挑选您喜爱的颜色<1-5>......");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 1a");break;default:printf("\n\n\t\t\t\t\t输入无效,重新输入......");getch();yanseshezhi();}printf("\n选择的颜色您还满意吗?(y返回主菜单/n继续选择)");scanf(" %c",&choice);if(choice=='Y'||choice=='y'){system("cls");menu();}else{yanseshezhi();}}12、void Jieshu(){char choice;system("cls");printf("\n\n\n\n\n\n\n\t\t\t您确定要退出系统吗?\n\n\n\t\t\t如果您想退出请按'y',其它键将返回主菜单.....");scanf(" %c",&choice);if(choice=='Y'||choice=='y'){system("cls");printf("\n\n\n\n\n\n\n\n\n\n\t\t\t\t谢谢您的使用!!!");printf("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n");}else{system("cls");menu();}}6 调试分析:“;〞before tybe7测试结果:1、欢送界面2、系统选择界面:3、新购物品入库:4、物品信息删除:5、物品信息修改:6、物品信息查询7、物品信息浏览:8、系统颜色设置:9、应用程序退出:8 参考文献:课程设计总结C语言已学习了两个学期了。
c语言课程设计超市管理系统

c语言课程设计超市管理系统一、教学目标本节课的教学目标是使学生掌握C语言编程基础,能够运用C语言实现简单的超市管理系统。
具体目标如下:1.知识目标:–掌握C语言的基本语法和数据类型。
–了解函数的定义和调用。
–掌握数组的声明和使用。
–理解指针的概念和应用。
2.技能目标:–能够使用C语言编写简单的程序。
–能够运用函数实现模块化编程。
–能够使用数组存储和管理数据。
–能够运用指针处理内存地址和数据。
3.情感态度价值观目标:–培养学生的编程兴趣和自信心。
–培养学生解决问题的能力和创新精神。
–培养学生团队合作和交流分享的意识。
二、教学内容本节课的教学内容主要包括C语言的基本语法、数据类型、函数、数组和指针。
具体安排如下:1.C语言的基本语法和数据类型:介绍C语言的构成要素,包括变量、常量、运算符、表达式等。
2.函数的定义和调用:讲解函数的声明、定义和调用方式,并通过实例演示函数的使用。
3.数组的声明和使用:介绍数组的声明、初始化和使用方法,并通过实例展示数组在超市管理系统中的应用。
4.指针的概念和应用:讲解指针的定义、声明和使用,并通过实例说明指针在超市管理系统中的应用。
三、教学方法本节课采用多种教学方法,以激发学生的学习兴趣和主动性:1.讲授法:通过讲解C语言的基本语法、数据类型、函数、数组和指针的概念和用法。
2.案例分析法:通过分析超市管理系统的实际案例,引导学生运用C语言编程解决实际问题。
3.实验法:安排课堂实验,让学生动手实践,加深对C语言编程的理解和应用。
4.讨论法:学生分组讨论,促进学生之间的交流与合作,培养团队合作精神。
四、教学资源本节课所需的教学资源包括:1.教材:选用权威、实用的C语言教材,为学生提供系统、全面的学习资料。
2.参考书:提供相关领域的参考书籍,拓展学生的知识面。
3.多媒体资料:制作课件、教学视频等多媒体资料,增强课堂教学的趣味性和生动性。
4.实验设备:准备计算机、编程环境等实验设备,确保学生能够动手实践。
C语言程序设计超市管理系统

程序设计——超市管理系统学院:专业:班级:姓名:学号:指导老师:超市管理系统课程设计1)需求分析:设计题目:超市管理系统设计要求:有一个小型超市,出售N(N>=10)种商品,设计并实现一个系统系统功能需求分析:1.保存及输出:超市中的各种商品信息保存在指定文件中,可以把它们输出显示。
2.计算并排序:计算每类商品的总价值(sum,单精度)及平均价(aver,单精度,输出一位小数),将每类商品按平均价从大到小的顺序排序打印出来。
3.统计:统计输出库存量低于100的货号及类别。
统计输出有两种以上(含两种)商品库存量低于100的商品类别。
2)概要设计:系统总体设计框架:系统功能模块图:3)详细设计:主要功能模块的算法设计思路:本程序主要分为八个模块:主模块、信息输出修改模块、新建信息模块、排序模块、计算模块、统计模块1、统计模块2、打印模块。
1)主模块:通过调用各分模块实现功能;2)信息输出修改模块:输出显示文件中商品信息内容,添加商品信息,删除商品信息,修改商品信息;3)新建商品信息模块:建立一个新结构体,为链表存信息用,并且将信息保存在指定的文件中;4)排序模块:把文件中顺序零乱的商品信息按单价的大小从高到低进行排序,放到链表里存储;5)计算模块:将所有商品的价格与库存量进行累加求和;6)打印模块:将商品信息按每类平均价格排序(从高到低)按顺序打印出来;7)统计模块1:统计库存量低于100的货名及类别;8)统计模块2:统计商品库存量有2种以上(含2种)低于100的商品类别工作流程图:4)主要源程序代码:#include "stdio.h" /*输入,输出头文件*/ #include "stdlib.h" /*申请空间头文件*/#include "string.h" /*对字符串加工头文件*/ #include "conio.h" /*清屏头文件*/FILE *fp;int n=0; /*定义文件指针类型*/int i,j,a[4],m; /*定义整数类型*/float aver[4],sum[4],g[4],h; /*定义浮点类型*/char c[5]="elec"; /*定义字符数组类型*/ char d[5]="comm"; /*定义字符数组类型*/char e[5]="food"; /*定义字符数组类型*/char f[5]="offi"; /*定义字符数组类型*/struct good /*定义结构体*/{int num; /*商品编号*/char name[20]; /*商品名称*/char kind[40]; /*商品类型*/float price; /*商品价格*/char unit[10]; /*商品单位*/int quantity; /*商品数量*/struct good *next; /*定义结构体指针类型*/}*head,*p1,*p2;struct good *createlist() /*创建链表函数*/{struct good *head1,*p1,*p2; /*定义结构体指针类型*/if((fp=fopen("goods message.txt","w"))==NULL) /*判断能否打开文件*/ {printf("can not open the file");exit(0); /*结束程序*/}head1=(struct good *)malloc(sizeof(struct good)); /*申请头结点空间*/p1=head1;p2=head1;printf("*********************************************\n");printf("请输入信息:编号,名称,类型,价格,单位,数目\n");printf(" (以输入“-1”表示结束输入)\n");printf("*********************************************\n");printf("____________________\n");scanf("%d %s %s %f %s %d",&p1->num,p1->name,p1->kind,&p1->price,p1->unit,&p 1->quantity); /*输入商品信息*/printf("____________________\n");p1->next=NULL;fprintf(fp,"%d %s %s %f %s %d",p1->num,p1->name,p1->kind,p1->price,p1->unit,p1->quantity); /*将商品信息写入文件*/while(1){p1=(struct good *)malloc(sizeof(struct good)); /*申请新空间*/printf("*********************************************\n");printf("请输入信息:编号,名称,类型,价格,单位,数目\n");printf(" (以输入“-1”表示结束输入)\n");printf("*********************************************\n");printf("____________________\n");scanf("%d",&p1->num);if(p1->num==-1) /*申请空间结束条件*/{printf("____________________\n\n");fprintf(fp,"%d",-1);fclose(fp);return head1; /*返回头指针*/}scanf("%s %s %f %s %d",p1->name,p1->kind,&p1->price,p1->unit,&p1->quantity); /*输入商品信息*/printf("________________\n");fprintf(fp,"%d %s %s %f %s %d",p1->num,p1->name,p1->kind,p1->price,p1->unit,p1->quantity); /*将商品信息写入文件*/p1->next=NULL;p2->next=p1;p2=p1;}}struct good *paixu(struct good*head2) /*链表排序函数*/struct good *p6,*p7,*r,*s; /*定义结构体指针类型*/for(i=0;i<=3;i++) /*赋初值值*/{a[i]=0;sum[i]=0;aver[i]=0;}p6=(struct good *)malloc(sizeof(struct good)); /*申请新空间*/ p6->next=head2;head2=p6;while(p6->next!=NULL) /*判断循环结束条件*/{p7=p6->next;r=p6;while(p7->next!=NULL) /*判断循环结束条件*/{if((p7->next->price)>(r->next->price)) /*判断是否调换*/r=p7;p7=p7->next;}if(p6!=r) /*判断循环结束条件*/s=r->next; /*指针调换*/r->next=s->next;s->next=p6->next;p6->next=s;}p6=p6->next;}p6=head2;head2=head2->next;free(p6); /*释放第一个无效空间*/return head2;}void jisuan(){p1=head;do{if(strcmp(p1->kind,c)==0) /*判断是否为电器类型*/{sum[0]=sum[0]+(p1->price)*(p1->quantity); /*求电器总价*/ a[0]=a[0]+p1->quantity; /*求电器总件数*/}if(strcmp(p1->kind,d)==0) /*判断是否为日用品类型*/{sum[1]=sum[1]+(p1->price)*(p1->quantity); /*求日用品总价*/ a[1]=a[1]+p1->quantity; /*求日用品总件数*/}if(strcmp(p1->kind,e)==0) /*判断是否为办公用品类型*/{sum[2]=sum[2]+(p1->price)*(p1->quantity); /*求办公用品总价*/ a[2]=a[2]+p1->quantity; /*求办公用品总件数*/}if(strcmp(p1->kind,f)==0) /*判断是否为食品类型*/{sum[3]=sum[3]+(p1->price)*(p1->quantity); /*求食品总价*/a[3]=a[3]+p1->quantity; /*求食品总件数*/}p1=p1->next;}while (p1!=NULL); /*遍历链表结束条件*/for(i=0;i<4;i++)aver[i]=sum[i]/a[i]; /*求每类商品平均价*/printf("****************************************************\n"); printf("商品类型\t 平均价\t 总库存量\n");printf("****************************************************\n");printf("____________________________________________________\n"); printf("电器总价值:%0.1f\t平均价:%0.1f\t总库存量:%d\n",sum[0],aver[0],a[0]); printf("____________________________________________________\n"); printf("日用品总价值:%0.1f\t平均价:%0.1f\t总库存量:%d\n",sum[1],aver[1],a[1]); printf("____________________________________________________\n"); printf("食品总价值:%0.1f\t平均价:%0.1f\t总库存量:%d\n",sum[2],aver[2],a[2]); printf("____________________________________________________\n"); printf("办公用品总价值:%0.1f\t平均价:%0.1f\t总库存量:%d\n",sum[3],aver[3],a[3]);printf("____________________________________________________\n");}void shuchu() /*输出商品信息函数*/{do{struct good *p3,*p4,*p5; /*定义结构体指针类型*/int n=0,p=0,q=0,r=0;printf("所有商品信息:\n");printf("编号,名称,类型,价格,单位,数目\n");printf("**********************************\n");if((fp=fopen("goods message.txt","rb+"))==NULL) /*判断能否打开文件*/{printf("can not open the file");exit(0); /*结束程序*/}head=(struct good *)malloc(sizeof(struct good)); /*申请头结点空间*/p3=head;fscanf(fp,"%d %s %s %f %s %d",&p3->num,p3->name,p3->kind,&p3->price,p3->unit,&p3->quantity);/*从文件中写到链表*/while(1){p4=(struct good *)malloc(sizeof(struct good)); /*申请头结点空间*/fscanf(fp,"%d ",&p4->num);if(p4->num!=-1) /*判断循环结束条件*/{fscanf(fp,"%s %s %f %s %d",p4->name,p4->kind,&p4->price,p4->unit,&p4->quantity); /*从文件中写到链表*/ p4->next=NULL;p3->next=p4;p3=p4;}else{p3->next=NULL;break;}}fclose(fp); /*关闭文件*/p3=head;while(p3!=NULL){printf(" %d %s %s %0.1f %s %d\n\n",p3->num,p3->name,p3->kin d,p3->price,p3->unit,p3->quantity);printf("__________________________________\n");p3=p3->next;}printf("**********************************\n");printf("//////////////////////////////////\n");while(n!=4){p3=head;printf("**********************************\n");printf("1 添加商品信息\n");printf("2 删除某商品信息\n");printf("3 修改某商品信息\n");printf("4 返回(当你完成了对某一商品的添加、删除或者修改后请按4返回)\n");printf("**********************************\n");scanf("%d",&n);if(n==1) /*添加商品信息*/{printf("请输入商品编号名称类型价格单位数目\n");printf("**********************************\n");p4=(struct good *)malloc(sizeof(struct good)); /*申请空间*/scanf("%d %s %s %f %s %d",&p4->num,p4->name,p4->kind,&p4->price,p4->unit,&p 4->quantity); /*输入商品信息*/p4->next=NULL;while(p3->next!=NULL) /*判断循环结束条件*/{p3=p3->next;}p3->next=p4;p3=head;if((fp=fopen("goods message.txt","w"))==NULL) /*判断能否打开文件*/{printf("can not open the file");exit(0); /*结束程序*/}while(p3!=NULL){fprintf(fp,"%d %s %s %f %s %d",p3->num,p3->name,p3->kind,p3->price,p3->unit,p3->quantity) ;/*将商品信息写入文件*/p3=p3->next;}fprintf(fp,"%d",-1);fclose(fp); /*关闭文件*/printf("**********************************\n");printf("__________________________________\n");printf("------------请按4返回-------------\n");printf("__________________________________\n");printf("**********************************\n");}if(n==2) /*删除商品*/{printf("**********************************\n");printf("请输入需要删除的商品编号\n");printf("**********************************\n");scanf("%d",&p);printf("**********\n");printf("1 确认删除\n2 取消删除\n");printf("**********\n");scanf("%d",&r);if(r==1){if((head->num)==p){head=head->next;free(p3); /*释放空间*/}else{p4=head;p3=p4->next;while(p3!=NULL) /*判断循环结束条件*/ {if((p3->num)==p){p5=p3->next;free(p3); /*释放空间*/p4->next=p5;break;}p3=p3->next;p4=p4->next;}}if((fp=fopen("goods message.txt","w"))==NULL) /*判断能否打开文件*/{printf("can not open the file");exit(0); /*结束程序*/}p3=head;while(p3!=NULL) /*判断循环结束条件*/{fprintf(fp,"%d %s %s %f %s %d",p3->num,p3->name,p3->kind,p3->price,p3->unit,p3->quantity); /*将商品信息写入文件*/p3=p3->next;}fprintf(fp,"%d",-1);fclose(fp); /*关闭文件*/}if(r==2)continue; /*继续循环*/printf("**********************************\n");printf("__________________________________\n");printf("------------请按4返回-------------\n");printf("__________________________________\n");printf("**********************************\n");}if(n==3) /*修改某商品信息*/{printf("请输入需要修改的商品编号\n");scanf("%d",&q);while(p3!=NULL) /*判断循环结束条件*/{if((p3->num)==q) /*判断是否为所需要修改的商品*/{printf("请输入商品单价与库存量(如果单价不变请输入原来的单价)\n");scanf("%f %d",&p3->price,&p3->quantity); /*输入商品价格与库存量*/}p3=p3->next;}if((fp=fopen("goods message.txt","w"))==NULL) /*判断能否打开文件*/{printf("can not open the file");exit(0); /*结束程序*/}p3=head;while(p3!=NULL) /*判断循环结束条件*/{fprintf(fp,"%d %s %s %f %s %d",p3->num,p3->name,p3->kind,p3->price,p3->unit,p3->quantity); /*将商品信息写入文件*/p3=p3->next;}fprintf(fp,"%d",-1);fclose(fp); /*关闭文件*/printf("**********************************\n");printf("__________________________________\n");printf("------------请按4返回-------------\n");printf("__________________________________\n");printf("**********************************\n");}if(n==4) /*退出*/break;}printf("**********\n");printf("1 继续修改\n---------\n2 返回\n");printf("**********\n");scanf("%d",&p);if(p==1)continue; /*继续循环*/if(p==2)break; /*跳出循环*/}while(n!=2);fclose(fp); /*关闭文件*/}void printf0(struct good *p) /*遍历链表并打印电器类商品函数*/{struct good *p3; /*定义结构体指针类型*/p3=p;while (p3!=NULL) /*判断遍历链表循环结束条件*/{if(strcmp(p3->kind,c)==0) /*判断商品类型是否为电器类型*/{printf("%d\t%s\t%s\t%0.1f\t%s\t%d\n",p3->num,p3->name,p3->kind,p3->price,p3->unit,p3->quantity); /*输出电器类商品信息*/ printf("________________________________________________\n");}p3=p3->next;}return;}void printf1(struct good *p) /*遍历链表并打印日用品类商品函数*/{struct good *p3; /*定义结构体指针类型*/p3=p;while (p3!=NULL) /*判断遍历链表循环结束条件*/{if(strcmp(p3->kind,d)==0) /*判断商品类型是否为日用品类型*/{printf("%d\t%s\t%s\t%0.1f\t%s\t%d\n",p3->num,p3->name,p3->kind,p3->price,p3->unit,p3->quantity); /*输出日用品类商品信息*/ printf("________________________________________________\n");}p3=p3->next;}return;}void printf2(struct good *p) /*遍历链表并打印办公用品类商品函数*/{struct good *p3; /*定义结构体指针类型*/p3=p;while (p3!=NULL) /*判断遍历链表循环结束条件*/{if(strcmp(p3->kind,e)==0) /*判断商品类型是否为办公用品类型*/{printf("%d\t%s\t%s\t%0.1f\t%s\t%d\n",p3->num,p3->name,p3->kind,p3->price,p3->unit,p3->quantity); /*输出办公用品类商品信息*/ printf("________________________________________________\n");}p3=p3->next;}return;}void printf3(struct good *p) /*遍历链表并打印食品类商品函数*/{struct good *p3; /*定义结构体指针类型*/p3=p;while (p3!=NULL) /*判断遍历链表循环结束条件*/{if(strcmp(p3->kind,f)==0) /*判断商品类型是否为食品类型*/{printf("%d\t%s\t%s\t%0.1f\t%s\t%d\n",p3->num,p3->name,p3->kind,p3->price,p3->unit,p3->quantity); /*输出食品类商品信息*/ printf("________________________________________________\n");}p3=p3->next;}return;}void shunxudayin(){for(i=0;i<4;i++)g[i]=aver[i]; /*将平均价赋给新数组*/for(j=0;j<3;j++) /*将新数组用冒泡排序法排序*/for(i=j+1;i<4;i++){if(g[j]<g[i]){h=g[j];g[j]=g[i];g[i]=h;}}printf("\n****************************\n");printf("商品平均价格排序表(从高到低)\n");printf("****************************\n");printf("________________________________________________\n");printf("编号\t名称\t类别\t单价\t单位\t数量\n");printf("________________________________________________\n"); for(j=0;j<4;j++)for(i=0;i<4;i++){if (aver[i]==g[j]) /*判断每类商品平均价格的先后顺序*/switch(i){case 0:printf0(head); /*调用遍历链表并打印电器类商品函数*/break;case 1:printf1(head); /*调用遍历链表并打印日用品类商品函数*/break;case 2:printf2(head);/*调用遍历链表并打印办公用品类商品函数*/break;case 3:printf3(head); /*调用遍历链表并打印食品类商品函数*/break;}}void tongji1(){p1=head;printf("\n************************\n");printf("库存量低于100的货名及类别\n");printf("************************\n");printf("________________________\n");printf("商品名称\t商品类型\n");printf("________________________\n");while(p1!=NULL) /*判断遍历链表循环结束条件*/{if(p1->quantity<100) /*判断库存量是否小于100*/{printf("%s\t%s\n",p1->name,p1->kind); /*输出商品名称及类别*/ printf("________________________\n");}p1=p1->next;}}void tongji2()printf("\n**********************************************\n");printf("商品库存量有2种以上(含2种)低于100的商品类别:\n");printf("**********************************************\n");printf("________\n");if((a[0]<100)&&(a[0]>=2)) /*判断电器类库存量是否为2种以上(含2种)低于100*/{printf("电器\n");printf("________\n");}if((a[1]<100)&&(a[1]>=2)) /*判断日用品类库存量是否为2种以上(含2种)低于100*/{printf("日用品\n");printf("________\n");}if((a[2]<100)&&(a[2]>=2)) /*判断食品类库存量是否为2种以上(含2种)低于100*/{printf("食品\n");printf("________\n");if((a[3]<100)&&(a[3]>=2)) /*判断办公用品类库存量是否为2种以上(含2种)低于100*/{printf("办公用品\n");printf("________\n");}}int main(int argc, char* argv[]){struct good *p1,*p2; /*定义结构体指针类型*/while(1){printf("***********************************************\n");printf("1 ----------输出查看或者修改已存信息-----------\n");printf("-----------------------------------------------\n");printf("2 -----重新输入新信息(并且删除原有信息)------\n");printf("-----------------------------------------------\n");printf("3 统计商品信息(如果您还没有查看过信息请先按1)\n");printf("-----------------------------------------------\n");printf("4 -------------------退出---------------------\n");printf("***********************************************\n");scanf("%d",&m);if(m==1)shuchu(); /*调用输出信息函数*/if(m==2){system("cls");head=createlist(); /*调用建立链表函数*/}if(m==3){printf("统计结果如下\n");head=paixu(head); /*调用链表排序函数*/ jisuan(); /*调用计算函数*/ shunxudayin(); /*调用顺序打印函数*/ tongji1(); /*调用统计1函数*/tongji2(); /*调用统计2函数*/}if(m==4){p1=head;while(p1!=NULL) /*判断遍历链表结束条件*/ {p2=p1->next;free(p1); /*释放空间*/p1=p2;}break;}}return 0; /*结束程序*/ }5)调试分析过程描述:测试数据:01 milk drink 2.5 box 502 apple fruit 3 kilo 2测试输出结果:存在问题的思考:源代码出错,漏了一些分号导致程序频频出错,在进行编写时注意小地方别出错!否则会影响大局!6)总结:学习体会与收获:通过这个超市管理系统程序设计实验,我从理论知识跨越到实践上,感到收效良多,从崇拜计算机到学会控制计算机,在心理上不再觉得计算机是万能的,人的大脑才是万能的,算法才是万能的数学才是万能的,在这次实验中,实现一个完整的程序大大加深了我对C语言课程的兴趣!对C语言课程设计的认识以及自己的建议:C语言课程设计就是通过编译实现需要的功能的一种程序的设计,建议自己以后在这方面多下功夫,真正实现自己编译以个完整的C程序,实现自己的梦想和未来!。
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
西安邮电大学高级语言课程设计报告题目:超市管理系统院系名称:理学院专业名称:应用物理学班级: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:调试分析调试过程中,会有很多的错误。