1、//main.cpp
#include
2、 string storeNo;//仓库编号 string kinds;//商品大类 string shelfNo;//货架号 }; //电器类 class ele { public: ele(); private: string name;//商品名 double price;//介格 shelf sh;//所属货架 long count;//商品数量 }; //管理(组合类) class mana { public: mana(); char first_face();//首页 void in_storage();//入库 vo
3、id out_storage();// 出库 void select_ele();//查询 void select_name();//按商品名称查询 void select_price();//按商品价格查询 void select_kind();//按大类查询 void call_break();//商品报损 private: ele aele; shelf ashelf; admin abs; }; //电器类默认结构函数 ele::ele():sh() { name = "xxx";//商品名 price = 0.0;//介格 count = 0;//商品
4、数量 } // //仓库货架类默认结构函数 shelf::shelf():men() { storeNo = "xxx";//仓库编号 kinds = "xxx";//商品大类 shelfNo = "xxx";;//货架号 } //仓库管理员类 admin::admin() { name = "xxx"; } //管理类默认结构函数 mana::mana():aele(), ashelf(), abs() { } char mana::first_face() { system("cls"); cout << endl; cou
5、t < 6、t◆ ◆"
< 7、ong count = 0; //商品数量
cout << endl << "商品入库,请输入相关信息 : " << endl << endl ;
cout << "\t商品名称 : ";
cin >> name;
cout << endl << "\t商品介格 : ";
cin >> price;
cout << endl << "\t商品数量 : ";
cin >> count;
cout << endl << "\t仓库编号 : ";
cin >> storeNo;
cout << endl << "\t商品大类 : ";
cin >> kinds;
cout 8、 << endl << "\t货架编号 : " ;
cin >> shelfNo;
ofstream storeFile("store.txt", ios::app);
storeFile << setiosflags(ios::left) << setw(20) << name << " "
<< setw(15) << price << " " << setw(10) << count << " "
<< setw(10) << storeNo << " " << setw(20) << kinds << " "
<< shelfNo << endl;
storeFile 9、close();
cout << endl << endl << "\t该商品已经入库......." << endl << endl << "\t";
system("pause");
}
// 出库
void mana::out_storage()
{
system("cls");
string name;//商品名
cout << endl << "\t商品出库,输入出库商品信息 : " << endl << endl;
cout << "\t商品名称 : ";
cin >> name;
ifstream storeFile("store 10、txt");
if (!storeFile)
{
ofstream storeFile1("store.txt");
storeFile1.close();
cout << endl << endl << "\t仓存为空!!!!" << endl << endl << "\t";
system("pause");
return;
}
bool flag = false;
string name1;//商品名
double price1;//介格
string storeNo1;//仓库编号
string kinds1;//商品大类
string shelfNo1; 11、//货架号
long count1 = 0; //商品数量
ofstream tempFile("temp.txt");
while (storeFile >> name1 >> price1 >> count1 >> storeNo1 >> kinds1 >> shelfNo1)
{
if (name1==name)
flag = true;
else
{
tempFile << setiosflags(ios::left) << setw(20) << name1 << " "
<< setw(15) << price1 << " " << setw(10) < 12、< count1 << " "
<< setw(10) << storeNo1 << " " << setw(20) << kinds1 << " "
<< shelfNo1 << endl;
}
}
tempFile.close();
storeFile.close();
if (!flag)
{
cout << endl << endl << "\t仓库中没有这种商品!!!" << endl << endl << "\t";
system("pause");
return;
}
ofstream storeFile1("store.txt");
ifst 13、ream tempFile1("temp.txt");
storeFile1 << tempFile1.rdbuf();
storeFile1.close();
tempFile1.close();
cout << endl << "\t这些商品已经出库, 请仔细检验!!!" << endl << endl << "\t";
system("pause");
}
//查询
void mana::select_ele()
{
while (1)
{
system("cls");
cout << endl << endl;
cout << "\t====== 14、" << endl
<< "\t|| ||" << endl
<< "\t|| 商 品 查 询 ||" << endl
<< "\t|| ||" << endl
<< "\t|| 1. 按商品名称查询 ||" << endl
<< "\t|| ||" << endl
<< "\t|| 2. 按商品价格查询 ||" << endl
<< "\t|| ||" << endl
<< "\t|| 3. 按大类查询 ||" << endl
<< "\t|| ||" << end 15、l
<< "\t|| 4. 返回 ||" << endl
<< "\t|| ||" << endl
<< "\t=============================================================" << endl << endl << "\t\t";
char select = getch();
switch (select)
{
case '1':
select_name();
break;
case '2':
select_price();
break;
case '3':
select_kind();
break; 16、
case '4':
return;
default:
break;
}
}
}
//按商品名称查询
void mana::select_name()
{
system("cls");
cout << endl << "\t按商品名查询 : " << endl << endl ;
cout << "\t输入商品名 : ";
string name;
cin >> name;
string name1;//商品名
double price1;//介格
string storeNo1;//仓库编号
string kinds1;//商品大类
strin 17、g shelfNo1;//货架号
long count1 = 0; //商品数量
ifstream storeFile("store.txt");
if (!storeFile)
{
cout << endl << endl << "\t对不起,你库存为空!!!" << endl << endl << "\t";
system("pause");
return;
}
bool flag = false;
cout << endl << "商品名 " << "介格 " << "商品数量 " << "仓库编号 "
<< "商品大类 " << "货架号" << endl 18、 << endl;
while (storeFile >> name1 >> price1 >> count1 >> storeNo1 >> kinds1 >> shelfNo1)
{
if (name1 == name)
{
flag = true;
cout << setiosflags(ios::left) << setw(15) << name1 << " "
<< setw(10) << price1 << " " << setw(10) << count1 << " "
<< setw(10) << storeNo1 << " " << setw(15) << ki 19、nds1 << " "
<< shelfNo1 << endl;
}
}
storeFile.close();
if (!flag)
cout << endl << endl << "对不起,库存中没有这种商品!!!";
cout << endl << endl;
system("pause");
}
//按商品价格查询
void mana::select_price()
{
system("cls");
cout << endl << "\t按商品价格查询 : " << endl << endl ;
cout << "\t输入价格 : ";
doubl 20、e price;
cin >> price;
string name1;//商品名
double price1;//介格
string storeNo1;//仓库编号
string kinds1;//商品大类
string shelfNo1;//货架号
long count1 = 0; //商品数量
ifstream storeFile("store.txt");
if (!storeFile)
{
cout << endl << endl << "\t对不起,你库存为空!!!" << endl << endl << "\t";
system("pause"); 21、
return;
}
bool flag = false;
cout << endl << "商品名 " << "介格 " << "商品数量 " << "仓库编号 "
<< "商品大类 " << "货架号" << endl << endl;
while (storeFile >> name1 >> price1 >> count1 >> storeNo1 >> kinds1 >> shelfNo1)
{
if (price1 == price)
{
flag = true;
cout << setiosflags(ios::left) << setw(15) << n 22、ame1 << " "
<< setw(10) << price1 << " " << setw(10) << count1 << " "
<< setw(10) << storeNo1 << " " << setw(15) << kinds1 << " "
<< shelfNo1 << endl;
}
}
storeFile.close();
if (!flag)
cout << endl << endl << "对不起,库存中没有这个价格商品!!!";
cout << endl << endl;
system("pause");
}
//按大类查询
voi 23、d mana::select_kind()
{
system("cls");
cout << endl << "\t按商品大类查询 : " << endl << endl ;
cout << "\t输入大类名 : ";
string kinds;
cin >> kinds;
string name1;//商品名
double price1;//介格
string storeNo1;//仓库编号
string kinds1;//商品大类
string shelfNo1;//货架号
long count1 = 0; //商品数量
ifstream storeFil 24、e("store.txt");
if (!storeFile)
{
cout << endl << endl << "\t对不起,你库存为空!!!" << endl << endl << "\t";
system("pause");
return;
}
bool flag = false;
cout << endl << "商品名 " << "介格 " << "商品数量 " << "仓库编号 "
<< "商品大类 " << "货架号" << endl << endl;
while (storeFile >> name1 >> price1 >> count1 >> st 25、oreNo1 >> kinds1 >> shelfNo1)
{
if (kinds1 == kinds)
{
flag = true;
cout << setiosflags(ios::left) << setw(15) << name1 << " "
<< setw(10) << price1 << " " << setw(10) << count1 << " "
<< setw(10) << storeNo1 << " " << setw(15) << kinds1 << " "
<< shelfNo1 << endl;
}
}
storeFile.close();
26、
if (!flag)
cout << endl << endl << "对不起,库存中没有这类商品!!!";
cout << endl << endl;
system("pause");
}
//商品报损
void mana::call_break()
{
system("cls");
string name;//商品名
cout << endl << "\t商品报损,请输入要报损商品信息 : " << endl << endl;
cout << "\t商品名称 : ";
cin >> name;
ifstream storeFile("stor 27、e.txt");
if (!storeFile)
{
ofstream storeFile1("store.txt");
storeFile1.close();
cout << endl << endl << "\t仓存为空!!!!" << endl << endl << "\t";
system("pause");
return;
}
bool flag = false;
string name1;//商品名
double price1;//介格
string storeNo1;//仓库编号
string kinds1;//商品大类
string shelfN 28、o1;//货架号
long count1 = 0; //商品数量
ofstream tempFile("temp.txt");
cout << endl << endl << "你想报损商品信息以下 : " << endl << endl;
cout << endl << "商品名 " << "介格 " << "商品数量 " << "仓库编号 "
<< "商品大类 " << "货架号" << endl << endl;
while (storeFile >> name1 >> price1 >> count1 >> storeNo1 >> kinds1 >> shelfNo1) 29、
{
if (name1==name)
{
flag = true;
cout << setiosflags(ios::left) << setw(15) << name1 << " "
<< setw(10) << price1 << " " << setw(10) << count1 << " "
<< setw(10) << storeNo1 << " " << setw(15) << kinds1 << " "
<< shelfNo1 << endl;
shelfNo1 += "(损坏)";
}
tempFile << setiosflags(ios::left) 30、 << setw(20) << name1 << " "
<< setw(15) << price1 << " " << setw(10) << count1 << " "
<< setw(10) << storeNo1 << " " << setw(20) << kinds1 << " "
<< shelfNo1 << endl;
}
tempFile.close();
storeFile.close();
if (!flag)
{
cout << endl << endl << "对不起,仓库中没有这种商品!!!" << endl << endl;
system(" 31、pause");
return;
}
ofstream storeFile1("store.txt");
ifstream tempFile1("temp.txt");
storeFile1 << tempFile1.rdbuf();
storeFile1.close();
tempFile1.close();
cout << endl << endl << "这些商品已经损坏,请立即从仓库中取出!!!" << endl << endl;
cout << "报损成功,统计已经更改!!!" << endl << endl ;
system("pause");
}
32、int main()
{
char select;
mana men;
while (select = men.first_face())
{
switch (select)
{
case '1':
men.in_storage();
break;
case '2':
men.out_storage();
break;
case '3':
men.select_ele();
break;
case '4':
men.call_break();
break;
case '5':
cout << "\t" << "谢谢使用!!!!" << endl << endl << "\t\t";
exit( 0 );
break;
default:
break;
}
}
return 0; }






