文章标题

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;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值