int main()
{
vector<book> _book;
vector<student> _stu;
string name;
string id;
int count;
int code;
while(1)
{
cout<<"----------BOOK-------------"<<endl;
cout<<"1 new book"<<endl;
cout<<"2 new user"<<endl;
cout<<"3 borrow book"<<endl;
cout<<"4 return book"<<endl;
cout<<"5 find all record of some student"<<endl;
cout<<"6 find all book"<<endl;
cout<<"----------BOOK-------------"<<endl;
cout<<"input op:";
cin>>code;
//code = getchar();
//code -= 48;
if(code <1 || code >6)
{
cout<<"input error\n";
continue;
}
if(code == 1)
{
cout<<"input book infomation:name(string) count(int)"<<endl;
cin>>name>>count;
_book.push_back(book(name,count));
}
else if(code == 2)
{
cout<<"input student information:name(string)\n";
cin>>name;
_stu.push_back(student(name));
}
else if(code == 3)//brrow
{
cout<<"input student name && book name :";
int flag = 0;
cin>>name>>id;
int i;
for( i=0;i<_stu.size();++i)
{
if(_stu[i].getname() == name)
{
flag = 1;
break;
}
}
if(flag != 1)
cout<<"student "<<name<<"not found\n";
if(0 == _stu.at(i).borrowBook(id,_book))
cout<<"brrowbook sucessful \n";
else
cout<<"brrowbook failed \n";
}
else if(code == 4)//return
{
cout<<"input student name && book name :";
int flag = 0;
cin>>name>>id;
int i;
for( i=0;i<_stu.size();++i)
{
if(_stu[i].getname() == name)
{
flag = 1;
break;
}
}
if(flag != 1)
cout<<"student "<<name<<"not found\n";
if(0 == _stu.at(i).returnBook(id,_book))
cout<<"returnbook sucessful \n";
else
cout<<"returnbook failed \n";
}
else if(code == 5)
{
cout<<"input student name:";
int flag = 0;
cin>>name;
int i;
for( i=0;i<_stu.size();++i)
{
if(_stu[i].getname() == name)
{
_stu.at(i).printAll();
flag = 1;
break;
}
}
if(flag == 0)
cout<<"student "<<name<<"not found"<<endl;
}
else if(code == 6)
{
for(int i=0;i<_book.size();++i)
{
_book.at(i).print();
}
}
}
return 0;
}
不合理的地方在后期需要改进的地方:
取消掉record类,需要加载上bookid和studentid,或者增加继承的结构