c++ 练习
迪丽瓦拉
2024-03-29 05:14:33
0

#include

 

using namespace std;

 

 

class Student

{

protected:

    string name;

    int age;

    double score;

 

public:

    Student() {}//无参构造

    Student(string n,int a,double s):name(n),age(a),score(s){}//有参构造

};

 

class Teacher

{

protected:

    int age;

    string tital;

 

public:

    Teacher() {}//无参构造

    Teacher(int a,string t):age(a),tital(t){}//有参构造

 

    void show()

    {

        cout<<"年龄:"<

        cout<<"职称:"<

    }

};

 

class Graduate:public Student,public Teacher

{

protected:

    string sex;

 

public:

    Graduate(string n,int stu_a,double s,int tea_a,string t,string se):Student(n,stu_a,s),Teacher(tea_a,t),sex(se){}

 

 

    void show()

    {

        cout<<"姓名:"<name<

        cout<<"年龄:"<Student::age<

        cout<<"成绩:"<score<

        cout<<"性别:"<sex<

        cout<<"老师年龄:"<Teacher::age<

        cout<<"老师职称:"<tital<

 

    }

};

 

 

int main()

{

    Graduate G("chen",18,100,55,"yuanzhang","man");

    G.show();

    return 0;

}

相关内容