鱼C论坛

 找回密码
 立即注册
查看: 1346|回复: 1

[已解决]求助!

[复制链接]
发表于 2022-5-15 10:37:15 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
编程要求;定义—个
Pers0n类,包含姓名年龄、
性别、电话等数据成员;
2、虚基类派出 Teacher(教师)类和 Cadre类, Te:
acher中额外数据成员
title,在 Cadre类中
额外包含数据成员post(职务);3、来用多继承方式由
这两个派出出新Teac
her Cadre类,
包含数据成员 wages(工
资);4生成派生类 Teaah
er Cadre 的对象,用 display
函数显示对象信息。
最佳答案
2022-5-15 11:41:42
#include <iostream>

using std::string;
class Person {
protected:
        string m_name;
        int m_age, m_tel;
};

class Teacher :virtual public Person {
protected:
        string m_title;
};


class Cadre :virtual public Person {
protected:
        string m_post;
};

class TeacherCadre :public Teacher, public Cadre {
public:
        TeacherCadre(string, int, int, string, string, float);
        void display();
protected:
        float m_wages;
};

using std::cout, std::endl;
void TeacherCadre::display() {
        cout
                << m_name << endl
                << m_age << endl
                << m_tel << endl
                << m_title << endl
                << m_post << endl
                << m_wages << endl;
}

TeacherCadre::TeacherCadre(string name, int age, int tel, string title, string post, float wages) {
        m_name = name;
        m_age = age;
        m_tel = tel;
        m_title = title;
        m_post = post;
        m_wages = wages;
}

int main(void) {
        TeacherCadre T("小甲鱼", 88, 123456789, "数学", "教师", 88888);
        T.display();
        return 0;
}
小甲鱼
88
123456789
数学
教师
88888
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2022-5-15 11:41:42 | 显示全部楼层    本楼为最佳答案   
#include <iostream>

using std::string;
class Person {
protected:
        string m_name;
        int m_age, m_tel;
};

class Teacher :virtual public Person {
protected:
        string m_title;
};


class Cadre :virtual public Person {
protected:
        string m_post;
};

class TeacherCadre :public Teacher, public Cadre {
public:
        TeacherCadre(string, int, int, string, string, float);
        void display();
protected:
        float m_wages;
};

using std::cout, std::endl;
void TeacherCadre::display() {
        cout
                << m_name << endl
                << m_age << endl
                << m_tel << endl
                << m_title << endl
                << m_post << endl
                << m_wages << endl;
}

TeacherCadre::TeacherCadre(string name, int age, int tel, string title, string post, float wages) {
        m_name = name;
        m_age = age;
        m_tel = tel;
        m_title = title;
        m_post = post;
        m_wages = wages;
}

int main(void) {
        TeacherCadre T("小甲鱼", 88, 123456789, "数学", "教师", 88888);
        T.display();
        return 0;
}
小甲鱼
88
123456789
数学
教师
88888
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 1 反对 0

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2024-10-5 22:24

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表