(店铺管理)超市管理系统完整+源代码_第1页
(店铺管理)超市管理系统完整+源代码_第2页
(店铺管理)超市管理系统完整+源代码_第3页
(店铺管理)超市管理系统完整+源代码_第4页
(店铺管理)超市管理系统完整+源代码_第5页
免费预览已结束,剩余24页可下载查看

下载本文档

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

文档简介

1、有一个小型超市,出售N (N> = 10)种商品,设计并实现一个系统,完成下列 功能:1 保存及输出。 超市中的各种商品信息保存在指定文件中, 可以把它们输出显示。2 .计算并排序。计算每类商品的总价值(sum,单精度)及平均价(aver,单 精度,输出一位小数),将每类商品按平均价从大到小的顺序排序打印出来。3 统计。统计输出库存量低于100 的货号及类别。统计输出有两种以上(含两种)商品库存量低于 100 的商品类别。1.2 总体结构本程序主要分为八个模块:主模块、信息输出修改模块、新建信息模块、排序模块、计算模块、统计模块1 、统计模块2、打印模块。1 )主模块:通过调用各分模块实

2、现功能;2 )信息输出修改模块:输出显示文件中商品信息内容,添加商品信息,删除商品信息,修改商品信息;3 ) 新建商品信息模块:建立一个新结构体,为链表存信息用,并且将信息保存在指定的文件中;4 )排序模块:把文件中顺序零乱的商品信息按单价的大小从高到低进行排序,放到链表里存储;5 )计算模块:将所有商品的价格与库存量进行累加求和;6 )打印模块:将商品信息按每类平均价格排序(从高到低)按顺序打印出来;7 )统计模块1:统计库存量低于 100的货名及类别;8 )统计模块2:统计商品库存量有2种以上(含 2 种)低于 100的商品类别。附 录(程序清单)#include "stdio.

3、h"#include "stdlib.h"#include "string.h"#include "conio.h" FILE *fp;/* 输入,输出头文件 */* 申请空间头文件*/*对字符串加工头文件*/* 清屏头文件*/int n=0;/*定义文件指针类型*/int i,j,a4,m;/*定义整数类型*/float aver4,sum4,g4,h;/*定义浮点类型*/char c5="elec"char d5="comm"char e5="food"char

4、 f5="offi"/*定义字符数组类型*/*定义字符数组类型 */*定义字符数组类型*/*定义字符数组类型*/struct good/*定义结构体*/int num;/*商品编号*/char name20;/*商品名称*/char kind40;/*商品类型 */float price;/* 商品价格 */char unit10;/*商品单位*/int quantity;/*商品数量*/struct good *next;/*定义结构体指针类型*/*head,*p1,*p2;struct good *createlist()/*创建链表函数*/struct good *h

5、ead1,*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(" 请输入信息 :编号,名称,类型,价格,单位,数目

6、 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);/*输入商品信息 */printf("n");p1->next=NULL;fprintf(fp,"%d %s %s

7、%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("I *n&quo

8、t;);printf("n");scanf("%d",&p1->num);if(p1->num=-1)/* 申请空间结束条件*/printf("nn");fprintf(fp,"%d",-1);fclose(fp);return head1;/*返回头指针 */scanf("%s %s %f %s %d",p1->name,p1->kind,&p1->price,p1->unit,&p1->quantity); /*输入商品信息

9、*/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+)/

10、*赋初值值 */ai=0;sumi=0;averi=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)/*判断循环结

11、束条件 */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;doif(strcmp(p1->kind,c)=0) /*判断是否为电器类型*/sum0=sum0+(p1->price)*(p1->quantity);/* 求电器总价*/a0=a0+p1->qua

12、ntity;/*求电器总件数*/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;/*求办公用品总件数*/if(strcmp(p1->kind,f)

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

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

15、1ft 总库存量 :%dn",sum3,aver3,a3);printf("n");void shuchu()/*输出商品信息函数*/dostruct 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) /*

16、判断能否打开文件*/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=(struc

17、t 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;elsep3->n

18、ext=NULL;break;fclose(fp);/* 关闭文件 */p3=head;while(p3!=NULL)printf(" %d %s %s %0.1f %s %dnn",p3->num,p3->name,p3- >kind,p3->price,p3->unit,p3->quantity);printf("n");p3=p3->next;printf("I*n");printf("/n");while(n!=4)p3=head;printf("I*n&

19、quot;);printf("1 添加商品信息n");printf("2 删除某商品信息n");printf("3 修改某商品信息n");printf("4 返回 (当你完成了对某一商品的添加、 删除或者修改后请按4 返回)n");printf("I*n");scanf("%d",&n);if(n=1)/*添加商品信息 */printf("请输入商品编号名称类型价格单位数目n");printf("I *n");/* 申请空间 *

20、/p4=(struct good *)malloc(sizeof(struct good);scanf("%d %s %s %f %s %d",&p4->num,p4->name,p4->kind,&p4->price,p4->unit,&p4->quantity);/*输入商品信息*/p4->next=NULL;while(p3->next!=NULL)/*判断循环结束条件 */p3=p3->next;p3->next=p4;p3=head;/*判断能if(fp=fopen("g

21、oods 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);

22、fclose(fp);/*关闭文件 */printf("*n");printf("n");printf(" 请按 4 返回 n");printf("n");printf("I*n");/*删除商品 */if(n=2)printf("I*n");printf(”请输入需要删除的商品编号n");printf("I*n");scanf("%d",&p);printf("I*n");printf("

23、;1 确认删除 n2 取消删除 n");printf("I*n");scanf("%d",&r);if(r=1)if(head->num)=p)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;/*判断能否

24、打开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=

25、p3->next;fprintf(fp,"%d",-1);fclose(fp);/*关闭文件 */if(r=2)continue;/*继续循环 */printf("I*n");printf("n");printf(" 请按 4 返回 n");printf("n");printf("I*n");if(n=3)/*修改某商品信息 */printf(”请输入需要修改的商品编号n");scanf("%d",&q);while(p3!=NUL

26、L)/*判断循环结束条件*/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 fi

27、le");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("I*n");if(n=4)/*退出 *

28、/printf("n");printf(" 请按 4 返回 n");printf("n");printf("I*n");break;printf("*n");printf("1 继续修改 nn2 返回 n");printf("I*n");scanf("%d",&p);if(p=1)continue;/*继续循环 */if(p=2)break;/*跳出循环*/while(n!=2);fclose(fp);/* 关闭文件*/void

29、 printf0(struct good *p)/*遍历链表并打印电器类商品函数*/struct good *p3;/*定义结构体指针类型*/p3=p;while (p3!=NULL)/*判断遍历链表循环结束条件*/if(strcmp(p3->kind,c)=0)/*判断商品类型是否为电器类型*/printf("%dt%st%st%0.1ft%st%dn",p3->num,p3->name,p3->kind,p3->price,p3->unit,p3->quantity);/*输出电器类商品信息 */printf("n&q

30、uot;);p3=p3->next;return;void printf1(struct good *p)/* 遍历链表并打印日用品类商品函数*/struct good *p3;/*定义结构体指针类型*/p3=p;while (p3!=NULL)/*判断遍历链表循环结束条件*/if(strcmp(p3->kind,d)=0) /*判断商品类型是否为日用品类型*/printf("%dt%st%st%0.1ft%st%dn",p3->num,p3->name,p3->kind,p3->price,p3->unit,p3->quan

31、tity);/* 输出日用品类商品信息 */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("%dt%st%st%0.1ft%st%dn",p3->num,p3->name,p3->ki

32、nd,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("%dt%st%st%0.1ft%st%dn"

33、;,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;j<3;j+)/*将新数组用冒泡排序法排序*/for(i=j+1;i<4;i+)if(gj<gi)h=gj;gj=gi;gi=h;printf("n*n");

34、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 (averi=gj)/*判断每类商品平均价格的先后顺序 */switch(i)case 0:printf0(head); /* 调用遍历链表并打印电器类商品函数*/break;case 1:printf1(h

35、ead); /* 调用遍历链表并打印日用品类商品函数*/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("%st%sn",p1->name,p1->kind); /* 输出商品名称及类别 */printf("n");p1=p1->next;void tongji2()*n");printf(" 商品库存量有2 种以上(含 2 种)低于 100

温馨提示

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

评论

0/150

提交评论