超市管理系统完整+源代码.docx

上传人:b****5 文档编号:14643313 上传时间:2023-06-25 格式:DOCX 页数:23 大小:19.07KB
下载 相关 举报
超市管理系统完整+源代码.docx_第1页
第1页 / 共23页
超市管理系统完整+源代码.docx_第2页
第2页 / 共23页
超市管理系统完整+源代码.docx_第3页
第3页 / 共23页
超市管理系统完整+源代码.docx_第4页
第4页 / 共23页
超市管理系统完整+源代码.docx_第5页
第5页 / 共23页
超市管理系统完整+源代码.docx_第6页
第6页 / 共23页
超市管理系统完整+源代码.docx_第7页
第7页 / 共23页
超市管理系统完整+源代码.docx_第8页
第8页 / 共23页
超市管理系统完整+源代码.docx_第9页
第9页 / 共23页
超市管理系统完整+源代码.docx_第10页
第10页 / 共23页
超市管理系统完整+源代码.docx_第11页
第11页 / 共23页
超市管理系统完整+源代码.docx_第12页
第12页 / 共23页
超市管理系统完整+源代码.docx_第13页
第13页 / 共23页
超市管理系统完整+源代码.docx_第14页
第14页 / 共23页
超市管理系统完整+源代码.docx_第15页
第15页 / 共23页
超市管理系统完整+源代码.docx_第16页
第16页 / 共23页
超市管理系统完整+源代码.docx_第17页
第17页 / 共23页
超市管理系统完整+源代码.docx_第18页
第18页 / 共23页
超市管理系统完整+源代码.docx_第19页
第19页 / 共23页
超市管理系统完整+源代码.docx_第20页
第20页 / 共23页
亲,该文档总共23页,到这儿已超出免费预览范围,如果喜欢就下载吧!
下载资源
资源描述

超市管理系统完整+源代码.docx

《超市管理系统完整+源代码.docx》由会员分享,可在线阅读,更多相关《超市管理系统完整+源代码.docx(23页珍藏版)》请在冰点文库上搜索。

超市管理系统完整+源代码.docx

超市管理系统完整+源代码

有一个小型超市,出售N(N>=10)种商品,设计并实现一个系统,完成下列功能:

1.保存及输出。

超市中的各种商品信息保存在指定文件中,可以把它们输出显示。

2.计算并排序。

计算每类商品的总价值(sum,单精度)及平均价(aver,单精度,输出一位小数),将每类商品按平均价从大到小的顺序排序打印出来。

3.统计。

统计输出库存量低于100的货号及类别。

统计输出有两种以上(含两种)商品库存量低于100的商品类别。

1.2总体结构

本程序主要分为八个模块:

主模块、信息输出修改模块、新建信息模块、排序模块、计算模块、统计模块1、统计模块2、打印模块。

1)主模块:

通过调用各分模块实现功能;

2)信息输出修改模块:

输出显示文件中商品信息内容,添加商品信息,删除商品信息,修改商品信息;

3)新建商品信息模块:

建立一个新结构体,为链表存信息用,并且将信息保存在指定的文件中;

4)排序模块:

把文件中顺序零乱的商品信息按单价的大小从高到低进行排序,放到链表里存储;

5)计算模块:

将所有商品的价格与库存量进行累加求和;

6)打印模块:

将商品信息按每类平均价格排序(从高到低)按顺序打印出来;

7)统计模块1:

统计库存量低于100的货名及类别;

8)统计模块2:

统计商品库存量有2种以上(含2种)低于100的商品类别。

 

附录(程序清单)

#include"stdio.h"/*输入,输出头文件*/

#include"stdlib.h"/*申请空间头文件*/

#include"string.h"/*对字符串加工头文件*/

#include"conio.h"/*清屏头文件*/

FILE*fp;

intn=0;/*定义文件指针类型*/

inti,j,a[4],m;/*定义整数类型*/

floataver[4],sum[4],g[4],h;/*定义浮点类型*/

charc[5]="elec";/*定义字符数组类型*/

chard[5]="comm";/*定义字符数组类型*/

chare[5]="food";/*定义字符数组类型*/

charf[5]="offi";/*定义字符数组类型*/

structgood/*定义结构体*/

{

intnum;/*商品编号*/

charname[20];/*商品名称*/

charkind[40];/*商品类型*/

floatprice;/*商品价格*/

charunit[10];/*商品单位*/

intquantity;/*商品数量*/

structgood*next;/*定义结构体指针类型*/

}*head,*p1,*p2;

structgood*createlist()/*创建链表函数*/

{

structgood*head1,*p1,*p2;/*定义结构体指针类型*/

if((fp=fopen("goodsmessage.txt","w"))==NULL)/*判断能否打开文件*/

{

printf("cannotopenthefile");

exit(0);/*结束程序*/

}

head1=(structgood*)malloc(sizeof(structgood));/*申请头结点空间*/

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,&p1->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=(structgood*)malloc(sizeof(structgood));/*申请新空间*/

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);

returnhead1;/*返回头指针*/

}

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;

}

}

 

structgood*paixu(structgood*head2)/*链表排序函数*/

{

structgood*p6,*p7,*r,*s;/*定义结构体指针类型*/

for(i=0;i<=3;i++)/*赋初值值*/

{

a[i]=0;

sum[i]=0;

aver[i]=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->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);/*释放第一个无效空间*/

returnhead2;

}

voidjisuan()

{

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");

}

 

voidshuchu()/*输出商品信息函数*/

{

do

{

structgood*p3,*p4,*p5;/*定义结构体指针类型*/

intn=0,p=0,q=0,r=0;

printf("所有商品信息:

\n");

printf("编号,名称,类型,价格,单位,数目\n");

printf("**********************************\n");

if((fp=fopen("goodsmessage.txt","rb+"))==NULL)/*判断能否打开文件*/

{

printf("cannotopenthefile");

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",&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->kind,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=(structgood*)malloc(sizeof(structgood));/*申请空间*/

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("goodsmessage.txt","w"))==NULL)/*判断能否打开文件*/

{

printf("cannotopenthefile");

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("goodsmessage.txt","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->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("goodsmessage.txt","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->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);/*关闭文件*/

}

voidprintf0(structgood*p)/*遍历链表并打印电器类商品函数*/

{

structgood*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

展开阅读全文
相关资源
猜你喜欢
相关搜索
资源标签

当前位置:首页 > IT计算机 > 电脑基础知识

copyright@ 2008-2023 冰点文库 网站版权所有

经营许可证编号:鄂ICP备19020893号-2