C语言程序设计超市管理系统_第1页
C语言程序设计超市管理系统_第2页
C语言程序设计超市管理系统_第3页
C语言程序设计超市管理系统_第4页
C语言程序设计超市管理系统_第5页
已阅读5页,还剩16页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、程序设计超市管理系统学院:专业:班级:姓名:学号:指导老师:超市管理系统课程设计1)需求分析:设计题目:超市管理系统设计要求:有一个小型超市,出售N(N>-10)种商品,设计并实现一个系统系统功能需求分析:1 .保存及输出:超市中的各种商品信息保存在指定文件中,可以把它们输出显示。2 .计算并排序:计算每类商品的总价值(sum,单精度)及平均价(aver,单精度,输出一位小数),将每类商品按平均价从大到小的顺序排序打印出来。3 .统计:统计输出库存量低于100的货号及类别。统计输出有两种以上(含两种)商品库存量低于100的商品类别。2)概要设计:系统总体设计框架:主模块信息输出修改模块打

2、印模块 统计模块2 统计模块1系统功能模块图:3)详细设计:主要功能模块的算法设计思路:本程序主要分为八个模块:主模块、信息输出修改模块、新建信息模块、排序模块、计算模块、统计模块1、统计模块2、打印模块。1)主模块:通过调用各分模块实现功能;2)信息输出修改模块:输出显示文件中商品信息内容,添加商品信息,删除商品信息,修改商品信息;3)新建商品信息模块:建立一个新结构体,为链表存信息用,并且将信息保存在指定的文件中;4)排序模块:把文件中顺序零乱的商品信息按单价的大小从高到低进行排序,放到链表里存储;5)计算模块:将所有商品的价格与库存量进行累加求和;6)打印模块:将商品信息按每类平均价格排

3、序(从高到低)按顺序打印出来;7)统计模块1:统计库存量低于100的货名及类别;8)统计模块2:统计商品库存量有2种以上(含2种)低于100的商品类别工作流程图:4)主要源程序代码:#include ""/*#include ""/*#include ""/*#include ""/*FILE *fp;输入,输出头文件*/ 申请空间头文件*/ 对字符串加工头文件*/ 清屏头文件*/intn=0;/*定义文件指针类型*/inti,j,a4,m;/*定义整数类型*/floataver4,sum4,g4,h;/*定义浮点

4、类型*/char c5="elec"char d5="comm"char e5="food"char f5="offi"/*/*/*/*定义字符数组类型 定义字符数组类型 定义字符数组类型 定义字符数组类型*/*/*/*/struct good /* int num; /*char name20;/*char kind40;/*float price; /* char unit10;/*int quantity; /* struct good *next; /* *head,*p1,*p2;定义结构体 */商品编号

5、 */商品名称*/商品类型*/商品价格 */商品单位*/商品数量 */定义结构体指针类型*/struct good *createlist()/*struct good *head1,*p1,*p2;/*if(fp=fopen("goods ","w")=NULL)/*创建链表函数*/定义结构体指针类型*/判断能否打开文件*/printf("can not open the file");exit(0);/*结束程序 */head1=(struct good *)malloc(sizeof(struct good); /*申请头结点空

6、*/p1=head1;p2=head1;printf("I*n");printf("请输入信息:编号,名称,类型,价格,单位,数目n");printf("(以输入“1”表示结束输入)n");printf("I*n");printf("n");scanf("%d%s%s%f%s%d",&p1->num,p1->name,p1->kind,&p1->price,p1->unit,&p1->quantity);/*输入商品

7、信息*/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=(structgood*)malloc(sizeof(structgood);/*申请新空*/printf("*n");printf("请输入信息:编号,名称,类型,价格,单位,数目n");print

8、f("(以输入“1”表示结束输入)n");printf("I*n");printf("n");scanf("%d",&p1->num);if(p1->num=-1)/*申请空间结束条件*/printf("nn");fprintf(fp,"%d",-1);fclose(fp);returnhead1;/*返回头指针*/scanf("%s%s%f%s%d",p1->name,p1->kind,&p1->price,

9、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;structgood*paixu(structgood*head2)/*链表排序函数*/structgood*p6,*p7,*r,*s;/*

10、定义结构体指针类型*/for(i=0;i<=3;i+)/*赋初值值*/ai=0;sumi=0;averi=0;p6=(structgood*)malloc(sizeof(structgood);/*申请新空间*/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-

11、>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)/*sum0=sum0+(p1->price)*(p1->quantity)

12、;/*求电器总价*/a0=a0+p1->quantity;/*求电器总件数*/if(strcmp(p1->kind,d)=0)/*判断是否为日用品类型*/求日用品总价*/sum1=sum1+(p1->price)*(p1->quantity);/*a1=a1+p1->quantity;/*求日用品总件数*/if(strcmp(p1->kind,e)=0)/*判断是否为办公用品类型*/sum2=sum2+(p1->price)*(p1->quantity);/*求办公用品总价*/a2=a2+p1->quantity;/*求办公用品总件数*/i

13、f(strcmp(p1->kind,f)=0)/*判断是否为食品类型*/sum3=sum3+(p1->price)*(p1->quantity);/*求食品总价*/a3=a3+p1->quantity;/*p1=p1->next;while(p1!=NULL);/*for(i=0;i<4;i+)求食品总件数*/遍历链表结束条件*/求每类商品平均价*/printf("I*n");printf(" 商品类型t 平均价 t总库存量 n");averi=sumi/ai;/*printf("*n");prin

14、tf("n");printf("电器总价值:%t平均价:%t总库存量:%dn",sum0,aver0,a0);printf("n");printf("日用品总价值:%t平均价:%t总库存量:dn",sum1,aver1,a1);printf("n");printf("食品总价值:%t平均价:%t总库存量:%dn",sum2,aver2,a2);printf("n");printf("办公用品总价值:%t平均价:%t总库存量:%dn",s

15、um3,aver3,a3);printf("n");voidshuchu()/*输出商品信息函数*/dostructgood*p3,*p4,*p5;/*定义结构体指针类型*/intn=0,p=0,q=0,r=0;printf("所有商品信息:n");printf("编号,名称,类型,价格,单位,数目n");判断能否打开文件*/printf("*n");if(fp=fopen("goods","rb+")=NULL)/*printf("cannotopenthefil

16、e");exit(0);/*结束程序 */*/head=(structgood*)malloc(sizeof(structgood);/*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=(structgood*)malloc(sizeof(structgood);/*fscanf(fp,"%d",

17、&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;elsep3->next=NULL;break;/*关闭文件 */fclose(fp);p3=head;while(p3!=NULL)printf("%d%s%s%s%dn

18、n",p3->num,p3->name,p3->kind,p3->price,p3->unit,p3->quantity);n");printf("p3=p3->next;printf("*n");printf("/n");while(n!=4)p3=head;printf("*n");printf("1 printf("2 printf("3 printf("4 n");添加商品信息n");删除某商品信

19、息n");修改某商品信息n");printf("I*n");scanf("%d",&n);if(n=1)/*添加商品信息 */printf(" 请输入商品 编号 名称 类型 价格 单位 数目 n");printf("I*n");p4=(struct good *)malloc(sizeof(struct good);/*/scanf("%d %s %s %f %s %d",&p4->num,p4->name,p4->kind,&p4-

20、>price,p4->unit,&p4->quantity); /*输入商品信息 */p4->next=NULL;while(p3->next!=NULL) /*判断循环结束条件*/p3=p3->next;p3->next=p4;p3=head;if(fp=fopen("goods ","w")=NULL)/*判断能否打开文件*/printf("can not open the file");exit(0); /*结束程序 */while(p3!=NULL)fprintf(fp,&qu

21、ot;%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); /*关闭文件 */返回(当你完成了对某一商品的添加、删除或者修改后请按4返printf("I*n");printf("n");printf("请按 4 返回 n");printf(&qu

22、ot;n");printf("*n"); if(n=2)/*删除商品 */printf("*n");printf(" 请输入需要删除的商品编号n");printf("*n");scanf("%d",&p);printf("*n");printf("1 确认删除 n2 printf("*n");取消删除 n");scanf("%d",&r);if(r=1)if(head->num)=p)

23、head=head->next;free(p3); /*elsep4=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","w")=NULL)/*printf("cannotopenthefile");exit(0)

24、;/*结束程序*/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("I*n");printf("n&quo

25、t;);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-&g

26、t;price,&p3->quantity);/*输入商品价格与库存量*/p3=p3->next;if(fp=fopen("goods","w")=NULL)/*判断能否打开文件*/printf("cannotopenthefile");exit(0);/*结束程序*/p3=head;while(p3!=NULL)/*判断循环结束条件*/fprintf(fp,"%d%s%s%f%s%d",p3->num,p3->name,p3->kind,p3->price,p3->

27、;unit,p3->quantity);/*将商品信息写入文件*/p3=p3->next;fprintf(fp,"%d",-1);关闭文件 */fclose(fp);/*printf("I*n");printf("n");printf("请按4返回n");printf("n");printf("I*n"); if(n=4)/*退出 */break;printf("*n");printf("1 继续修改 nn2返回 n");p

28、rintf("I*n");scanf("%d",&p);if(p=1)continue; /*if(p=2)break;/*while(n!=2);fclose(fp); /*继续循环 */跳出循环 */关闭文件 */voidprintf0(structgood*p)/*遍历链表并打印电器类商品函数*/structgood*p3;/*定义结构体指针类型*/p3=p;while(p3!=NULL)/*判断遍历链表循环结束条件*/if(strcmp(p3->kind,c)=0)/*判断商品类型是否为电器类型*/printf("%dt%

29、st%st%t%st%dn",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) */*遍历链表并打印日用品类商品函数定义结构体指针类型*/判断遍历链表循环结束条件*/*判断商品

30、类型是否为日用品类型*/printf("%dt%st%st%t%st%dn",p3->num,p3->name,p3->kind,p3->price,p3->unit,p3->quantity);/*输出日用品类商品信息*/printf("n");p3=p3->next;return;voidprintf2(structgood*p)/*遍历链表并打印办公用品类商品函数*/structgood*p3;/*定义结构体指针类型*/p3=p;while(p3!=NULL)/*判断遍历链表循环结束条件*/if(strcm

31、p(p3->kind,e)=0)/*判断商品类型是否为办公用品类型*/printf("%dt%st%st%t%st%dn",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->

32、kind,f)=0)/*遍历链表并打印食品类商品函数定义结构体指针类型*/判断遍历链表循环结束条件*/* 判断商品类型是否为食品类型*/*/printf("%dt%st%st%t%st%dn",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+) gi=averi; /* for(j=0

33、;j<3;j+)/*for(i=j+1;i<4;i+) if(gj<gi) h=gj;将平均价赋给新数组*/将新数组用冒泡排序法排序 */gj=gi;gi=h;printf("nprintf(" 商品平均价格排序表(从高到低)n");printf("I*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 (averi=gj)

34、/* switch(i)case 0:printf0(head); /* break;case 1:printf1(head); /* break;case 2: printf2(head);/* break;case 3:printf3(head); /* break;判断每类商品平均价格的先后顺序*/调用遍历链表并打印电器类商品函数*/调用遍历链表并打印日用品类商品函数*/调用遍历链表并打印办公用品类商品函数*/调用遍历链表并打印食品类商品函数*/voidtongji1()p1=head;printf("n*n");printf("库存量低于100的货名及类别

35、n");printf("*n");printf("n");printf("商品名称t商品类型n");printf("n");while(p1!=NULL)/*判断遍历链表循环结束条件*/判断库存量是否小于100*/if(p1->quantity<100)/*输出商品名称及类别 */printf("%st%sn",p1->name,p1->kind);/*n");printf("p1=p1->next;voidtongji2()print

36、f("n*n");printf("商品库存量有2种以上(含2种)低于100的商品类别printf("*n");printf("n");if(a0<100)&&(a0>=2)/*库存量是否为2种以上(含2种)低于100*/printf("电器n");printf("n");if(a1<100)&&(a1>=2)/*类库存量是否为2种以上(含2种)低于100*/printf("日用品n");printf("n");if(a2<100)&&(a2>=2)/*库存量是否为2种以上(含2种)低于100*/prin

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论