using namespace std;
int a;
class Student
{
private:
int m_iNo;
string m_sName;
int m_iGrad;
public:
Student(
int no,
string name,
int grad)
{
m_iNo = no;
m_sName = name;
m_iGrad = grad;
}
int getNo()
{
return m_iNo;
}
string getName()
{
return m_sName;
}
int getGrad()
{
return m_iGrad;
}
bool operator==(
int num)
{
if(
0==a)
return m_iNo == num;
if(
1==a)
{
return m_iGrad == num;
}
}
bool operator==(
string name)
{
return m_sName == name;
}
};
ostream&
operator<<(ostream& os, Student& s)
{
os <<
"No:" << s.getNo() <<
" " <<
"name:" << s.getName() <<
" " <<
"grade:" << s.getGrad() << endl;
return os;
}
class StuFindIf
{
private:
int m_low;
int m_high;
public:
StuFindIf(
int low,
int high)
{
m_low = low;
m_high = high;
}
bool operator()(Student& s)
{
return s.getGrad() >= m_low&&s.getGrad() <= m_high;
}
};
class StudentClot
{
private:
vector<Student>v;
public:
void addStu(Student& stu)
{
v.push_back(stu);
}
void find_No(
int no)
{
a =
0;
vector<Student>::iterator s = find(v.begin(), v.end(), no);
if(s!=v.end())
cout << *s << endl;
}
void find_Name(
string name)
{
vector<Student>::iterator s = find(v.begin(), v.end(), name);
while(s != v.end())
{
cout << *s << endl;
s++;
s=find(s, v.end(), name);
}
}
void find_grade(
int grade)
{
a =
1;
vector<Student>::iterator s = find(v.begin(), v.end(), grade);
while (s != v.end())
{
cout << *s << endl;
s++;
s = find(s, v.end(), grade);
}
}
void find_grade_fanwei(
int low,
int high)
{
StuFindIf sf(low, high);
vector<Student>::iterator s = find_if(v.begin(), v.end(), sf);
while (s != v.end())
{
cout << *s << endl;
s++;
s = find_if(s, v.end(), sf);
}
}
};
int main()
{
Student s1(
100,
"zhangsan",
60);
Student s2(
101,
"lisi",
70);
Student s3(
101,
"lisi",
80);
StudentClot mana;
mana.addStu(s1);
mana.addStu(s2);
mana.addStu(s3);
mana.find_Name(
"lisi");
mana.find_No(
100);
mana.find_grade_fanwei(
60,
80);
return 0;
}