1、c+ 仓库管理系统212020年5月29日文档仅供参考#include#includeusing namespace std;const int m=100; /定义常量mclass Store /定义类private:int num; /编号char name20; /名称double price; /价格int quantity; /数量int amount; /数目public:void Input();int Input_2();void Dig();void Change();void Search_num();void Search_name();void Show();void
2、Short();void Delete();goodsm;void Store:Input() /创立表单int i,n;coutamount;coutendl;for(i=0;iamount;i+)cout这是第(i+1)货物信息endl;goodsi.num=i+1;coutgoodsi.name;coutgoodsi.price;coutgoodsi.quantity;coutendl;coutn输入的信息:endl;for(i=0;iamount;i+)cout货号:goodsi.numends;cout货品名:goodsi.nameends;cout单价:goodsi.priceen
3、ds;cout库存量:goodsi.quantityendsendl;ofstream os(goods.txt,ios_base:out|ios_base:binary); /创立、打开文件for(n=0;namount;n+)os.write( reinterpret_cast(&(goodsn),sizeof(Store) ); /导出文件os.close(); /关闭文件int Store:Input_2() /文件读入int i,n;ifstream is(goods.txt,ios_base:in|ios_base:binary);if(!is)cout打开失败endl;retur
4、n 0;for(i=0;is.read( reinterpret_cast(goods+i) , sizeof(Store) );i+)amount=i;cout导入的表单:endl;for(n=0;namount;n+)cout货号:goodsn.numends;cout货品名:goodsn.nameends;cout单价:goodsn.priceends;cout库存量:goodsn.quantityendsendl;return 1;void Store:Dig() /插入信息int i,n,m;coutn;coutendl;for(i=0;in;i+)cout这是第(i+1)货物信息e
5、ndl;goodsamount+i.num=amount+i+1;coutgoodsamount+i.name;coutgoodsamount+i.price;coutgoodsamount+i.quantity;coutn输入的信息endl;for(i=0;iamount+n;i+)cout货号:goodsi.numends;cout货品名:goodsi.nameends;cout单价:goodsi.priceends;cout库存量:goodsi.quantityendsendl;amount=amount+n;ofstream os(goods.txt,ios_base:out|ios_
6、base:binary); /创立、打开文件for(m=0;mamount;m+)os.write( reinterpret_cast(&(goodsm),sizeof(Store) ); /导出文件os.close(); /关闭文件;void Store:Change() /修改信息int n,i,m;coutn;coutendl;cout请输入修改的信息endl;coutgoodsn-1.name;coutgoodsn-1.price;coutgoodsn-1.quantity;coutendl;cout修改后的信息:endl;for(i=0;iamount;i+)cout货号:goods
7、i.numends;cout货品名:goodsi.nameends;cout单价:goodsi.priceends;cout库存量:goodsi.quantityendsendl;ofstream os(goods.txt,ios_base:out|ios_base:binary); /创立、打开文件for(m=0;mamount;m+)os.write( reinterpret_cast(&(goodsm),sizeof(Store) ); /导出文件os.close(); /关闭文件void Store:Search_num() /按编号查int n;coutn;coutendl;if(n
8、=amount)cout货号:goodsn-1.numends;cout货品名:goodsn-1.nameends;cout单价:goodsn-1.priceends;cout库存量:goodsn-1.quantityendsamount)cout输入错误,请重新输入:amount);void Store:Search_name() /按名称查int flag = 0;int i;char x20;coutx;coutendl;for(i=0;iamount;i+)if(strcmp(goodsi.name,x)=0) /strcmp 用来比较字符串.tname和xflag = 1;cout货
9、号:goodsi.numends;cout货品名:goodsi.nameends;cout单价:goodsi.priceends;cout库存量:goodsi.quantityendsendl;else;if (flag = 0)cout输入错误,请重新输入:ends;while(flag = 0);void Store:Show() /显示信息int i;for(i=0;iamount;i+)cout货号:goodsi.numends;cout货品名:goodsi.nameends;cout单价:goodsi.priceends;cout库存量:goodsi.quantityendsendl
10、;void Store:Short() /查询不足货物int flag = 0;int i;int y;couty;coutendl;for(i=0;iamount;i+)if(goodsi.quantity=y)flag = 1;cout货号:goodsi.numends;cout货品名:goodsi.nameends;cout单价:goodsi.priceends;cout库存量:goodsi.quantityendsendl;else;if (flag = 0)cout没有货物,请重新输入:ends;while(flag = 0);void Store:Delete() /删除货物cha
11、r y20;int n,m;couty;for(int i=0;iamount;i+)if(strcmp(goodsi.name,y)=0)/strcmp 用来比较字符串.tname和yfor(;iamount;i+)goodsi=goodsi+1;goodsi.num=i+1;amount=amount-1; /货物数减一cout删除后货单:endl;for(m=0;mamount;m+)cout货号:goodsm.numends;cout货品名:goodsm.nameends;cout单价:goodsm.priceends;cout库存量:goodsm.quantityendsendl;o
12、fstream os(goods.txt,ios_base:out|ios_base:binary); /创立、打开文件for(n=0;namount;n+)os.write( reinterpret_cast(&(goodsn),sizeof(Store) ); /导出文件os.close(); /关闭文件;void Clear() /清屏函数char a;a=getchar();system(cls);void menuPrint() /主菜单coutt* 仓库管理 *endl;coutt* 1.输入货物信息 *endl;coutt* 2.查询货物信息 *endl;coutt* 3.显示货
13、物信息 *endl;coutt* 4.显示不足货物 *endl;coutt* 5.删除货物信息 *endl;coutt* 6. 退出系统 *endl;coutt*endl;cout请输入你要进行的操作(16):n;coutendl;switch(n)case 1: /输入货物信息int a;cout 输入方式endl;cout1.创立表单endl;cout2.从文件导入endl;cout3.插入信息endl;cout4.修改信息endl;cout5.返回主菜单a;coutendl;switch(a)case 1: /调用创立函数Goods.Input();break;case 2: /调用文件
14、读入函数Goods.Input_2();break;case 3: /调用增加函数Goods.Dig();break;case 4: /调用增加函数Goods.Change();break;case 5:break;default:cout您的输入有误,请重新选择endl;break;break;case 2: /查询int a;cout 查询方式endl;cout1.按编号查询endl;cout2.按名称查询endl;cout3.返回主菜单a;coutendl;switch(a)case 1: /调用函数(按货号查)Goods.Search_num();break;case 2: /调用函数(按货名查)Goods.Search_name();break;case 3:break;default:cout您的输入有误,请重新选择endl;break;break;case 3: /显示Goods.Show();break;case 4: /查询不足货物Goods.Short();break;case 5: /删除信息Goods.Delete();break;case 6: /退出exit(0);break;default:cout您的输入有误,请重新选择ends;break;while(1);return 0;