超市商品管理系统C语言源代码

合集下载

商品管理系统源代码

商品管理系统源代码

商品管理系统源代码中南大学本科生课程设计(实践)源代码(大学计算机基础)题目超市商品管理系统学生姓名指导教师学院专业班级学生学号计算机基础教学实验中心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; /结束程序/ }。

超市管理系统c++代码

超市管理系统c++代码

#include<iostream.h>#include<conio.h>#include<stdio.h>#include<process.h>#include<fstream.h>#include<string.h>#include<dos.h>class spbase{public:int t;float oprice;float iprice;float prof;int quantity;char name[10];void getdate();void showdate();void add();void search();void remove();int gett(){return t;};};void spbase::getdate() //输入函数的设计{ cout<<"\n\t\t请输入商品名称:";cin>>name;cout<<"\n\t\t请输入商品售价:";cin>>oprice;cout<<"\n\t\t请输入商品进价:";cin>>iprice;cout<<"\n\t\t请输入商品库存量:";cin>>quantity;}void spbase::showdate() //输出函数的设计{ cout<<"\n\n商品基本信息如下:";cout<<"\n\n\t\t商品名称:";cout<<name;cout<<"\n\n\t\t商品售价:";cout<<oprice;cout<<"\n\n\t\t商品进价:";cout<<iprice;cout<<"\n\n\t\t商品库存量:";cout<<quantity;prof=(oprice-iprice)*quantity;cout<<"\n\n\t\t商品利润为:";cout<<prof;}void spbase::add() //添加函数的设计{ t=1;ofstream file("HYY.txt",ios::out|ios::ate);if(!file){cout<<"文件打开失败!";getch();exit(1);}spbase p1;p1.getdate();file.write(reinterpret_cast<char*>(&p1),sizeof(spbase)); // reinterpret_cast强制转换file.close();}void spbase::search() //查询函数的设计{char name4[10];cout<<"\n请输入生活用品名称:";cin>>name4;fstream file("HYY.txt",ios::in);if (!file){cout<<"文件打开失败!";getch();exit(1);}char flag='a'; //设标志位spbase p1;file.read(reinterpret_cast<char*>(&p1),sizeof(spbase));while(!file.eof()) //正确显示,指针还没到末尾继续{ if((strcmp(,name4)==0)&&gett()){p1.showdate();getch();flag='z';break;}file.read(reinterpret_cast<char*>(&p1),sizeof(spbase));}if(flag!='z'){ cout<<("该商品已被删除!");getch();}file.close();}void spbase::remove() //删除函数的设计{ t=0;search();}class food:public spbase{ private:char pfs[10];public:void getdatef(){ spbase::getdate();cout<<"\n\t\t请输入商品批发商:";cin>>pfs;}void showdatef(){ spbase::showdate();cout<<"\n\n\t\t商品批发商:";cout<<pfs;}void addf(){ t=1;ofstream file("HYY1.txt",ios::out|ios::ate);if(!file){cout<<"文件打开失败!";getch();exit(1);}food f;f.getdatef();file.write(reinterpret_cast<char*>(&f),sizeof(food));file.close();}void searchf(){ char name1[10];cout<<"\n请输入食品名称:";cin>>name1;fstream file("HYY1.txt",ios::in);if (!file){cout<<"文件打开失败!";getch();exit(1);}char flag='a';food f;file.read(reinterpret_cast<char*>(&f),sizeof(food));while(!file.eof()){ if((strcmp(,name1)==0)&&gett()){f.showdatef();getch();flag='z';break;}file.read(reinterpret_cast<char*>(&f),sizeof(food));}if(flag!='z'){ cout<<("该商品已被删除!");getch();}file.close();}void removef(){ t=0;searchf();}};class makeup:public spbase{ private:char pp[10];public:void getdatem(){ spbase::getdate();cout<<"\n\t\t请输入商品品牌:";cin>>pp;}void showdatem(){ spbase::showdate();cout<<"\n\n\t\t商品品牌:";cout<<pp;}void addm(){ t=1;ofstream file("HYY2.txt",ios::out|ios::ate);if(!file){cout<<"文件打开失败!";getch();exit(1);}makeup m;m.getdatem();file.write(reinterpret_cast<char*>(&m),sizeof(makeup));file.close();}void searchm(){ char name2[10];cout<<"\n请输入化妆品名称:";cin>>name2;fstream file("HYY2.txt",ios::in);if (!file){cout<<"文件打开失败!";getch();exit(1);}char flag='a';makeup m;file.read(reinterpret_cast<char*>(&m),sizeof(makeup));while(!file.eof()){ if((strcmp(,name2)==0)){m.showdatem();getch();flag='z';break;}file.read(reinterpret_cast<char*>(&m),sizeof(makeup));}if(flag!='z'){ cout<<("该商品已被删除!");getch();}file.close();}void removem(){ t=0;searchm();}};class drink:public spbase{ private:char factory[10];public:void getdated(){ spbase::getdate();cout<<"\n\t\t请输入商品生产厂家:";cin>>factory;}void showdated(){ spbase::showdate();cout<<"\n\n\t\t商品生产厂家:";cout<<factory;}void addd(){ t=1;ofstream file("HYY3.txt",ios::out|ios::ate);if(!file){cout<<"文件打开失败!";getch();exit(1);}drink d;d.getdated();file.write(reinterpret_cast<char*>(&d),sizeof(drink)); file.close();}void searchd(){ char name3[10];cout<<"\n请输入饮料名称:";cin>>name3;fstream file("HYY3.txt",ios::in);if (!file){cout<<"文件打开失败!";getch();exit(1);}char flag='a';drink d;file.read(reinterpret_cast<char*>(&d),sizeof(drink)); while(!file.eof()){ if((strcmp(,name3)==0)){d.showdated();getch();flag='z';break;}file.read(reinterpret_cast<char*>(&d),sizeof(drink)); }if(flag!='z'){ cout<<("该商品已被删除!");getch();}file.close();}void removed(){ t=0;searchd();}};class live:public spbase{public:void getdatel(){ spbase::getdate();}void showdatel(){ spbase::showdate();}void addl(){ spbase::add();}void searchl(){ spbase::search();}void removel(){spbase::remove();}};void main(){ system("cls");cout<<"\n\n\n\n\t\t********************************************\n"<<"\t\t* *\n"<<"\t\t* *\n"<<"\t\t* 欢迎使用小型超市商品销售管理系统(HYY) *\n"<<"\t\t* *\n"<<"\t\t* Desined by 韩永扬206050529 *\n"<<"\t\t* *\n"<<"\t\t* (按任意键进入) *\n"<<"\t\t* *\n"<<"\t\t* *\n"<<"\t\t********************************************\n"<<endl;getch();food f;makeup m;drink d;live l;while(1){A:system("cls");int choice;int x;cout<<"\n\n\t\t\t\t主菜单"<<"\n\n\t\t\t\t(1)添加商品品种\n" <<"\n\t\t\t\t(2)查询商品\n"<<"\n\t\t\t\t(3)删除商品"<<"\n\n\t\t\t\t(4)退出"<<"\n\n\n请选择:";cin>>x;switch(x){ case 1:{system("cls");cout<<"\n\n\n\n\n\n\t\t请选择添加哪一类:"<<"\n\n\t\t\t\t(1)食品类"<<"\n\t\t\t\t(2)化妆品类"<<"\n\t\t\t\t(3)饮料类"<<"\n\t\t\t\t(4)生活用品类"<<"\n\t\t\t\t(5)返回"<<endl;cin>>choice;switch(choice){case 1:system("cls");f.addf();break;case 2:system("cls");m.addm();break;case 3:system("cls");d.addd();break;case 4:system("cls");l.addl();break;case 5:system("cls");break;}break;}case 2:{system("cls");cout<<"\n\n\n\n\n\n\t\t请选择查询哪一类:"<<"\n\n\t\t\t\t(1)食品类"<<"\n\t\t\t\t(2)化妆品类"<<"\n\t\t\t\t(3)饮料类"<<"\n\t\t\t\t(4)生活用品类"<<"\n\t\t\t\t (5)返回"<<endl;cin>>choice;switch(choice){case 1:system("cls");f.searchf();break;case 2:system("cls");m.searchm();break;case 3:system("cls");d.searchd();break;case 4:system("cls");l.searchl();break;case 5:break;}break;}case 3:{system("cls");cout<<"\n\n\n\n\n\n\t\t请选择删除哪一类:"<<"\n\n\t\t\t\t(1)食品类"<<"\n\t\t\t\t(2)化妆品类"<<"\n\t\t\t\t(3)饮料类"<<"\n\t\t\t\t(4)生活用品类"<<"\n\t\t\t\t (5)返回"<<endl;cin>>choice;switch(choice){ case 1:system("cls");f.removef();break;case 2:system("cls");m.removem();break;case 3:system("cls");d.removed();break;case 4:system("cls");l.removel();break;case 5:system("cls");break;}break;}case 4:cout<<"\n\n\n\n\n\n\t\t\t\t谢谢使用!"<<"\n\n\t\t\t\t再见!\n";exit(1);}break;default:{cout<<"输入有误,请重选!";goto A;}}}}。

C语言 超市收银系统

C语言 超市收银系统

/*—-——-———-—-—-———-——--——--—--———-—--—-——时间:2015—7—1 16:44:21吴俊龙C语言专周设计超市收银系统--————--——-—---—-——-———-————---—--—-—--*/#include 〈stdio.h>#include <windows。

h〉#include 〈string。

h>int menu1(void);//主页面int menu2(void);//商品管理页面int menu3(void);//退出页面int menu4(void);//添加商品信息int menu5(void);//商品信息浏览int menu6(void);//商品信息修改int menu7(void);//商品信息查询int menu8(void);//商品信息删除int menu9(void);//结账页面int sign(void);//欢迎页面struct ima{int id;//商品编号char name[20];//商品的名称char produce[30]; //商品的产地int number; //商品的数量int money; //商品的价格};int len = 0;struct ima thing[50];struct ima *p;int menu1(void)//主页面{int n;system("cls");printf(”\n\n\n");printf(”\t\t —--—-------——-—-—-—--————--—-———-—-—---—— \n");printf(”\t\t| 欢迎使用结账管理系统|\n”);printf("\t\t|---—-—-—--—-—---—————------—--—----———---|\n");printf(”\t\t| |\n");printf("\t\t| 1。

用c语言编写商品管理系统

用c语言编写商品管理系统

用c语言编写商品管理系统-标准化文件发布号:(9456-EUATWK-MWUB-WUNN-INNUL-DDQTY-KII#include<stdio.h>#include<stdlib.h>#include<conio.h>#include<dos.h>#include<string.h>#define LEN sizeof(struct commdity)#define FORMAT "%-8d%-15s%-12.11f%-12.11f%-12.11f\n"#define DATA comm[i].num,comm[i].name,comm[i].price,comm[i].count,comm[i].total /*定义商品的结构体*/struct commdity{int num;char name[15];double count;double total;}comm[100000],t;/*函数的声明*/void in(); /*商品录入并保存*/void show(); /*显示商品记录*/void order(); /*商品记录排序*/void del(); /*商品记录删除*/void modify(); /*商品记录修改*/void menu(); /*主菜单*/void insert(); /*商品记录插入*/void total(); /*商品统计*/void search(); /*查看商品记录*/void main(){int n;menu();scanf("%d",&n);while(n){switch(n){case 0:break;case 1:in();break;case 2:search();break;case 3:del();break;case 4:modify();break;case 5:insert();break;case 6:order();break;case 7:total();break;default:printf("error! 操作错误.....\n");break;}getch();menu();scanf("%d",&n);}}/**************************自定义主菜单函数************************/ void menu(){system("cls"); /*清屏*/printf("\n\n\n\n\n");printf("\t\t--------欢迎将进入商品管理系统----------------\n");printf("\t\t|\t0.退出 |\n");printf("\t\t|\t1.录入记录 |\n");printf("\t\t|\t2.查找记录 |\n");printf("\t\t|\t3.删除记录 |\n");printf("\t\t|\t4.修改记录 |\n");printf("\t\t|\t5.插入记录 |\n");printf("\t\t|\t6.排序记录 |\n");printf("\t\t|\t7.统计记录 |\n");printf("\t\t|--------------------------------------------|\n");printf("\t\t\t请输入您的操作类型【0-7】: \n");}/**************************自定义商品录入并保存函数************************/void in(){int i,m=0;char ch[2];FILE *fp;if((fp=fopen("data.txt","ab+"))==NULL){ printf("不能打开文件!\n");return; }while(!feof(fp)){if(fread(&comm[m],LEN,1,fp)==1)m++;}fclose(fp);if(m==0)printf("无商品记录........\n");else{ system("cls");show();}if((fp=fopen("data.txt","wb"))==NULL){ printf("不能打开文件!\n");return;}for(i=0;i<m;i++)fwrite(&comm[i],LEN,1,fp);printf("是否输入(y/n):\n");scanf("%s",ch);while(strcmp(ch,"Y")==0||strcmp(ch,"y")==0){ printf("编号:\n");scanf("%d",&comm[m].num);for(i=0;i<m;i++)if(comm[m].num==comm[i].num){ printf("该记录已经存在,按任意键返回......\n"); getch();fclose(fp);return;}printf("商品名:\n");scanf("%s",comm[m].name);printf("单价:\n");scanf("%lf",&comm[m].price);printf("数量:\n");scanf("%lf",&comm[m].num);comm[m].total=comm[m].count*comm[m].price;if(fwrite(&comm[m],LEN,1,fp)!=1){ printf("不能保存!\n");getch();return;}else{ printf("%s 已经保存!\n",comm[m].name);m++;printf("是否继续(y/n):\n");scanf("%s",ch);}fclose(fp);printf("OK!\n");return;}/**************************自定义显示商品记录函数************************/void show(){int i,m=0;FILE *fp;if((fp=fopen("data.txt","ab+"))==NULL){printf("不能打开记录!\n");return;}while(!feof(fp)){if(fread(&comm[m],LEN,1,fp)==1)m++;}fclose(fp);if(m==0){printf("无商品记录........\n");}else{printf("编号商品名称单价数量总金额\t\n");for(i=0;i<m;i++){printf(FORMAT,DATA);}}}/**************************自定义商品查看函数************************/ void search(){ FILE *fp;int snum,i,m=0;char ch[2];if((fp=fopen("data.txt","ab+"))==NULL){printf("不能打开文件!\n");return;}while(!feof(fp)){if(fread(&comm[m],LEN,1,fp)==1)fclose(fp);if(m==0){ printf("无商品记录........\n");return;}printf("编号:\n");scanf("%d",&snum);for(i=0;i<m;i++)if(snum==comm[i].num){printf("已经找到记录,是否显示(y/n):\n");scanf("%s",ch);if(strcmp(ch,"Y")==0||strcmp(ch,"y")==0){printf("编号商品名称单价数量总金额\t\n"); printf(FORMAT,DATA);break;}elsereturn;}if(i==m){printf("没有找到相应的记录....\n");}}/**************************自定义商品记录删除函数************************/void del(){int i,m=0,j,snum;char ch[2];FILE *fp;if((fp=fopen("data.txt","ab+"))==NULL){printf("不能打开文件!\n");return;}while(!feof(fp)){if(fread(&comm[m],LEN,1,fp)==1)m++;}fclose(fp);if(m==0){printf("无商品记录........\n");return;}printf("请输入编号:\n");scanf("%d",&snum);for(i=0;i<m;i++)if(snum==comm[i].num)break;if(i==m){printf("没有找到.....\n");getch();return;}printf("已经找到记录,是否删除(y/n):\n");scanf("%s",ch);if(strcmp(ch,"Y")==0||strcmp(ch,"y")==0){for(j=i;j<m;j++)comm[j]=comm[j+1];m--;printf("删除成功....\n");}if((fp=fopen("data.txt","wb"))==NULL){printf("不能打开文件!\n");return;}for(i=0;i<m;i++)if(fwrite(&comm[j],LEN,1,fp)!=1){printf("不能保存!\n");getch();}fclose(fp);}/**************************自定义商品记录修改函数************************/void modify(){int i,m=0,snum;char ch[2];FILE *fp;if((fp=fopen("data.txt","ab+"))==NULL){printf("不能打开文件!\n");return;}while(!feof(fp)){if(fread(&comm[m],LEN,1,fp)==1)m++;}fclose(fp);if(m==0){printf("无商品记录........\n");fclose(fp);return;}printf("请输入您要修改信息的编号:\n");scanf("%d",&snum);for(i=0;i<m;i++)if(snum==comm[i].num)break;if(i<m){printf("已经找到该记录,是否修改(y/n):\n");scanf("%s",ch);if(strcmp(ch,"Y")==0||strcmp(ch,"y")==0){printf("商品名:\n");scanf("%s",comm[i].name);printf("单价:\n");scanf("%lf",&comm[i].price);printf("数量:\n");scanf("%lf",&comm[i].num);comm[i].total=comm[i].count*comm[i].price;}elsereturn;}else{printf("没有找到......\n");getchar();return;}if((fp=fopen("data.txt","wb"))==NULL){printf("不能打开文件!\n");return;}for(i=0;i<m;i++)if(fwrite(&comm[i],LEN,1,fp)!=1){printf("不能保存!\n");getch();}fclose(fp);}/**************************自定义商品记录插入函数************************/void insert(){int i,m=0,j,k,snum;FILE *fp;if((fp=fopen("data.txt","ab+"))==NULL){printf("不能打开文件!\n");return;}while(!feof(fp)){if(fread(&comm[m],LEN,1,fp)==1)m++;}if(m==0){printf("无商品记录........\n");fclose(fp);return;}printf("请输入要插入记录的位置【即编号】:\n");scanf("%d",&snum);for(i=0;i<m;i++)if(snum==comm[i].num)break;for(j=m-1;j>i;j--)comm[j+1]=comm[j];printf("请输入您要插入的信息:\n");printf("编号:\n");scanf("%d",&comm[i+1].num);for(k=0;k<m;k++)if(comm[k].num==comm[i+1].num&&k!=i+1){ printf("该编号已经存在,按任意键继续......\n"); getch();fclose(fp);return;}printf("商品名:\n");scanf("%s",comm[i+1].name);printf("单价:\n");scanf("%lf",&comm[i+1].price);printf("数量:\n");scanf("%lf",&comm[i+1].num);comm[i+1].total=comm[i+1].count*comm[i+1].price;if((fp=fopen("data.txt","wb"))==NULL){printf("不能打开文件!\n");return;}for(k=0;k<m+1;k++)if(fwrite(&comm[k],LEN,1,fp)!=1){printf("不能保存!\n");getch();}fclose(fp);}/**************************自定义商品记录统计函数************************/void total(){int i,m=0;FILE *fp;if((fp=fopen("data.txt","ab+"))==NULL){printf("不能打开记录!\n");return;}while(!feof(fp)){if(fread(&comm[m],LEN,1,fp)==1)m++;}if(m==0){printf("无商品记录........\n");fclose(fp);}else{printf("编号商品名称单价数量\t\n");for(i=0;i<m;i++){printf("%-8d%-15s%-12.11f%-12.11f\n",comm[i].num,comm[i].name,comm[i].price,comm[i].count);} printf("一共有%d条记录!\n",m);fclose(fp);}}/**************************自定义商品记录排序函数************************/void order(){int i,j,m=0;FILE *fp;if((fp=fopen("data.txt","ab+"))==NULL){printf("不能打开记录!\n");return;}while(!feof(fp)){if(fread(&comm[m],LEN,1,fp)==1)m++;}fclose(fp);if(m==0){printf("无商品记录........\n");}else{for(i=0;i<m;i++)for(j=i+1;j<m;j++){if(comm[i].total<comm[j].total){t=comm[i];comm[i]=comm[j];comm[j]=t;}}printf("编号商品名称单价数量总金额\t\n");for(i=0;i<m;i++){printf(FORMAT,DATA);}}}11。

C++超市管理系统代码文档

C++超市管理系统代码文档

C++超市管理系统代码文档#include〈stdlib.h〉#include<time。

h〉srand((unsigned)time(NULL));while(i〈5){arr。

a[i++]=rand()%5;arr.length++;}cin〉>cn;switch(cn){case 0: exit;case 1: mpsort(int a[Max]);diaplay();break; case 2: xzsort(int a[Max]);diaplay();break; default : cout<〈"error”<<endl;}#include<iostream。

h>const int Max=5;class Array{int a[Max];int last;public:void init();void mpSort();void xzSort(); }void Array::Init(){int i=0,t;last=0;cout〈<”请输入一个数组"<〈endl;while((cin〉〉t)&&i〈Max){a[i]=t;i++;last++;}}void Swap(int &x,int &y){int z;z=x;x=y;y=z;}void Array::mpSort() {int i,j;cout<〈”您调用的是冒泡排序法"〈<endl; for(i=0;i<last-1;i++)for(j=0;j〈last—i;j++)if(a[j]〉a[j+1])swap(a[j],a[j+1]); }void Array::xzSort() {int i,j,k;cout〈<”您调用的是选择排序法"<〈endl;for(i=0;i〈last-1;i++){k=i;for(j=i+1;j〈last—1;j++)if(a[j]<a[i])k=j;Swap(a[i],a[k]);}}void Array::diaplay(){int i;cout〈<"当前数组中的元素是:”<〈endl;for(i=0;i<last;i++)cout〈〈a[i]〈〈endl;}int menu_select() {int cn;char s;cout〈<"欢迎使用趣味菜单,请选择您要处理问题的方法"<〈endl; cout<〈”0. 退出"〈〈endl;cout<<”1. 用冒泡排序法进行排序”〈〈endl;cout〈<"2. 用选择排序法进行排序”<<endl; cout<〈"请输入0,,2"<〈endl;do{s=getchar();cn=(int)s-48;}while(cn〈-1||cn>2);return cn;}void main(){Array b;b.init();b。

超市商品信息管理系统源代码

超市商品信息管理系统源代码
t1=glist[i].num;
t2=glist[j].num;
break;
case 2:
t1=glist[i].price;
t2=glist[j].price;
break;
case 3:
t1=glist[i].stock;
}
printf("排序后\n");
output(glist,len);
}
}
int search(GOODS glist[],int len,int search_num)
{
int i=len-1;
while(i>=0&&(glist[i].num!=search_num))
i--;
return i; //返回找到的数组下标
}
void edit(GOODS glist[],int len,int edit_num)
{
int ss;
ss=search(glist,len,edit_num);
if(ss==-1)
printf("查无此商品\n");
}
return i;
}
void output(GOODS glist[],int len)
{
int i;
for(i=0;i<len;i++)
printf("商品号=%-5d 商品名称=%-5s 商品价格=%-5.2f元 商品库存量=%-5d件\n",glist[i].num,glist[i].name,glist[i].price,glist[i].stock);

C语言大作业-超市货物管理系统

C语言大作业-超市货物管理系统

//预防闪屏
return 0;
}
for(i=0;i<n;i++)
if(gds[i].ave!=0)
//在后面的 del()函数中通过将 gds[i].ave=0 来
表示该记录被删除了
if(fwrite(&gds[i],sizeof(struct goods),1,fp)!=1)//开始写入文件
printf("文件写入发生错误\n");
gds[i].ave=( gds[i].MJ+ gds[i].JJ)/2;
}
/*******【编号长度处理函数】********/
void lenbian(int i)
{
int j,l,a;
l=strlen(gds[i].BH);
if(l<LEN)
{
for(j=LEN-l,a=0;j<LEN;j++)
case 2:printf("姓名:");scanf("%s",gds[i].MZ);break;
case 3:printf("进价:");scanf("%f",&gds[i].JJ);break;
case 4:printf("卖价:");scanf("%f",&gds[i].MJ);break;
case 5:rishuru(i);break;
//i 表示第 i 个货物信息,n 表示比较到第
n 个货物
{
int j,k,w1;
do{
w1=0;
printf(" 编 号 :\t\t 【 %d 位 , 低 于 %d 位 前 面 补 0, 长 的 截 尾 处 理 ! 】

C语言程序设计超市管理系统1

C语言程序设计超市管理系统1

程序设计——超市管理系统学院:专业:班级:姓名:学号:指导老师:超市管理系统课程设计1)需求分析:设计题目:超市管理系统设计要求:有一个小型超市,出售N(N>=10)种商品,设计并实现一个系统系统功能需求分析:1.保存及输出:超市中的各种商品信息保存在指定文件中,可以把它们输出显示。

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

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

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

2)概要设计:系统总体设计框架:系统功能模块图:3)详细设计:主要功能模块的算法设计思路:本程序主要分为八个模块:主模块、信息输出修改模块、新建信息模块、排序模块、计算模块、统计模块1、统计模块2、打印模块。

1)主模块:通过调用各分模块实现功能;2)信息输出修改模块:输出显示文件中商品信息内容,添加商品信息,删除商品信息,修改商品信息;3)新建商品信息模块:建立一个新结构体,为链表存信息用,并且将信息保存在指定的文件中;4)排序模块:把文件中顺序零乱的商品信息按单价的大小从高到低进行排序,放到链表里存储;5)计算模块:将所有商品的价格与库存量进行累加求和;6)打印模块:将商品信息按每类平均价格排序(从高到低)按顺序打印出来;7)统计模块1:统计库存量低于100的货名及类别;8)统计模块2:统计商品库存量有2种以上(含2种)低于100的商品类别工作流程图:4)主要源程序代码:#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->u nit,&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->qua ntity); /*输入商品信息*/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->pr ice,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->pr ice,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->pr ice,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; /*结束程序*/}5)调试分析过程描述:测试数据:01 milk drink 2.5 box 502 apple fruit 3 kilo 2测试输出结果:存在问题的思考:源代码出错,漏了一些分号导致程序频频出错,在进行编写时注意小地方别出错!否则会影响大局!6)总结:学习体会与收获:通过这个超市管理系统程序设计实验,我从理论知识跨越到实践上,感到收效良多,从崇拜计算机到学会控制计算机,在心理上不再觉得计算机是万能的,人的大脑才是万能的,算法才是万能的数学才是万能的,在这次实验中,实现一个完整的程序大大加深了我对C语言课程的兴趣!对C语言课程设计的认识以及自己的建议:C语言课程设计就是通过编译实现需要的功能的一种程序的设计,建议自己以后在这方面多下功夫,真正实现自己编译以个完整的C程序,实现自己的梦想和未来!如有侵权请联系告知删除,感谢你们的配合!。

用c语言编写商品管理信息系统

用c语言编写商品管理信息系统

商品管理信息系统#include "stdio.h"#include "string.h"#define NAME_MAX_LEN 20#define Prod_MAX_NUM 50typedef struct{int num;char name[NAME_MAX_LEN];double unitprice;int amount;double totalprice;}prodNode;typedef struct sequence{prodNode data[Prod_MAX_NUM];int len;}seq;seq product;void inputGoods(){int i,n;printf("请输入商品个数:\n");scanf("%d",&n);if (n<0)return;for (i=0;i<n;i++){printf("请输入第%d个商品记录。

\n",i+1);printf("输入商品的编号:\n");scanf("%d",&product.data[i].num);printf("输入商品的名字:\n");scanf("%s",product.data[i].name);printf("输入商品的单价:\n");scanf("%lf",&product.data[i].unitprice);printf("输入商品的数量:\n");scanf("%d",&product.data[i].amount);product.data[i].totalprice=product.data[i].unitprice*product.data[i].amount;}product.len=n;}void outputGoods()int i;if (product.len==0){printf("\n无数据!\n");return;}printf("\n商品的记录为:\n");printf("编号\t名字\t单价\t数量\t总价\n");for (i=0;i<product.len;i++){printf("%d\t%s\t%lf\t%d\t%.2lf",product.data[i].num,product.data[i].name,product.data[i].unitpric e,product.data[i].amount,product.data[i].totalprice);printf("\n");}}void saveGoods(){int i;FILE *fp;if (product.len==0){printf("\n无数据!\n");return;}fp=fopen("d:\\商品管理信息系统\\goods.txt","w");if (fp==NULL){printf("文件打开失败!\n");return;}for (i=0;i<product.len;i++){ fprintf(fp,"\n");fprintf(fp,"%d\t",product.data[i].num);fprintf(fp,"%s\t",product.data[i].name);fprintf(fp,"%lf\t",product.data[i].unitprice);fprintf(fp,"%d\t",product.data[i].amount);fprintf(fp,"%.2lf",product.data[i].totalprice);}fclose(fp);printf("已成功存盘!\n");void readGoods(){int i;FILE *fp;fp=fopen("d:\\商品管理信息系统\\goods.txt","r");if (fp==NULL){printf("文件打开失败!\n");return;}i=0;while (!feof(fp)){fscanf(fp,"%d",&product.data[i].num);fscanf(fp,"%s",product.data[i].name);fscanf(fp,"%lf",&product.data[i].unitprice);fscanf(fp,"%d",&product.data[i].amount);fscanf(fp,"%lf",&product.data[i].totalprice);i++;}product.len=i;fclose(fp);printf("已从文件成功读取%d条成绩记录!\n",product.len); }void insertOneGoods(){prodNode G;int i,pos;if (product.len==Prod_MAX_NUM){printf("表已满!\n");return;}printf("请输入插入位置:");scanf("%d",&pos);if (pos<0||pos>product.len){ printf("插入位置出错!\n");return;}printf("请输入要插入的商品记录:\n");printf("请输入编号:");do {scanf("%d",&G.num);if (G.num<=0)printf("输入的编号不合理,请重新输入。

C语言实现超市管理系统

C语言实现超市管理系统

C语⾔实现超市管理系统本⽂实例为⼤家分享了C语⾔实现超市管理系统的具体代码,供⼤家参考,具体内容如下超市管理系统1.包括管理员和顾客2.管理员有登⼊,录⼊商品信息,显⽰所有商品信息功能3.顾客有购物车和结算功能4.购物车具有显⽰商品列表,显⽰购物车商品,往购物车添加商品的功能函数void UpdateKu();//更新购物车信息函数void calculate();//计算所购商品价格并修改保存int menu1();//打印主菜单函数int menu2();//打印管理员菜单函数int menu3();//打印顾客函数void CreateGoods();//录⼊商品信息函数void ShowGoods();//显⽰库存信息函数void ShopCart();//对购物车进⾏操作int ShopCartMenu();//打印购物车菜单void ShowCart();//显⽰购物列表void add();//在购物车⾥添加商品建⽴库存函数void CreateGoods(){//⼿动建⽴库存信息FILE *fp;//定义⽂件指针int i;printf("请输⼊需要录⼊的商品个数:\n");scanf("%d",&n);//输⼊数量printf("请依次输⼊货物信息:\n");printf("--------------------------------------------\n");for(i=0;i<n;i++){//向⽂件中写⼊信息printf("第%d个商品:\n",i+1);printf("货号:");fflush(stdin);//清空输⼊流gets(goods[i].ID);//输⼊货号printf("品名:");fflush(stdin);//清空输⼊流gets(goods[i].brand);//输⼊品名printf("进价: ");fflush(stdin);//清空输⼊流scanf("%lf",&goods[i].inprice);//输⼊进价printf("售价:");fflush(stdin);//清空输⼊流scanf("%lf",&goods[i].outprice);//输⼊售价printf("数量:");fflush(stdin);//清空输⼊流scanf("%d",&goods[i].storage);//输⼊数量printf("保质期:");fflush(stdin);//清空输⼊流gets(goods[i].date);//输⼊货号printf("\n");}if((fp=fopen("kucun.txt","w"))==NULL){//判断⽂件是否创建失败printf("创建⽂件失败。

超市商品管理系统C语言版(文件读取)

超市商品管理系统C语言版(文件读取)

超市商品管理系统C语言版(文件读取)#include#include#include//------------------------------------------------------------- //Max count of good,def 100 temporary//------------------------------------------------------------- #define MAX 100#define false -1#define true 1//声明一个计数器int CurrentCnt;//------------------------------------------------------------- //Good Information Definition//------------------------------------------------------------- struct GoodInfo {char good_id[30];char good_name[30];char good_price[10];char good_discount[10];int good_amount;int good_remain;};struct GoodInfo *Goods[MAX];//------------------------------------------------------------- //read a goodinfo from file//------------------------------------------------------------- struct GoodInfo *readGoodInfo(FILE* fp){struct GoodInfo *pGoodInfo = (struct GoodInfo*)malloc(sizeof(struct GoodInfo));//开辟空间fscanf(fp,"%s",&pGoodInfo->good_id);fscanf(fp,"\t%s",&pGoodInfo->good_name);fscanf(fp,"\t%s",&pGoodInfo->good_price);fscanf(fp,"\t%s",&pGoodInfo->good_discount);fscanf(fp,"\t%d",&pGoodInfo->good_amount);fscanf(fp,"\t%d\n",&pGoodInfo->good_remain);//将信息存入结构return pGoodInfo;}//-------------------------------------------------------------//check whether the file exists or not//-------------------------------------------------------------int check_nullfile(){FILE *fp = fopen("E:\\goodinfo.txt","r");//file not existif(!fp){printf("商品信息初始化文件不存在!\n请您放到E盘根目录!\n");FILE *fp = fopen("E:\goodinfo.txt","w");fclose(fp);}//file already existelse{int temp;//res for try to read file if file null feof() can't jarge if file is nullint res = fscanf(fp,"%d",&temp);fclose(fp);if(res<=0){printf("文件为空,请确保文件中存有商品信息\n");return false;}elsereturn true;}}//------------------------------------------------------------- //initialize//------------------------------------------------------------- void info_init(){int i;for(i=0; i<="" p="">Goods[i] = NULL;}int res = check_nullfile();FILE *fp = fopen("E:\\goodinfo.txt","r");int j = 0;while( res && !feof(fp) ){Goods[j] = readGoodInfo(fp);j++;CurrentCnt++;}fclose(fp);}//------------------------------------------------------------- // search a goodinfoint info_search(){int i;char name[30];scanf("%s",&name);for(i=0;i<="">{if(Goods[i]==NULL)//跳过已被释放内存的空指针i++;if(strcmp(name,Goods[i]->good_name)==0)//若商品名与输入相同则返回下标return i;}if(i==CurrentCnt)//未找到商品return false;}//-------------------------------------------------------------//modify a goodinfo//-------------------------------------------------------------void info_change(int i){printf("输入新的商品信息(以换行区分信息条目):\n");scanf("%s",&Goods[i]->good_id);scanf("%s",&Goods[i]->good_name);scanf("%s",&Goods[i]->good_price);scanf("%s",&Goods[i]->good_discount);scanf("%d",&Goods[i]->good_amount);scanf("%d",&Goods[i]->good_remain);printf("修改商品信息成功!\n");}//delete a goodinfo//-------------------------------------------------------------void info_dele(int i){if(i!=false){free(Goods[i]);//释放空间Goods[i]=NULL;//指向空指针}printf("删除商品信息成功!\n");}//-------------------------------------------------------------//output//-------------------------------------------------------------void info_output(int i){printf("目前商品信息:\n");printf("商品id:%s商品名称:%s商品价格:%s\n",Goods[i]->good_id,Goods[i]->good_name,Goods[i]->g ood_price);printf("商品折扣:%s商品数量:%d商品余数:%d\n",Goods[i]->good_discount,Goods[i]->good_amount,Go ods[i]->good_remain);}//-------------------------------------------------------------//insert one goodinfo//-------------------------------------------------------------void info_insert(){ //开辟空间struct GoodInfo *newgoods=(struct GoodInfo*)malloc(sizeof(struct GoodInfo));scanf("%s",&newgoods->good_id);scanf("\n%s",&newgoods->good_name);scanf("\n%s",&newgoods->good_price);scanf("\n%s",&newgoods->good_discount);scanf("\n%d",&newgoods->good_amount);scanf("\n%d",&newgoods->good_remain);Goods[CurrentCnt]=newgoods;CurrentCnt++;printf("商品信息插入完成!\n");}//-------------------------------------------------------------//write one goodinfo into file//-------------------------------------------------------------void writeGoodInfo(FILE* fp,struct GoodInfo* pGoodInfo) { fprintf(fp,"%s\t",pGoodInfo->good_id);fprintf(fp,"%s\t",pGoodInfo->good_name);fprintf(fp,"%s\t",pGoodInfo->good_price);fprintf(fp,"%s\t",pGoodInfo->good_discount);fprintf(fp,"%d\t",pGoodInfo->good_amount);fprintf(fp,"%d\n",pGoodInfo->good_remain);}//-------------------------------------------------------------//write all goodinfos into file//-------------------------------------------------------------void info_flush(){int i;FILE *fp = fopen("E:\\goodinfo.txt","w");for(i=0; i<="" p="">if(Goods[i])writeGoodInfo(fp,Goods[i]);}fclose(fp);}//------------------------------------------------------------- //free goodinfo memory//------------------------------------------------------------- void freeGoodInfo(){int i;for(i=0;i<currentcnt;i++)< p="">free(Goods[i]);}//------------------------------------------------------------- //main entry//------------------------------------------------------------- int main(){int i;int choice;char name[30];info_init();for(;;){printf("超市商品管理系统\n""*****************************************\n""1.商品信息的修改:\n""2.删除某个商品信息:\n""3.查找商品信息:\n""4.插入某个商品信息\n""其他数字,退出系统\n""****************************************\n" "请输入您的选择:");scanf("%d",&choice);switch(choice){case 1:printf("输入您要修改的商品名称:");i=info_search();if(i!=false)info_change(i);elseprintf("您要修改的商品不存在\n"); break;case 2:printf("输入您要删除的商品名称:");i=info_search();if(i!=false)info_dele(i);elseprintf("您要删除的商品不存在\n"); break;case 3:printf("输入你要查询的商品名称:");i=info_search();if(i!=false)info_output(i);elseprintf("您要查询的商品不存在\n"); break;case 4:printf("输入你要插入的商品信息(以换行区分信息条目):\n"); info_insert();break;default:break;}if(choice!=1&&choice!=2&&choice!=3&&choice!=4) break;}info_flush();//存盘freeGoodInfo();//释放内存return 0;}</currentcnt;i++)<>。

超市管理系统源程序

超市管理系统源程序

超市管理系统源程序#include <stdio.h>#include <string.h>#define MAX 20#define N 3#define PAGE 2#define PRINT1 printf("---------------------\n")#define PRINT2 printf("商品号--商品名称--商品种类--销售价格--生产日期(年-月-日)--保质期\n")#define PRINT3 printf("%4d%s%s%8d%15%-%2d-%2d%10d\n",goods[i].num,goods [i].name,goods[i].kind,goods[i].out_price,goods[i].pro_t ime.year,goods[i].pro_time.month,goods[i].pro_time.date, goods[i].save_day)int sum;/*记录商品数目*/struct date /*日期结构体类型*/{int year;int month;int date;}struct goods_type /*商品结构体类型*/{int sum;char name[10];char kind[10];int amount;int goods_up;int goods_down;int in_price;int out_price;int in_num;struct date in_time;struct date pro_time;char factory[10];int save_day;int profit;}goods[MAX]; /*存放MAX种商品记录的结构体数据*/ save_message(jin sum) /*保存信息*/{FILE *fp;int i;if((fp=fopen("supermarket.txt","wb"))==NULL){printf("读文件错误!\n");return;}for(i=0;i<sum;i++)if(fwrite(&goods[i],sizeof(struct goods_type),1,fp)!=1) printf("写文件错误!\n");fclose(fp):}input message() /*输入模块*/{int i=0,s=MAX;clrscr();printf("\n\n 录入商品信息(最多%d 种)\n",s);printf("-------------------------\n");do{printf("\n 第%d种商品",i+1);printf("\n 商品号:");scanf("%d",&goods[i].num);if(goods[i].num==0) break;printf("\n 商品名称:");scanf("%s",goods[i].name);printf("\n 商品类别:");scanf("%s",goods[i].kind);printf("\n 商品总量:");scanf("%s",&goods[i].amout);printf("\n 商品上限:");scanf("%s",&goods[i].goods_up);printf("\n 商品下限:");scanf("%s",&goods[i].goods_down);printf("\n 进货价格:");scanf("%s",&goods[i].in_price);printf("\n 销售价格:");scanf("%s",&goods[i].out_price);printf("\n 进货数量:");scanf("%s",&goods[i].in_num);printf("\n 进货日期(yyyy-mm-dd):");scanf("%d-%d-%d",&goods[i].in_time.year,&goods[i].in_tim e.month,&goods[i].in_time.date);printf("\n 商品名称:");printf("\n 生产日期(yyyy-mm-dd):");scanf("%d-%d-%d",&goods[i].pro_time.year,&goods[i].pro_t ime.month,&goods[i].pro_time.date);printf("\n 生产厂家:");scanf("%s",goods[i].factory);printf("\n 保质期:");scanf("%s",goods[i].save_day);i++;}while(i<MAX);printf("\n --%d种商品信息输入完毕!--\n",i);sum=i;printf("\n 按任意键返回主菜单!");bioskey(0);}int read_message() /*读取信息*/{FILE *fp;int i=0;if((fp=fopen("supermarket.txt","rb"))==NULL){printf("\n\n*****暂时还没有任何库存信息,按任意键进入主菜单选择基本信息的录入!******\n");return;}while(feof(fp)!=1){fread(&goods[i],sizeof(struct goods_type),1,fp);if(goods[i].num==0) break;else i++;}fclose(fp);return(i);}output_message() /*输出模块*/{int i=0,j=0,count,page=1;clrscr();printf("\n\n --商品信息表-- 第%d页\n\n",page);PRINT2;PRINT1;do{if(goods[i].num!=0){j++;if(j%PAGE!=0){PRINT3;PRINT1;}else{PRINT3;PRINT1;if(goods[i+1].num!=0){printf("按任意键继续!");bioskey(0);clrscr();printf("\n\n --商品信息表-- 第%d页\n\n",++page);PRINT2;PRINT1;}}}i++;}while(goods[i].num!=0);printf("按任意键返回主菜单!");bioskey(0);}insert_message() /*添加商品信息*/{int i=sum,j,flag=0;char choice;clrscr();printf("\n\n 添加一种新商品\n");printf(" --------------------\n");do{goods[i].num=++sum;printf("\n 新商品号:%d",goods[i].num); printf("\n 商品名称:");scanf("%s",goods[i].name);printf("\n 商品类别:");scanf("%s",goods[i].kind);printf("\n 商品总量:");scanf("%s",&goods[i].amout);printf("\n 商品上限:");scanf("%s",&goods[i].goods_up);printf("\n 商品下限:");scanf("%s",&goods[i].goods_down);printf("\n 进货价格:");scanf("%s",&goods[i].in_price);printf("\n 销售价格:");scanf("%s",&goods[i].out_price);printf("\n 进货数量:");scanf("%s",&goods[i].in_num);printf("\n 进货日期(yyyy-mm-dd):");scanf("%d-%d-%d",&goods[i].in_time.year,&goods[i].in_tim e.month,&goods[i].in_time.date);printf("\n 商品名称:");printf("\n 生产日期(yyyy-mm-dd):");scanf("%d-%d-%d",&goods[i].pro_time.year,&goods[i].pro_t ime.month,&goods[i].pro_time.date);printf("\n 生产厂家:");scanf("%s",goods[i].factory);printf("\n 保质期:");scanf("%s",goods[i].save_day);printf("\n 要继续吗?(Y/N)");choice=getch();if(choice=='y'||choice=='Y'){printf("\n 继续!\n");i++;flag=1;}else flag=0;}while(flag==1);printf("\n 按任意键返回主菜单!");bioskey(0);}del_message() /*删除商品信息*/{;}revise_message() /*修改模块*/{int i=0,choice,revise_num,flag;do{clrscr();printf("\n 输入要修改的商品号:");scanf("%d",&revise_num);for(i=0;i<sum;i++)if(goods[i].num==revise_num){printf("\n --商品信息--\n");PRINT1;PRINT2;PRINT3;printf("\n 您要修改那一项?\n"); printf("\n 1.名称 \n");printf("\n 2.种类 \n");printf("\n 3.销售价格\n");printf("\n 4.生产日期\n");printf("\n 5.保质期 \n"); printf("\n 请选择(1-5)\n");scanf("%d",&choice);switch(choice){case 1;printf("\n 输入修改后的名称:");scanf("%s",&goods[i].name);break; case 2;printf("\n 输入修改后的种类:");scanf("%s",&goods[i].kind);break; case 3;printf("\n 输入修改后的销售价格:");scanf("%s",&goods[i].out_price);break;case 4;printf("\n 输入修改后的生产日期:");scanf("%d-%d-%d",&goods[i].pro_time.year,&goods[i].pro_t ime.month,&goods[i].pro_time.date);break;case 5;printf("\n 输入修改后的保质期:");scanf("%s",&goods[i].save_day);break;PRINT1;PRINT2;PRINT3;break;}if(i==sum){printf("\n 该商品不存在!");bioskey(0);}printf("\n\n 继续修改吗?(Y/N)"); choice=getch();if(choice=='y'||choice=='Y'){flag=1;printf("\n 继续!\n");}else flag=0;}while(flag==1);printf("\n 按任意键返回主菜单!");bioskey(0);}renew_message() /*更新模块*/int choice;do{clrscr();printf("\n\n\n ********更新商品信息*******\n\n");printf(" 1.添加商品信息\n\n");printf(" 2.删除商品信息\n\n");printf(" 3.修改商品信息\n\n");printf(" 0.返回主菜单\n\n"); printf(" 请选择(0-3):\n\n"); scanf("%d",&choice);switch(choice){case 1 : insert_message();break;case 2 : del_message();break;case 3 : revise_message();break;case 0 : break;}}while(choice!=0);inquire_name(){int i,choixe,j=0,inquire_in_price;char inquire_name[10];clrscr();printf("\n 输入要查询的商品名称:");scanf("%s",inquire_name);for(i=0;i<sum;i++)if(strcmp(goods[i].name,inquire_name)==0&&goods[i].num!= 0){printf("\n --商品信息--\n"); PRINT1;PRINT2;PRINT3;}else j++;if(j==sum)printf("\n 该商品不存在!");bioskey(0);}{;}inquire_count_time(){;}inquire_message() /*查询模块*/{int choice;do{clrscr();printf("\n\n\n *****查询商品信息*******\n\n");printf(" 1.按商品名称查询\n\n");printf(" 2.按商品类别查询\n\n");printf(" 3.按进货量和进货价格查询\n\n");printf(" 0.返回主菜单\n\n");printf(" 请选择(0-3) ");scanf("%d",&choice);switch(choice){case 2 : inquire_kind(); ;break;case 3 : inquire_count_time(); ;break;case 0 : break;}}while(choice!=0);}count_profit() /*统计利润*/{int i,choice,j=0,count_num,profit;char inquire_name[10];clrscr();printf("\n 输入要统计的商品号:");scanf("%d",&count_num);for(i=0;i<sum;i++)if(goods[i].num==count_num){profit=goods[i].out_price-goods[i].in_price;printf("\n 商品利润 ");printf("\n -------------------\n ");printf("\n 商品号利润 ");printf("\n%25d%13d\n",goods[i].num,profit);else j++;if(j==sum)printf("\n 该商品不存在!");bioskey(0);}count_in_amount() /*统计进货量*/{;}count_full() /*统计库存量*/{;}count_message() /*统计模块*/{int choice;do{clrscr();printf("\n\n\n ********统计商品信息*******\n\n");printf(" 1.统计某商品的利润\n\n");printf(" 2.统计某商品的进货量\n\n");printf(" 3.统计同种名称不同货号商品库存量\n\n");printf(" 0.返回主菜单\n\n");printf(" 请选择(0-3):");switch(choice){case 1 : count_profit() ;break;case 2 : count_in_amount() ;break; case 3 : count_full() ;break;case 0 : break;}}while(choice!=0);}sort_amount() /*库存排行*/{struct goods_type *p,*q[MAX];int i,j,k;clrscr();printf(" 库存排行\n");printf("----------------------------\n");printf("\n 排名商品号商品名称商品类别库存量\n"); p=goods;for(i=0;i<sum;i++)q[i]=p++;for(i=0;i<sum;i++){k=i;if(q[k]->amount<q[j]->amount)k=j;if(k!=i){p=q[i];q[i]=q[k];q[k]=p;}}for(i=0;i<sum;i++)printf("\n%18d %6d %8d %11s %10d\n",i+1,q[i]->name,q[i]->kind,q[i]->amount);bioskey(0);}sort_profit() /*利润排行*/{;}sort_out_amount() /*销售量排行*/{;}sort_message() /*排行模块*/{int choice;do{clrscr();********\n\n");printf(" 1.库存量排行\n\n");printf(" 2.利润排行\n\n"); printf(" 3.销售量排行\n\n");printf(" 0.返回主菜单\n\n");printf(" 请选择(0-3)\n\n"); scanf("%d",&choice);switch(choice){case 1 : sort_amount(); ;break;case 2 : sort_profit(); ;break;case 3 : sort_out_amount(); ;break; case 0 : break;}}while(choice!=0);}main() /*主程序*/{int choice;sum=read_message();do{clrscr();printf("\n\n\n *********超市管理系统********\n\n");printf(" 1.录入商品信息 \n\n");printf(" 2.打印商品信息 \n\n");printf(" 3.更新商品信息 \n\n");printf(" 4.查询商品信息 \n\n");printf(" 5.统计商品信息 \n\n");printf(" 6.商品排行信息 \n\n");printf(" 请选择(0-6)");scanf("%d",&choice);switch(choice){case 1: input_message(); break;case 2: output_message(); break;case 3: renew_message(); break;case 4: inquire_message(); break;case 5: count_message(); break;case 6: sort_message(); break;case 0: break;}}while(choice!=0);save_message(sum);printf("\n-以上商品信息已保存!--(文件名:supermarket.txt)\n");}。

  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
{
printf(" %d ",i+1);
printf(" %d ",q[i]->num);
printf(" %s ",q[i]->name);
printf(" %s ",q[i]->kind);
printf(" %d \n ",q[i]->amount);
}
else
j++;
if(j==sum)
printf("\n 该商品不存在!!!");
printf("\n 按任意键返回主菜单!!");
bioskey(0);
}
void Count_Message(void) /*统计模块*/
if(goods[i].num==0) break;
printf("\n 商品名称: ");
scanf ("%s",goods[i].name);
printf("\n 商品种类: ");
scanf ("%s",goods[i].kind);
#define PRINT2 printf("商品号--商品名称--商品种类--销售价格--生产日期(年-月-日)--保质期\n")
#define PRINT3 printf("%4d%8s%8s%8d%8d-%2d-%2d%4d\n",goods[i].num,goods[i].name,goods[i].kind,goods[i].out_price,goods[i].pro_time.year,goods[i].pro_time.month,goods[i].pro_time.day,goods[i].save_day)
printf("\n -------------------------------");
printf("\n 商品号 利润");
printf("\n %8d%8d\n",&goods[i].num,&profit);
printf("\n 保质期: ");
scanf ("%d",&goods[i].save_day);
printf("继续输入信息,y or n ??");
fflush(stdin);
scanf("%c",&bd);
if(bd=='y')
int amount;
int in_price;
int out_price;
struct date pro_time;
int save_day;
int profit;
}goods[MAX];
Save_Message(int sum); /*函数声明*/
scanf("%d",&choice);
switch(choice)
{
case 1:Count_Amount();break;
case 2:Count_Profit();break;
case 0:break;
void Inquire_message(void);
void Inquire_goodskind(void);
void Inquire_goodsname(void);
int Read_Message(void);
void Renew_Messahe(void);
void Revise_Message(void);
printf(" 1:按库存量排行\n\n");
printf(" 0:返回主菜单\n\n");
printf(" 请选择(0-1): ");
scanf("%d",&choice);
printf("******* 2:统计利润 ************\n\n\n");
printf("******* 0:返回主菜单 ************\n\n\n");
printf("******* 请选择(0-2): ************\n\n\n");
bioskey(0);
}
long Count_Profit() /*统计利润模块*/
{
int i,choice,j=0,count_num,profit;
clrscr();
printf("\n 请输入想要统计的商品号: ");
scanf("%d",&count_num);
{
struct goods_type *p,*q[MAX];
int i,j,k;
clrscr();
printf(" 库存排行");
PRINT1;
f("\n\n排名 商品号 商品名称 商品类别 库存量\n\n");
i++;
printf("\n 商品库存量: ");
scanf ("%d",&goods[i].amount);
printf("\n 进货价格: ");
scanf ("%d",&goods[i].in_price);
printf("\n 销售价格: ");
scanf("%d",&count_num);
for(i=0;i<sum;i++)
if(goods[i].num==count_num)
{
Amount=goods[i].amount;
printf("-------------------------");
k=j;
if(k!=i)
{
p=q[i];
q[i]=q[k];
q[k]=p;
}
}
for(i=0;i<sum;i++)
for(i=0;i<sum;i++)
if(goods[i].num==count_num)
{
profit=goods[i].out_price-goods[i].in_price;
printf("\n 商品利润");
}
}while(choice!=0);
}
int Input_Message(void) /*输入模块*/
{
int i=0,s=MAX;
char bd;
clrscr();
printf("开始输入商品信息.\n");
printf("\n\n 商品信息:(最多 %d) \n",s);
printf(" 商品号 库存量");
printf("\n%8d%8d",goods[i].num,Amount);
}
else
j++;
if(j==sum)
printf("该商品信息不存在!!!");
{
int choice;
do{
clrscr();
printf("**************统计商品信息*************\n\n\n");
printf("******* 1:统计库存量 ************\n\n\n");
scanf ("%d",&goods[i].out_price);
printf("\n 生产日期(yyyy-mm-dd): ");
scanf ("%d-%d-%d",&goods[i].pro_time.year,&goods[i].pro_time.month,&goods[i].pro_time.day);
}
bioskey(0);
}
long Count_Amount() /*统计库存量*/
{
int i,j=0,choice,count_num,Amount;
char inquire_name[10];
clrscr();
printf("\n 请输入想要统计的商品号: ");
void Delete_Message(void);
void Insert_Message();
void Show_Message(void);
int Input_Message(void);
void Count_Message();
long Count_Profit();
long Count_Amount();
switch(choice)
{
case 1:Sort_amount();break;
case 0:break;
}
}while(choice!=0);
}
void Sort_amount(void) /*库存量排序*/
void Sort_amount(void);
void Sort_Message(void);
相关文档
最新文档