//管理学生名册
#include <iostream>
#include <map>
#include <string>
using namespace std;
struct student
{
string id;
string name;
int grade;
};
int main()
{
map<string,student> stubook;
student stu;
cout<<"--creat student book--"<<endl;
for(int i=0;i<2;i++)
{
cin>>stu.id;
cin>>stu.name;
cin>>stu.grade;
stubook[stu.id]=stu;
}
//判断student book是否为空
if(stubook.empty()) cout<<"stubook is empty!"<<endl;
else cout<<"stubook isnot empty!"<<stubook.size()<<endl;
//输出student book
cout<<"---print student book--"<<endl;
map<string,student>::iterator iter=stubook.begin();
for( ;iter!=stubook.end();iter++)
{
cout<<"student book:"<<iter->second.id<<" - "<<iter->second.name<<" -"<<iter->second.grade<<endl;
}
//查找学生
cout<<"---find a student(please input studentid)--"<<endl;
string studentid;
cin>>studentid;
iter=stubook.find(studentid);
if(iter==stubook.end())
{
cout<<"cannot find: "<<studentid<<endl;
}
else
{
cout<<"student: "<<iter->second.id<<" - "<<iter->second.name<<" - "<<iter->second.grade<<endl;
cout<<"do you want to delete the student (y/n):"<<endl;
char c;
cin>>c;
if(c=='y')
{
stubook.erase(studentid);
}
}
//输出student book
cout<<"---print student book--"<<endl;
map<string,student>::iterator iter2=stubook.begin();
for( ;iter2!=stubook.end();iter2++)
{
cout<<"student book:"<<iter2->second.id<<" - "<<iter2->second.name<<" -"<<iter2->second.grade<<endl;
}
return 0;
}