商品月销售基本信息管理软件设计电子教案.doc
Good is good, but better carries it.精益求精,善益求善。商品月销售基本信息管理软件设计-/*商品月销售基本信息管理软件设计*#include<fstream.h>#include<iostream.h>#include<string.h>#include<conio.h>structproductintnumber;charname20;doubleprice;charaddress20;inttotal_num;/*本月当前销售总数量*doubletotal_sale;/*本月当前销售总金额*intstocks;/*库存余量*;voidwrite();/录入voidsearch();/查询voidin();/进货voidsell();/售出voidstat();/统计charExit();/退出intMenu();/菜单intmain()cout<<"¤¤"<<endl;cout<<""<<endl;cout<<"<欢迎来到商品查询系统>"<<endl;cout<<"_"<<endl;cout<<"=_="<<endl;cout<<""<<endl;cout<<""<<endl;cout<<"-欢迎使用商品查询系统-"cout<<endl<<endl;intselect;chars;while(1)select=Menu();switch(select)case1:write();break;case2:search();break;case3:sell();break;case4:in();break;case5:stat();break;case6:s=Exit();if(s='Y'|s='y')return0;break;default:cout<<"无效输入!"<<endl;return0;voidwrite()productpro;inti,n;ofstreamoutfile("info.dat",ios:out|ios:binary);if(!outfile)cout<<"文件打开错误!"return;cout<<"输入商品个数:"<<endl;cin>>n;for(i=0;i<n;i+)cout<<"输入第"<<i+1<<"个商品的编号、名称、单价、生产地、销售总数、库存余量"<<endl;cin>>pro.number;cin>>pro.name;cin>>pro.price;cin>>pro.address;cin>>pro.total_num;pro.total_sale=pro.total_num*pro.price;cin>>pro.stocks;outfile.write(char*)&pro,sizeof(pro);/*向磁盘文件输出数据*outfile.close();voidsearch()/*查找功能*productpro;intn;fstreammfile("info.dat",ios:in|ios:binary);cout<<"输入要查询商品的编号:"cin>>n;/*查找是否有符合条件的商品*domfile.read(char*)&pro,sizeof(pro);while(pro.number!=n&&!mfile.eof();if(!mfile.eof()cout<<"商品名称:"<<pro.name<<endl;cout<<"商品库存余量:"<<pro.stocks<<endl;cout<<"商品价格:"<<pro.price<<endl;cout<<"商品总销售额:"<<pro.total_sale<<endl;elsecout<<"无此商品"<<endl;mfile.close();voidin()/*进货功能*productpro;intn,x;fstreammfile("info.dat",ios:in|ios:out|ios:binary);cout<<"输入要进货商品的编号:"cin>>n;domfile.read(char*)&pro,sizeof(pro);while(pro.number!=n&&!mfile.eof();if(!mfile.eof()cout<<"当前商品信息:"<<endl;cout<<"商品名称:"<<pro.name<<endl;cout<<"商品库存余量:"<<pro.stocks<<endl;cout<<"商品价格:"<<pro.price<<endl;cout<<"商品总销售额:"<<pro.total_sale<<endl;elsecout<<"无此商品"<<endl;return;cout<<"请输入进货数量:"cin>>x;pro.stocks+=x;/*库存增加*pro.total_sale-=pro.price*x;/*销售总额减少*mfile.seekp(-(int)sizeof(pro),ios:cur);mfile.write(char*)&(pro),sizeof(pro);cout<<"新的商品信息:"<<endl;cout<<"商品名称:"<<pro.name<<endl;cout<<"商品库存余量:"<<pro.stocks<<endl;cout<<"商品价格:"<<pro.price<<endl;cout<<"商品总销售额:"<<pro.total_sale<<endl;mfile.close();voidsell()/*售出功能*productpro;intn,x;fstreammfile("info.dat",ios:in|ios:out|ios:binary);cout<<"输入售出商品的编号:"cin>>n;domfile.read(char*)&pro,sizeof(pro);while(pro.number!=n&&!mfile.eof();if(!mfile.eof()cout<<"当前商品信息:"<<endl;cout<<"商品名称:"<<pro.name<<endl;cout<<"商品库存余量:"<<pro.stocks<<endl;cout<<"商品价格:"<<pro.price<<endl;cout<<"商品总销售额:"<<pro.total_sale<<endl;elsecout<<"无此商品"<<endl;cout<<"请输入售出数量:"cin>>x;if(pro.stocks>x)pro.stocks-=x;/*库存减少*elsecout<<"输入数据错误!"<<endl;pro.total_sale+=pro.price*x;/*销售总额增加*mfile.seekp(-(int)sizeof(pro),ios:cur);mfile.write(char*)&(pro),sizeof(pro);cout<<"新的商品信息:"<<endl;cout<<"商品名称:"<<pro.name<<endl;cout<<"商品库存余量:"<<pro.stocks<<endl;cout<<"商品价格:"<<pro.price<<endl;cout<<"商品总销售额:"<<pro.total_sale<<endl;mfile.close();voidstat()/*统计功能*productpro;doublet=0.0;intnum=0;charn20;fstreammfile("info.dat",ios:in|ios:binary);domfile.read(char*)&pro,sizeof(pro);if(t<pro.total_sale)t=pro.total_sale;num=pro.number;strcpy(n,pro.name);while(!mfile.eof();cout<<"最大商品的编号、商品名及销售总额:"<<endl;cout<<num<<'t'<<n<<'t'<<t<<endl;intMenu()cout<<"主菜单"<<endl;intn=1,select=-1;cout<<n+<<"录入功能"<<""cout<<n+<<"查询功能"<<""cout<<n+<<"售出功能"<<""cout<<n+<<"进货功能"<<""cout<<n+<<"统计功能"<<""cout<<n+<<"退出"<<endl<<endl;cout<<"请选择相应数字:"cin>>select;returnselect;charExit()chars;cout<<"确定要退出本程序吗?【Y/N】:"cin>>s;cout<<"THEEND"<<endl;cout<<"谢谢观看!··"<<endl;cout<<""<<endl;cout<<""<<endl;returns;-