一个class的student项目

艾晋
2023-12-01

话不多说,直接给代码

#include <iostream>
#include <string>
using namespace std;
class student
{
private:
    string name;
    unsigned score;
    bool male;
public:
    student():name(""),score(0),male(true){}
    student(string n,unsigned s,bool m):name(n),score(s),male(m){}
    void SetName(string n)
    {
        name=n;
    }
    void SetScore(unsigned s)
    {
        score=s;
    }
    void SetMale(bool m)
    {
        male=m;
    }
    string GetName()
    {
        return name;
    }
    unsigned GetScore()
    {
        return score;
    }
    bool GetMale()
    {
        return male;
    }
    string GetNMale()
    {
        if(male)
            return "male";
        return "female";
    }
    bool operator<(student s)
    {
        return s.score>score;
    }
    bool operator>(student s)
    {
        return s.score<score;
    }
};
int main()
{
    student s("",100,true);
    student st("",99,false);
    return 0;
}

 类似资料: