admin 管理员组文章数量: 1086019
2024年3月13日发(作者:伦勃朗画一幅画的时间)
(店铺管理)超市管理系统
完整+源代码
有壹个小型超市,出售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("","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,p
1->unit,&p1->quantity);/*输入商品信息*/
printf("____________________n");
p1->next=NULL;
fprintf(fp,"%d%s%s%f%s%d",p1->num,p1->name,p1->kind,p1->price,p
1->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("____________________nn");
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,p
1->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.1ft平均价:%0.1ft总库存
量:%dn",sum[0],aver[0],a[0]);
printf("____________________________________________________n");
printf("日用品总价值:%0.1ft平均价:%0.1ft总库存
量:%dn",sum[1],aver[1],a[1]);
printf("____________________________________________________n");
printf("食品总价值:%0.1ft平均价:%0.1ft总库存
量:%dn",sum[2],aver[2],a[2]);
printf("____________________________________________________n");
printf("办公用品总价值:%0.1ft平均价:%0.1ft总库存
量:%dn",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("","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->pric
e,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%dnn",p3->num,p3->name,p3->kind,p3->pric
e,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,p
4->unit,&p4->quantity);/*输入商品信息*/
p4->next=NULL;
while(p3->next!=NULL)/*判断循环结束条件*/
{
p3=p3->next;
}
p3->next=p4;
p3=head;
if((fp=fopen("","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,p
3->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("","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,p
3->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("","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,p
3->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("%dt%st%st%0.1ft%st%dn",p3->num,p3->name,p3->kind,p3
->price,p3->unit,p3->quantity);/*输出电器类商品信息*/
printf("________________________________________________n");
}
p3=p3->next;
}
return;
}
voidprintf1(structgood*p)/*遍历链表且打印日用品类商品函数*/
{
structgood*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->quantity);/*输出日用品类商品信息*/
printf("________________________________________________n");
}
p3=p3->next;
}
return;
}
voidprintf2(structgood*p)/*遍历链表且打印办公用品类商品函数*/
{
structgood*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->kind,p3
->price,p3->unit,p3->quantity);/*输出办公用品类商品信息*/
printf("________________________________________________n");
}
p3=p3->next;
}
return;
}
voidprintf3(structgood*p)/*遍历链表且打印食品类商品函数*/
{
structgood*p3;/*定义结构体指针类型*/
p3=p;
while(p3!=NULL)/*判断遍历链表循环结束条件*/
{
if(strcmp(p3->kind,f)==0)/*判断商品类型是否为食品类型*/
{
printf("%dt%st%st%0.1ft%st%dn",p3->num,p3->name,p3->kind,p3
->price,p3->unit,p3->quantity);/*输出食品类商品信息*/
printf("________________________________________________n");
}
p3=p3->next;
}
return;
}
voidshunxudayin()
{
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] { 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) { case0: printf0(head);/*调用遍历链表且打印电器类商品函数*/ break; case1: printf1(head);/*调用遍历链表且打印日用品类商品函数*/ break; case2: printf2(head);/*调用遍历链表且打印办公用品类商品函数*/ break; case3: printf3(head);/*调用遍历链表且打印食品类商品函数*/ break; } } } voidtongji1() { 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; } } voidtongji2() { 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"); } } intmain(intargc,char*argv[]) { structgood*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; } } return0;/*结束程序*/ }
版权声明:本文标题:(店铺管理)超市管理系统完整+源代码最全版 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.roclinux.cn/p/1710270069a565364.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论