超市商品管理系统(免费哦,超好有源代码的)

合集下载

商品管理系统源代码

商品管理系统源代码

商品管理系统源代码中南大学本科生课程设计(实践)源代码(大学计算机基础)题目超市商品管理系统学生姓名指导教师学院专业班级学生学号计算机基础教学实验中心2011年 6月 29 日#include#include#include"Goods.h"using namespace std;int displayMenu(){int choice=0;cout<<"**********欢迎进入超市商品管理系统-主菜单**********制作人:方锦\n"<<"\t1. 我要进商品\n"<<"\t2. 我要卖商品\n"<<"\t3. 查看仓库\n"<<"\t4. 销售额及利润统计\n"<<"\t0. 退出系统\n"<<"请选择所需的操作(0~4):";cin>>choice;return choice;}void disp(CGoods * goods[],int );int main(){CGoods *Goods[100];double total=0;double profit=0;Goods[0]=new CGoods(0,"康师傅方便面",1,3,3.5,1);int choice1,choice2,choice3;static int Goodnum=0;int temp;string name;int daihao,bianhao;double in,out;double count;choice1=displayMenu();while(choice1){switch(choice1){case 1:disp(Goods,Goodnum);cout<<"是否为新增商品,否请按1,是请按2,退出请按0";cin>>choice2;switch(choice2){case 1:cout<<"\n请输入您要进商品的编号"<<endl;< p="">cin>>choice3;if(choice3>Goodnum||choice3<0){cout<<"您输入的商品编号不存在,请重新输入"<<endl;< p="">break;}cout<<"\n请输入数量"<<endl;< p="">cin>>temp;Goods[choice3]->setCount(temp+Goods[choice3]->getCount());break;case 2:cout<<"\n欢迎新增商品"<<endl;< p="">Goodnum++;cout<<"\n请输入您新增商品名称:";Goods[Goodnum]=new CGoods(1,"aa",1,1,1,1);Goods[Goodnum]->setBianhao(Goodnum);cin>>name;Goods[Goodnum]->setName(name);cout<<"\n请输入供货商代号:";cin>>daihao;Goods[Goodnum]->setDaihao(daihao);cout<<"\n请输入进价";cin>>in;Goods[Goodnum]->setinPrice(in);cout<<"\n请输入售出价";cin>>out;Goods[Goodnum]->setoutPrice(out);cout<<"\n请输入数量";cin>>count;Goods[Goodnum]->setCount(count);cout<<"新增商品成功"<<endl;< p="">break;case 0:break;default:cout<<"请按提示输入!"<<endl;< p="">break;}break;case 2:disp(Goods,Goodnum);cout<<"\n请输入商品编号:";cin>>bianhao;if(bianhao<0||bianhao>Goodnum){cout<<"您输入的商品编号不存在,请重新输入\n"; break;} cout<<"请问要买"<getName()<<"多少"<<endl;< p=""> cin>>count;if((Goods[bianhao]->getCount()-count)<0){cout<<"不好意思,库存不够,请重新输入"<<endl;< p=""> break;}Goods[bianhao]->setCount(Goods[bianhao]->getCount()-count);total+=Goods[bianhao]->getOutPrice()*count;profit+=(Goods[bianhao]->getOutPrice()-Goods[bianhao]->getInPrice())*count;break;case 3:disp(Goods,Goodnum);break;case 4:cout<<"您已售出";cout<<total<<"元"<<endl;< p="">cout<<"获得利润"<<profit<<"元"<<endl;< p="">break;default:cout<<"请按提示输入"<<endl;< p="">break;}choice1=displayMenu();}return 0;}void disp(CGoods * goods[],int num)cout<<"您仓库剩余商品有:\n";for(int i=0;i<=num;i++)cout<<"\t"<<i+1<<"."<<*goods[i];< p="">}// Goods.cpp: implementation of the CGoods class.///////////////////////////////////////////////////////////////////// ///#include "Goods.h"#include#includeusing namespace std;/////////////////////////////////////////////////////////////////// ///// Construction/Destruction/////////////////////////////////////////////////////////////////// ///CGoods::CGoods(int m1,const string &nn,int m2, double m3,double m4 ,int cc) {setBianhao(m1); setDaihao(m2); setName(nn);setinPrice(m3); setoutPrice(m4); setCount(cc);}CGoods::CGoods(const CGoods &g){setBianhao(g.bianhao); setDaihao(g.daihao); setName(/doc/6417181243.html,);setinPrice(g.in); setoutPrice(g.out);}CGoods::~CGoods()}ostream& operator<<(ostream& output, const CGoods &c) {output<<"商品编号:"<<c.getbianhao()< p=""><<"\n商品名:"<<c.getname()< p=""><<"\n供应商代号:"<<c.getdaihao()< p=""><<"\n进货价:"<<c.getinprice()< p=""><<"\n售出价:"<<c.getoutprice()< p=""><<"\n存货数:"<<c.getcount()< p=""><<"\n";return output;}// Goods.h: interface for the CGoods class.///////////////////////////////////////////////////////////////////// ///#if !defined(AFX_GOODS_H__A8BC5029_A8C8_41BA_BA6C_ 8FE1A04DEECB__INCLUDED_)#defineAFX_GOODS_H__A8BC5029_A8C8_41BA_BA6C_8FE1A04DEECB__ INCLUDED_#if _MSC_VER > 1000#pragma once#endif // _MSC_VER > 1000#include#includeusing namespace std;class CGoods{friend ostream& operator<<(ostream& output, const CGoods &c);public:// CGoods(int m1=0,string &nn="",int m2=0, int m3=0,int m4=0,int cc=0){//bianhao=m1;name=nn;daihao=m2;in=m3;out=m4;count=cc;} CGoods(int m1=0,const string &nn="",int m2=0, double m3=0,double m=0,int cc=0);CGoods(const CGoods &goods);int getBianhao() const {return bianhao;}int getDaihao() const { return daihao;}string getName() const { return name;}double getInPrice() const { return in;}double getOutPrice() const { return out;}int getCount() const { return count;}void setBianhao(const int nn){bianhao=nn;}void setDaihao(const int mm){daihao=mm;}void setName(const string &n){name=n;}void setinPrice(double ip){in=ip;}void setoutPrice(double op){out=op;}void setCount(int c){count=c;}virtual ~CGoods();private:int bianhao,daihao;double in,out;int count;string name;};#endif// !defined(AFX_GOODS_H__A8BC5029_A8C8_41BA_BA6C_8FE1 A04DEECB__INCLUDED_)</c.getcount()<></c.getoutprice()<></c.getinprice()<></c.getdaihao()<></c.getname()<></c.getbianhao()<></i+1<<"."<<*goods[i];<></endl;<></profit<<"元"<<endl;<></total<<"元"<<endl;<></endl;<></endl;<></endl;<></endl;<></endl;<></endl;<></endl;<></endl;<>。

超市管理系统完整源代码

超市管理系统完整源代码

有一个小型超市,出售NN>=10种商品,设计并实现一个系统,完成下列功能:1.保存及输出;超市中的各种商品信息保存在指定文件中,可以把它们输出显示; 2.计算并排序;计算每类商品的总价值sum,单精度及平均价aver,单精度,输出一位小数,将每类商品按平均价从大到小的顺序排序打印出来;3.统计;统计输出库存量低于100的货号及类别;统计输出有两种以上含两种商品库存量低于100的商品类别;总体结构本程序主要分为八个模块:主模块、信息输出修改模块、新建信息模块、排序模块、计算模块、统计模块1、统计模块2、打印模块;1 主模块:通过调用各分模块实现功能;2 信息输出修改模块:输出显示文件中商品信息内容,添加商品信息,删除商品信息,修改商品信息;3 新建商品信息模块:建立一个新结构体,为链表存信息用,并且将信息保存在指定的文件中;4 排序模块:把文件中顺序零乱的商品信息按单价的大小从高到低进行排序,放到链表里存储;5 计算模块:将所有商品的价格与库存量进行累加求和;6 打印模块:将商品信息按每类平均价格排序从高到低按顺序打印出来;7 统计模块1:统计库存量低于100的货名及类别;8 统计模块2:统计商品库存量有2种以上含2种低于100的商品类别;附录程序清单include "" /输入,输出头文件/include "" /申请空间头文件/include "" /对字符串加工头文件/include "" /清屏头文件/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 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 head1,p1,p2; /定义结构体指针类型/iffp=fopen"goods ","w"==NULL /判断能否打开文件/{printf"can not open the file";exit0; /结束程序/}head1=struct good mallocsizeofstruct 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 ,&p1->quantity; /输入商品信息/printf"____________________\n";p1->next=NULL;fprintffp,"%d %s %s %f %s %d",p1->num,p1->name,p1->kind,p1->price,p1->unit,p1->quantity; /将商品信息写入文件/while1{p1=struct good mallocsizeofstruct good; /申请新空间/printf"\n";printf"请输入信息:编号,名称,类型,价格,单位,数目\n";printf" 以输入“-1”表示结束输入\n";printf"\n";printf"____________________\n";scanf"%d",&p1->num;ifp1->num==-1 /申请空间结束条件/{printf"____________________\n\n";fprintffp,"%d",-1;fclosefp;return head1; /返回头指针/}scanf"%s %s %f %s %d",p1->name,p1->kind,&p1->price,p1->unit,&p1->quantity; /输入商品信息/printf"________________\n";fprintffp,"%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 paixustruct goodhead2 /链表排序函数/{struct good p6,p7,r,s; /定义结构体指针类型/fori=0;i<=3;i++ /赋初值值/{ai=0;sumi=0;averi=0;}p6=struct good mallocsizeofstruct good; /申请新空间/ p6->next=head2;head2=p6;whilep6->next=NULL /判断循环结束条件/{p7=p6->next;r=p6;whilep7->next=NULL /判断循环结束条件/{ifp7->next->price>r->next->price /判断是否调换/ r=p7;p7=p7->next;}ifp6=r /判断循环结束条件/{s=r->next; /指针调换/r->next=s->next;s->next=p6->next;p6->next=s;}p6=p6->next;}p6=head2;head2=head2->next;freep6; /释放第一个无效空间/return head2;}void jisuan{p1=head;do{ifstrcmpp1->kind,c==0 /判断是否为电器类型/ {sum0=sum0+p1->pricep1->quantity; /求电器总价/a0=a0+p1->quantity; /求电器总件数/}ifstrcmpp1->kind,d==0 /判断是否为日用品类型/{sum1=sum1+p1->pricep1->quantity; /求日用品总价/a1=a1+p1->quantity; /求日用品总件数/}ifstrcmpp1->kind,e==0 /判断是否为办公用品类型/{sum2=sum2+p1->pricep1->quantity; /求办公用品总价/a2=a2+p1->quantity; /求办公用品总件数/}ifstrcmpp1->kind,f==0 /判断是否为食品类型/{sum3=sum3+p1->pricep1->quantity; /求食品总价/a3=a3+p1->quantity; /求食品总件数/}p1=p1->next;}while p1=NULL; /遍历链表结束条件/fori=0;i<4;i++averi=sumi/ai; /求每类商品平均价/printf"\n";printf"商品类型 \t 平均价\t 总库存量\n";printf"\n";printf"____________________________________________________\n"; printf"电器总价值:%\t平均价:%\t总库存量:%d\n",sum0,aver0,a0;printf"____________________________________________________\n"; printf"日用品总价值:%\t平均价:%\t总库存量:%d\n",sum1,aver1,a1; printf"____________________________________________________\n"; printf"食品总价值:%\t平均价:%\t总库存量:%d\n",sum2,aver2,a2;printf"____________________________________________________\n"; printf"办公用品总价值:%\t平均价:%\t总库存量:%d\n",sum3,aver3,a3; 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";iffp=fopen"goods ","rb+"==NULL /判断能否打开文件/{printf"can not open the file";exit0; /结束程序/}head=struct good mallocsizeofstruct good; /申请头结点空间/p3=head;fscanffp,"%d %s %s %f %s %d",&p3->num,p3->name,p3->kind,&p3->price,p3->unit,&p3->quantity; /从文件中写到链表/while1{p4=struct good mallocsizeofstruct good; /申请头结点空间/fscanffp,"%d ",&p4->num;ifp4->num=-1 /判断循环结束条件/{fscanffp,"%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;}}fclosefp; /关闭文件/p3=head;whilep3=NULL{printf" %d %s %s % %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";whilen=4{p3=head;printf"\n";printf"1 添加商品信息\n";printf"2 删除某商品信息\n";printf"3 修改某商品信息\n";printf"4 返回当你完成了对某一商品的添加、删除或者修改后请按4返回\n"; printf"\n";scanf"%d",&n;ifn==1 /添加商品信息/{printf"请输入商品编号名称类型价格单位数目\n";printf"\n";p4=struct good mallocsizeofstruct good; /申请空间/scanf"%d %s %s %f %s %d",&p4->num,p4->name,p4->kind,&p4->price,p4->unit ,&p4->quantity; /输入商品信息/p4->next=NULL;whilep3->next=NULL /判断循环结束条件/{p3=p3->next;}p3->next=p4;p3=head;iffp=fopen"goods ","w"==NULL /判断能否打开文件/{printf"can not open the file";exit0; /结束程序/}whilep3=NULL{fprintffp,"%d %s %s %f %s %d",p3->num,p3->name,p3->kind,p3->price,p3->unit,p3->quantity /将商品信息写入文件/p3=p3->next;}fprintffp,"%d",-1;fclosefp; /关闭文件/printf"\n";printf"__________________________________\n";printf"------------请按4返回-------------\n";printf"__________________________________\n";printf"\n";}ifn==2 /删除商品/{printf"\n";printf"请输入需要删除的商品编号\n";printf"\n";scanf"%d",&p;printf"\n";printf"1 确认删除\n2 取消删除\n";printf"\n";scanf"%d",&r;ifr==1{ifhead->num==p{head=head->next;freep3; /释放空间/}else{p4=head;p3=p4->next;whilep3=NULL /判断循环结束条件/ {ifp3->num==p{p5=p3->next;freep3; /释放空间/p4->next=p5;break;}p3=p3->next;p4=p4->next;}}iffp=fopen"goods ","w"==NULL /判断能否打开文件/ {printf"can not open the file";exit0; /结束程序/}p3=head;whilep3=NULL /判断循环结束条件/{fprintffp,"%d %s %s %f %s %d",p3->num,p3->name,p3->kind,p3->price,p3->unit,p3->quantity; /将商品信息写入文件/p3=p3->next;}fprintffp,"%d",-1;fclosefp; /关闭文件/}ifr==2continue; /继续循环/printf"\n";printf"__________________________________\n";printf"------------请按4返回-------------\n";printf"__________________________________\n";printf"\n";}ifn==3 /修改某商品信息/{printf"请输入需要修改的商品编号\n";scanf"%d",&q;whilep3=NULL /判断循环结束条件/{ifp3->num==q /判断是否为所需要修改的商品/{printf"请输入商品单价与库存量如果单价不变请输入原来的单价\n";scanf"%f %d",&p3->price,&p3->quantity; /输入商品价格与库存量/}p3=p3->next;}iffp=fopen"goods ","w"==NULL /判断能否打开文件/{printf"can not open the file";exit0; /结束程序/}p3=head;whilep3=NULL /判断循环结束条件/{fprintffp,"%d %s %s %f %s %d",p3->num,p3->name,p3->kind,p3->price,p3->unit,p3->quantity; /将商品信息写入文件/p3=p3->next;}fprintffp,"%d",-1;fclosefp; /关闭文件/printf"\n";printf"__________________________________\n";printf"------------请按4返回-------------\n";printf"__________________________________\n";printf"\n";}ifn==4 /退出/break;}printf"\n";printf"1 继续修改\n---------\n2 返回\n";printf"\n";scanf"%d",&p;ifp==1continue; /继续循环/ifp==2break; /跳出循环/}whilen=2;fclosefp; /关闭文件/}void printf0struct good p /遍历链表并打印电器类商品函数/{struct good p3; /定义结构体指针类型/p3=p;while p3=NULL /判断遍历链表循环结束条件/{ifstrcmpp3->kind,c==0 /判断商品类型是否为电器类型/{printf"%d\t%s\t%s\t%\t%s\t%d\n",p3->num,p3->name,p3->kind,p3->price,p3->unit,p3->quantity; /输出电器类商品信息/printf"________________________________________________\n";}p3=p3->next;}return;}void printf1struct good p /遍历链表并打印日用品类商品函数/{struct good p3; /定义结构体指针类型/p3=p;while p3=NULL /判断遍历链表循环结束条件/{ifstrcmpp3->kind,d==0 /判断商品类型是否为日用品类型/{printf"%d\t%s\t%s\t%\t%s\t%d\n",p3->num,p3->name,p3->kind,p3->price,p3->unit,p3->quantity; /输出日用品类商品信息/printf"________________________________________________\n";}p3=p3->next;}return;}void printf2struct good p /遍历链表并打印办公用品类商品函数/{struct good p3; /定义结构体指针类型/p3=p;while p3=NULL /判断遍历链表循环结束条件/{ifstrcmpp3->kind,e==0 /判断商品类型是否为办公用品类型/{printf"%d\t%s\t%s\t%\t%s\t%d\n",p3->num,p3->name,p3->kind,p3->price,p3->unit,p3->quantity; /输出办公用品类商品信息/printf"________________________________________________\n";}p3=p3->next;}return;}void printf3struct good p /遍历链表并打印食品类商品函数/{struct good p3; /定义结构体指针类型/p3=p;while p3=NULL /判断遍历链表循环结束条件/{ifstrcmpp3->kind,f==0 /判断商品类型是否为食品类型/{printf"%d\t%s\t%s\t%\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{fori=0;i<4;i++gi=averi; /将平均价赋给新数组/forj=0;j<3;j++ /将新数组用冒泡排序法排序/fori=j+1;i<4;i++{ifgj<gi{h=gj;gj=gi;gi=h;}}printf"\n\n";printf"商品平均价格排序表从高到低\n";printf"\n";printf"________________________________________________\n";printf"编号\t名称\t类别\t单价\t单位\t数量\n";printf"________________________________________________\n"; forj=0;j<4;j++fori=0;i<4;i++{if averi==gj /判断每类商品平均价格的先后顺序/switchi{case 0:printf0head; /调用遍历链表并打印电器类商品函数/break;case 1:printf1head; /调用遍历链表并打印日用品类商品函数/break;case 2:printf2head;/调用遍历链表并打印办公用品类商品函数/break;case 3:printf3head; /调用遍历链表并打印食品类商品函数/ break;}}}void tongji1{p1=head;printf"\n\n";printf"库存量低于100的货名及类别\n";printf"\n";printf"________________________\n";printf"商品名称\t商品类型\n";printf"________________________\n";whilep1=NULL /判断遍历链表循环结束条件/{ifp1->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";ifa0<100&&a0>=2 /判断电器类库存量是否为2种以上含2种低于100/{printf"电器\n";printf"________\n";}ifa1<100&&a1>=2 /判断日用品类库存量是否为2种以上含2种低于100/{printf"日用品\n";printf"________\n";}ifa2<100&&a2>=2 /判断食品类库存量是否为2种以上含2种低于100/{printf"食品\n";printf"________\n";}ifa3<100&&a3>=2 /判断办公用品类库存量是否为2种以上含2种低于100/{printf"办公用品\n";printf"________\n";}}int mainint argc, char argv{struct good p1,p2; /定义结构体指针类型/while1{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;ifm==1shuchu; /调用输出信息函数/ifm==2{system"cls";head=createlist; /调用建立链表函数/}ifm==3{printf"统计结果如下\n";head=paixuhead; /调用链表排序函数/ jisuan; /调用计算函数/shunxudayin; /调用顺序打印函数/tongji1; /调用统计1函数/tongji2; /调用统计2函数/}ifm==4{p1=head;whilep1=NULL /判断遍历链表结束条件/{p2=p1->next;freep1; /释放空间/ p1=p2;}break;}}return 0; /结束程序/ }。

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

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

有一个小型超市,出售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;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,&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=(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->quan tity); /*输入商品信息*/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->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=(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("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; /*结束程序*/}。

Java课程设计超市库存管理系统附源代码可以直接运行

Java课程设计超市库存管理系统附源代码可以直接运行
p = new ImagePanel(new ImageIcon("E:/Java文件/SuperMarket/picture/1.jpg").getImage());
登录= new JButton("登录");
登录.addActionListener(this);
重置= new JButton("重置");
try{
Class.forName(dbdriver);
}
catch(ClassNotFoundException classnotfound){
System.out.println("未能找到SQLServerDriver,请检查是否已加载SQLServer驱动");
}
}
void init()
{
f = new Font("幼圆",Font.BOLD,18);
重置.addActionListener(this);
用户名= new JTextField(16);
用户名.setFont(f);
密码= new JPasswordField(16);
userName = new JLabel("用户名:");
userName.setFont(f);
psw = new JLabel("密码:");
String user = "sa";
String pass = "123";
public loginframe()
{
setLayout(new FlowLayout());
init();
setBounds(130,80,960,600);

超市管理系统源代码

超市管理系统源代码

第1章JavaBean部分1.1 数据库连接(DataBase.java)package common;import java.sql.*;import javax.naming.*;import javax.sql.*;import java.util.*;public class DataBase {private String dbUrl ="jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=ManagermentDB";private String dbUser = "ren";private String dbPwd = "ren";//定义数据库的连接public DataBase() throws Exception{Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");}//加载数据库的驱动public Connection getConnection()throws Exception{return java.sql.DriverManager.getConnection(dbUrl,dbUser,dbPwd);}//建立数据库的连接public void closeConnection(Connection con){try{if(con!=null) con.close();}catch(Exception e){e.printStackTrace();}}public void closePrepStmt(PreparedStatement prepStmt){try{if(prepStmt!=null) prepStmt.close();}catch(Exception e){e.printStackTrace();}}public void closeResultSet(ResultSet rs){//关闭当前记录集try{if(rs!=null) rs.close();}catch(Exception e){e.printStackTrace();}}public static void close( ResultSet rs, Statement st, Connection conn )//关闭数据库的连接{try{if( rs!=null ) rs.close();}catch( SQLException ex ) { };try{if( st!=null ) st.close();}catch( SQLException ex ) { };try{if( conn!=null ) conn.close(); }catch( SQLException ex ) { };}}1.2 人事管理部门1.2.1员工实体的定义(Employees.java)package employees;public class Employees implements Comparable{private String EmpId;private String DepId;private String EmpName;private String Sex;private String Nationality;private String Birth;private String Academic;private String Marital;private String Original;private String Id_Card;private String Mobile;private String Memo;//员工实体的属性Employees(String EmpId,String DepId,String EmpName ,String Sex,String Nationality,String Birth,String Academic,String Marital,String Original,String Id_Card,String Mobile,StringMemo){ //初始化操作this.EmpId = EmpId;this.DepId = DepId;this.EmpName = EmpName;this.Sex = Sex;this.Nationality = Nationality;this.Birth = Birth;this.Academic = Academic ;this.Marital = Marital;this.Original = Original;this.Id_Card = Id_Card;this.Mobile = Mobile ;this.Memo = Memo;}//对每一个属性赋值和取值操作public void setEmpId(String newEmpId){this.EmpId = newEmpId;}public String getEmpId(){return EmpId;}public void setDepId(String newDepId){this.DepId = newDepId;}public String getDepId(){return DepId;}public void setEmpName(String newEmpName){ this.EmpName = newEmpName;}public String getEmpName(){return EmpName;}public void setSex(String newSex){this.Sex = newSex;}public String getSex(){return Sex;}public void setNationality(String newNationality){ this.Nationality = newNationality;}public String getNationality(){return Nationality;}public void setBirth(String newBirth){this.Birth = newBirth;}public String getBirth(){return Birth;}public void setAcademic(String newAcademic){ this.Academic = newAcademic;}public String getAcademic(){return Academic;}public void setMarital(String newMarital){this.Marital = newMarital;}public String getMarital(){return Marital;}public void setOriginal(String newOriginal){this.Original = newOriginal;}public String getOriginal(){return Original;}public void setId_Card(String newId_Card){this.Id_Card = newId_Card;}public String getId_Card(){return Id_Card;}public void setMobile(String newMobile){this.Mobile = newMobile;}public String getMobile(){return Mobile;}public void setMemo(String newMemo){this.Memo = newMemo;}public String getMemo(){return Memo;}public int compareTo(Object o){Employees n = (Employees)o;int lastCmp = pareTo(n.EmpName);return(lastCmp);}}1.2.2员工实体的操作(EmployeesBean.java)package employees;import java.sql.*;import java.util.*;import javax.naming.*;import javax.sql.*;。

python超市管理代码

python超市管理代码

python超市管理代码下面是一个简单的 Python 超市管理代码示例,用于模拟超市商品的管理和销售:```python# 定义商品类class Product:def __init__(self, name, price): = nameself.price = pricedef __str__(self):return f"{}: {self.price} 元"# 定义超市类class Supermarket:def __init__(self):self.products = []def add_product(self, name, price):product = Product(name, price)self.products.append(product)def sell_product(self, name):for product in self.products:if == name:product.price -= 1 # 模拟销售商品,价格减 1return f"{name} 已售出"return f"商品 {name} 不存在"def get_products(self):return self.products# 创建超市对象supermarket = Supermarket()# 添加商品supermarket.add_product("苹果", 10)supermarket.add_product("香蕉", 8)supermarket.add_product("橙子", 12)# 销售商品print(supermarket.sell_product("苹果"))print(supermarket.sell_product("香蕉"))print(supermarket.sell_product("橙子"))print(supermarket.sell_product("西瓜")) # 不存在的商品# 获取所有商品print(supermarket.get_products())```上述代码定义了两个类:`Product` 类表示商品,包含商品名称和价格;`Supermarket` 类表示超市,包含商品列表。

超市管理系统设计代码

超市管理系统设计代码

import java.awt.*;import java.awt.event.*;import javax.swing.table.*;import javax.swing.event.*;import javax.swing.*;import java.sql.*;import java.util.*;import java.io.*;class Myframe1 extends JFrame //设置主界面{JFrame f=new JFrame();JLabel L1,L2;JButton btn1,btn2,btn3,btn4;public Myframe1(){f=new JFrame("主界面");L1=new JLabel("超市商品管理系统欢迎您");L1.setFont(new Font("TimesRoman",Font.BOLD,18));L2=new JLabel("您辛苦了~~~~");L2.setFont(new Font("TimesRoman",Font.BOLD,18));btn1=new JButton("进货管理系统");btn2=new JButton("售货管理系统");btn3=new JButton("商品信息管理");btn4=new JButton("管理系统帮助");Container container=this.getContentPane();container.setLayout(new GridLayout(9,3,0,50));for(int i=0;i<3;i++)container.add(new JLabel());container.add(new JLabel()); container.add(L1);container.add(new JLabel());container.add(new JLabel()); container.add(btn1);container.add(new JLabel());container.add(new JLabel()); container.add(btn2);container.add(new JLabel());container.add(new JLabel()); container.add(btn3);container.add(new JLabel());container.add(new JLabel()); container.add(btn4);container.add(new JLabel());container.add(new JLabel()); container.add(L2);container.add(new JLabel());container.setBackground(Color.cyan);f.add(container);f.setLocation(60,60);f.setSize(750,650);f.setVisible(true);Montior bn=new Montior();btn1.addActionListener(bn);btn2.addActionListener(bn);btn3.addActionListener(bn);btn4.addActionListener(bn);}class Montior implements ActionListener{public void actionPerformed(ActionEvent e1) {if(e1.getSource()==btn1){new Myframe2();}if(e1.getSource()==btn2){new Myframe3();}if(e1.getSource()==btn3){new Myframe4();}if(e1.getSource()==btn4){new bangzhu();}}}}class bangzhu extends JFrame{JTextPane ta=new JTextPane();JScrollPane sp=new JScrollPane(ta);public bangzhu(){super("管理系统帮助");ta.setFont(new Font("TimesRoaman",Font.BOLD+Font.PLAIN,20));ta.setText(" 1.初次进入登录系统,系统中没有售货员信息,可以进入系统但是为了以后能够使用方便\n"+" 还是增加售货员信息,以便下次登录。

python实现简单的超市商品销售管理系统

python实现简单的超市商品销售管理系统

python实现简单的超市商品销售管理系统本⽂实例为⼤家分享了python超市商品销售管理系统的具体代码,供⼤家参考,具体内容如下class Goods(object):def __init__(self, id, name, price):self.id = id = nameself.price = pricedef __str__(self):info = "编号:%s\t商品名称:%s\t\t价格:%d" % (self.id, , self.price)return infoclass ShopManager(object):def __init__(self, path):# path:表⽰读取⽂件的路径 shopdic:表⽰存放内存的容器self.path = pathself.shopdic = self.readFileToDic()def readFileToDic(self):# 读取⽂件,写⼊到字典中f = open(self.path, 'r', encoding='utf-8')clist = f.readlines()f.close()index = 0shopdic = {}while index < len(clist):# 将每⼀⾏的字符串进⾏分割,存放到新的列表中ctlist = clist[index].replace('\n', "").split("|")# 将每⾏的内容存放到⼀个对象中good = Goods(ctlist[0], ctlist[1], int(ctlist[2]))# 将对向存放到集合中shopdic[good.id] = goodindex = index + 1return shopdicdef writeContentFile(self):# 将内存当中的信息写⼊到⽂件当中str1 = ''for key in self.shopdic.keys():good = self.shopdic[key]ele = good.id + "|" + + "|" + str(good.price) + "\n"str1 = str1 + elef = open(self.path, 'w', encoding='utf-8')f.write(str1)f.close()def addGoods(self):# 添加商品的⽅法id = input("请输⼊添加商品编号:>")if self.shopdic.get(id):print("商品编号已存在,请重新选择!")returnname = input("请输⼊添加商品名称:>")price = int(input("请输⼊添加商品价格:>"))good = Goods(id, name, price)self.shopdic[id] = goodprint("添加成功!")def deleteGoods(self):# 删除商品的⽅法id = input("请输⼊删除商品编号:>")if self.shopdic.get(id):del self.shopdic[id]print("删除成功!")else:print("商品编号不存在!")def showGoods(self):# 展⽰所有商品信息print("=" * 40)for key in self.shopdic.keys():good = self.shopdic[key]print(good)print("=" * 40)def adminWork(self):info = """==========欢迎进⼊好海哦购物商场==========输⼊功能编号,您可以选择以下功能:输⼊“1”:显⽰商品的信息输⼊“2”:添加商品的信息输⼊“3”:删除商品的信息输⼊“4”:退出系统功能=========================================="""print(info)while True:code = input("请输⼊功能编号:>")if code == "1":self.showGoods()elif code == "2":self.addGoods()elif code == "3":self.deleteGoods()elif code == "4":print("感谢您的使⽤,正在退出系统!!")self.writeContentFile()breakelse:print("输⼊编号有误,请重新输⼊!!")def userWork(self):print(" ==============欢迎进⼊好海哦购物商场==============") print("您可输⼊编号和购买数量选购商品,输⼊编号为n则结账")self.showGoods()total = 0while True:id = input("请输⼊购买商品编号:>")if id == "n":print("本次购买商品共消费%d元,感谢您的光临!" % (total))breakif self.shopdic.get(id):good = self.shopdic[id]num = int(input("请输⼊购买数量:>"))total = total + good.price * numelse:print("输⼊商品编号有误,请核对后重新输⼊!")def login(self):# 登录功能print("==========欢迎登录好海哦购物商场==========")uname = input("请输⼊⽤户名:>")password = input("请输⼊密码:>")if uname == "admin":if password == "123456":print("欢迎您,admin管理员")self.adminWork()else:print("管理员密码错误,登录失败!")else:print("欢迎你,%s⽤户" % (uname))# 执⾏⽤户的购买功能erWork()if __name__ == '__main__':shopManage = ShopManager("shop.txt")shopManage.login()更多学习资料请关注专题《》。

  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
printf(" 1.商品信息的录入:\n");
printf(" 2.商品信息的查找:\n");
printf(" 3.插入新的物资信息:\n");
printf(" 4.统计销售量:\n");
printf(" 5.打印商品清单:\n");
printf(" 6.退出系统:\n");
printf(" ********************************************\n");
改程序一共有五个模块,不但可以进行超市信息的显示录入,查找,删除,更新,还能对货品的一些清单进行打印,操作界面简洁,操作简单。
程序用了指针、链表、数组、结构体等知识点,可运用于小的管理软件。软件运用菜单实现交互式管理,用户轻松的按键就可实现对软件的操作,方便超市管理。
设计思路
structMarketgoooБайду номын сангаасs
void search(); //商品数据信息查找函数
void insert(); //插入新的物资信息
int sum(); //规定日期内的销售量
void print(); //商品信息输出
int count=0; //全局变量,用于保存实际上有多少个商品
void main() //主函数
{
while(1)
{
char no[30]; /*商品的编号*/
char name[20]; /*商品的名称*/
float amount; /*库存数量*/
float price; /*商品价格*/
char kind; /*商品种类*/
struct import ko; /*进货的结构体*/
char place[50]; /*库存位置*/
流程图:
void input() //数据录入
{
char flag[20];
do{
printf("请输入你的商品信息:\n"); //录入商品的信息
printf("商品编号:");
scanf("%s",goods[count].no);
printf("商品名称:");
scanf("%s",goods[count].name);
printf("输入你的选择: ");
scanf("%d",&c); /*根据你的选择执行相应的函数*/
if(c==1)
input();
else if(c==2)
search();
else if(c==3)
insert();
else if(c==4)
sum();
else if(c==5)
print();
主函数:
#include "stdio.h" //需要的一些头文件
#include "stdlib.h"
#include "cstring"
#define COUNT 10000 //声明商品的种类为30中,你也可以修改
//函数声明
void start(); //启动界面
void input(); //商品数据信息输入函数
1.按商品名称进行查找
2.按商品的进货日期进行查找
3.按商品的规模进行查找
流程图:
void search() /*数据查找*/
{
int i,k;
char a[20];
struct date time1;
printf("please choose:1.按名称查找2.按进货日期查询3.按类别查找\n");
else if(c==6)
{ printf("你已经退出超市商品管理系统!\n");
exit(0);}
else
printf(" You Enter The Choice Is Not valid ! \n");
}
2.商品信息输入模块
通过对商品信息的录入来保存商品信息,从而方便以后商品的管理与其信息的更新。
1)按产品名称查询;
2)按进货日期查询并统计(统计某年某月进的某种产品的数量,产品的种类);
3)按产品名称和规模查询并统计;
4.新物资入库模块insert():在原数据文件中插入新物资信息。
5.打印功能模块print():
1)打印进货单
2)打印商品库存清单
课程设计目的
随着社会的逐步发展,超市在老百姓的生活中占据着重要的位置。然而琳琅满目的商品的管理也是一个大问题,在任何一个商店这都是不可忽视的问题,所以超市对商品的管理设计是很重要的,它可以在很大程度上帮助超市人员管理商品情况。
printf("是否继续输入数据y是n否: "); //是否还想继续输入数据
scanf("%s",flag);
}while(strcmp(flag,"y")==0||strcmp(flag,"Y")==0);
print(); //打印商品数据
}
3.数据查找模块
本模块可方便员工进行商品数据的查找与统计,且可便捷找到商品的库存位置,可按以下三种方式进行查找:
start();
}
1.启动界面
通过此界面超市员工可方便选择各种操作,灵活性较强。
流程图:
void start() /*启动菜单*/
{
int c;
printf("超市商品管理系统\n");
printf(" ********************************************\n");
}goods[count];
struct import
{
struct date time; /*进货日期的结构体*/
int jin; /*进货的数量*/
int sell-sum; /*销售总量*/
}ko[8000];
struct date
{
int year;
int month;
int day;
}time[8000];
设计报告
设计题目:超市商品管理系统
年级
班级
姓名
学号
起止时间6.10~~6.28
1.主菜单显示进入各模块程序
2.信息输入模块input():建立超市商品数据总文件,完成对超市商品信息的录入,并将其存放到指定文件(如:pro.dat)中。
3.信息查找模块search():采用如下方式进行查找,若找到,则输出该商品的相关信息;否则,输出提示信息(如:not found!)。
printf("商品总数目:");
scanf("%f",&goods[count].amount);
printf("商品价格:");
scanf("%f",&goods[count].price);
printf("商品位置:");
scanf("%s",goods[count].place);
count++; //存数的商品数加一
相关文档
最新文档