仓库管理系统 查询系统不能用,好像只有添加和删除能用
#include<iostream>
#include<list>
#include<fstream>
#include<string>
#include<sstream>
using namespace std;
class Bale
{
public:
Bale(string ID=" ",string Name=" ",double Price=0,int Number=0)
{
id=ID;name=Name;price=Price;number=Number;
}
string getID(){return id;}
string getName(){return name;}
double getPrice(){return price;}
int getNumber(){return number;}
list<Bale>::iterator Begin(){ return balelist.begin(); }
list<Bale>::iterator End(){ return balelist.end(); }
void Add()//添加货物
{
string id;string name;double price;int number;
cout<<"添加的货物编号是:"<<endl;
cin>>id;
while(1)
{
if(CheckID(id))
break;
else
{
cout<<"输入的货物编号已存在,需重新输入编号:";
cin>>id;
}
}
cout<<"货物的名称是:"<<endl;
cin>>name;
while(1)
{
if(CheckName(name))
break;
else
{
cout<<"输入的货物名称已存在,需重新输入名称:";
cin>>name;
}
}
cout<<"货物单价是:"<<endl;
cin>>price;
cout<<"货物数量是:"<<endl;
cin>>number;
Bale bale(id,name,price,number);
balelist.insert(balelist.end(),bale);
system("pause");
}
void Add(Bale bale)
{
balelist.insert(balelist.end(),bale);
}
void Delete()//删除货物
{
string name;
cout<<"请输入需要删除的货物的名称:"<<endl;
cin>>name;
list<Bale>::iterator beg=balelist.begin();
list<Bale>::iterator end=balelist.end();
while(beg!=end)
{
if(beg->getName()==name)
break;
beg++;
}
if(beg==end)
{
cout<<"你输入的货物不存在"<<endl;
}
else
{
balelist.erase(beg);
cout<<"已成功删除该货物信息"<<endl;
}
system("pause");
}
private:
string id;string name;double price;int number;int tag;bool CheckName(string);bool CheckID(string);list <Bale>balelist;
};
bool Bale::CheckID(string id)//检验编号
{
list<Bale>::iterator beg=balelist.begin();
list<Bale>::iterator end=balelist.end();
for(;beg!=end;beg++)
{
if(beg->getID()==id)
break;
}
return beg==end;
}
bool Bale::CheckName(string name)//检验名称
{
list<Bale>::iterator beg=balelist.begin();
list<Bale>::iterator end=balelist.end();
for(;beg!=end;beg++)
{
if(beg->getName()==name)
break;
}
return beg==end;
}
class Warehouse
{
public:
Warehouse();
void SearchID();
void SearchName();
void ShowAllbale();
list<Bale>::iterator Begin(){ return balelist.begin(); }
list<Bale>::iterator End(){ return balelist.end(); }
private:
list <Bale>balelist;void ShowBale(list<Bale>::iterator);
};
Warehouse::Warehouse(){}
void Warehouse::ShowBale(list<Bale>::iterator iter)
{
cout<<"编号:"<<iter->getID()<<endl;
cout<<"名称:"<<iter->getName()<<endl;
cout<<"单价:"<<iter->getPrice()<<endl;
cout<<"数量:"<<iter->getNumber()<<endl;
system("pause");
};
void Warehouse::SearchID()
{
string id;
cout<<"要查询的货物编号是:"<<endl;
cin>>id;
list<Bale>::iterator beg=balelist.begin();
list<Bale>::iterator end=balelist.end();
while(beg!=end)
{
if(beg->getID()==id)
break;
beg++;
}
if(beg==end)
{
cout<<"该编号的货物不存在;";
}
else
{
cout<<"该货物的信息如下:"<<endl;
ShowBale(beg);
}
system("pause");
}
void Warehouse::SearchName()
{
string name;
cout<<"要查询的货物的名称是:"<<endl;
cin>>name;
list<Bale>::iterator beg=balelist.begin();
list<Bale>::iterator end=balelist.end();
while(beg!=end)
{
if(beg->getName()==name)
break;
beg++;
}
if(beg==end)
{
cout<<"该名称的货物不存在;"<<endl;
}
else
ShowBale(beg);
system("pause");
}
void Warehouse::ShowAllbale()
{
list<Bale>::iterator beg=balelist.begin();
list<Bale>::iterator end=balelist.end();
int i=0;
cout<<"所有货物的信息:"<<endl;
while(beg!=end)
{
i++;
cout<<"第"<<i<<"个货物的信息:"<<endl;
ShowBale(beg);
cout<<endl;
beg++;
}
system("pause");
}
int main()
{
system("color A0");//运行界面色彩设置
string id;//编号
string name;//名称
double price;//单价
int number;//数字
Bale aa;
Warehouse house;
char i;
do
{
system("CLS");
cout<<"---------------------------"<<endl;
cout<<" 仓库管理系统 "<<endl;
cout<<"---------------------------"<<endl;
cout<<" [1]添加货物 [2]删除货物 "<<endl;
cout<<" [3]按编号查询货物 [4]按名称查询货物 "<<endl;
cout<<" [5]显示货物 [0]退出"<<endl;
cout<<"---------------------------"<<endl;
cout<<"请输入0~5的数字选择操作\n";
cin>>i;
switch(i)
{
case '1':
system("CLS");
aa.Add();
break;
case '2':
system("CLS");
aa.Delete();
break;
case '3':
system("CLS");
house.SearchID();
break;
case '4':
system("CLS");
house.SearchName();
break;
case '5':
system("CLS");
house.ShowAllbale();
default:
cout<<"输入错误,请重新输入";
system("pause");
break;
}
}while(i!='0');
return 0;
}