c++ 仓库管理系统

整理文档很辛苦,赏杯茶钱您下走!

免费阅读已结束,点击下载阅读编辑剩下 ...

阅读已结束,您可以下载文档离线阅读编辑

资源描述

#includeiostream#includefstreamusingnamespacestd;constintm=100;//定义常量mclassStore//定义类{private:intnum;//编号charname[20];//名称doubleprice;//价格intquantity;//数量intamount;//数目public:voidInput();intInput_2();voidDig();voidChange();voidSearch_num();voidSearch_name();voidShow();voidShort();voidDelete();}goods[m];voidStore::Input()//创建表单{inti,n;cout请输入货物总数:;cinamount;coutendl;for(i=0;iamount;i++){cout这是第(i+1)货物信息endl;goods[i].num=i+1;cout货品名:;cingoods[i].name;cout单价:;cingoods[i].price;cout库存量:;cingoods[i].quantity;coutendl;}cout\n输入的信息:endl;for(i=0;iamount;i++){cout货号:goods[i].numends;cout货品名:goods[i].nameends;cout单价:goods[i].priceends;cout库存量:goods[i].quantityendsendl;}ofstreamos(goods.txt,ios_base::out|ios_base::binary);//创建、打开文件for(n=0;namount;n++){os.write(reinterpret_castchar*(&(goods[n])),sizeof(Store));//导出文件}os.close();//关闭文件}intStore::Input_2()//文件读入{inti,n;ifstreamis(goods.txt,ios_base::in|ios_base::binary);if(!is){cout打开失败endl;return0;}for(i=0;is.read(reinterpret_castchar*(goods+i),sizeof(Store));i++)amount=i;cout导入的表单:endl;for(n=0;namount;n++){cout货号:goods[n].numends;cout货品名:goods[n].nameends;cout单价:goods[n].priceends;cout库存量:goods[n].quantityendsendl;}return1;}voidStore::Dig()//插入信息{inti,n,m;cout请输入增加的货物总数:;cinn;coutendl;for(i=0;in;i++){cout这是第(i+1)货物信息endl;goods[amount+i].num=amount+i+1;cout货品名:;cingoods[amount+i].name;cout单价:;cingoods[amount+i].price;cout库存量:;cingoods[amount+i].quantity;}cout\n输入的信息endl;for(i=0;iamount+n;i++){cout货号:goods[i].numends;cout货品名:goods[i].nameends;cout单价:goods[i].priceends;cout库存量:goods[i].quantityendsendl;}amount=amount+n;ofstreamos(goods.txt,ios_base::out|ios_base::binary);//创建、打开文件for(m=0;mamount;m++){os.write(reinterpret_castchar*(&(goods[m])),sizeof(Store));//导出文件}os.close();//关闭文件};voidStore::Change()//修改信息{intn,i,m;cout要修改第几个货物的信息(输入货号):;cinn;coutendl;cout请输入修改的信息endl;cout货品名:;cingoods[n-1].name;cout单价:;cingoods[n-1].price;cout库存量:;cingoods[n-1].quantity;coutendl;cout修改后的信息:endl;for(i=0;iamount;i++){cout货号:goods[i].numends;cout货品名:goods[i].nameends;cout单价:goods[i].priceends;cout库存量:goods[i].quantityendsendl;}ofstreamos(goods.txt,ios_base::out|ios_base::binary);//创建、打开文件for(m=0;mamount;m++){os.write(reinterpret_castchar*(&(goods[m])),sizeof(Store));//导出文件}os.close();//关闭文件}voidStore::Search_num()//按编号查{intn;cout请输入货号:;do{cinn;coutendl;if(n=amount){cout货号:goods[n-1].numends;cout货品名:goods[n-1].nameends;cout单价:goods[n-1].priceends;cout库存量:goods[n-1].quantityendsendl;}elseif(namount){cout输入错误,请重新输入:ends;}}while(namount);};voidStore::Search_name()//按名称查{intflag=0;inti;charx[20];cout请输入货物名:;do{cinx;coutendl;for(i=0;iamount;i++){if(strcmp(goods[i].name,x)==0)//strcmp用来比较字符串.tname和x{flag=1;cout货号:goods[i].numends;cout货品名:goods[i].nameends;cout单价:goods[i].priceends;cout库存量:goods[i].quantityendsendl;}else;}if(flag==0)cout输入错误,请重新输入:ends;}while(flag==0);};voidStore::Show()//显示信息{inti;for(i=0;iamount;i++){cout货号:goods[i].numends;cout货品名:goods[i].nameends;cout单价:goods[i].priceends;cout库存量:goods[i].quantityendsendl;}};voidStore::Short()//查询不足货物{intflag=0;inti;inty;cout请查询库存量:;do{ciny;coutendl;for(i=0;iamount;i++){if(goods[i].quantity=y){flag=1;cout货号:goods[i].numends;cout货品名:goods[i].nameends;cout单价:goods[i].priceends;cout库存量:goods[i].quantityendsendl;}else;}if(flag==0)cout没有货物,请重新输入:ends;}while(flag==0);};voidStore::Delete()//删除货物{chary[20];intn,m;cout请输入要删除的货物名:;ciny;for(inti=0;iamount;i++){if(strcmp(goods[i].name,y)==0)//strcmp用来比较字符串.tname和y{for(;iamount;i++){goods[i]=goods[i+1];goods[i].num=i+1;}amount=amount-1;//货物数减一}}cout删除后货单:endl;for(m=0;mamount;m++){cout货号:goods[m].numends;cout货品名:goods[m].nameends;cout单价:goods[m].priceends;cout库存量:goods[m].quantityendsendl;}ofstreamos(goods.txt,ios_base::out|ios_base::binary);//创建、打开文件for(n=0;namount;n++){os.write(reinterpret_castchar*(&(goods[n])),sizeof(Store));//导出文件}os.close();//关闭文件};voidClear()//清屏函数{chara;a=getchar();system(cls);}voidmenuPrint()//主菜单{cout\t*****仓库管理*****endl;cout\t*1.输入货物信息*endl;cout\t*2.查询货物信息*endl;cout\t*3.显示货物信息*endl;cout\t*4.显示不足货物*endl;cout\t*5.删除货物信息*endl;cout\t*6.退出系统*endl;cout\t**********************endl;cout请输入你要进行的操作(1~6):endl;}intmain()//主函数{StoreGoods;//定义对象intn;do{menuPrint();//调用主菜单cinn;coutendl;switch(n){case1://输入货物信息{inta;cout输入方式endl;cout1.创建表单endl;cout2.从文件导入endl;cout3.插入信息endl;cout4.修改信息endl;cout5.返回主菜单endl;cina;coutendl;switch(a){case1://调用创建函数Goods.Input();break;case2://调用文件读入函数Goods.Input_2();break;case3://调用增加函数Goods.Dig();break;case4://调用增加函数Goods.Change();break;case5:break;default:cout您的输入有误,请重新选择endl;break;}break;}case2:/

1 / 10
下载文档,编辑使用

©2015-2020 m.777doc.com 三七文档.

备案号:鲁ICP备2024069028号-1 客服联系 QQ:2149211541

×
保存成功