鱼C论坛

 找回密码
 立即注册
查看: 1209|回复: 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
  1. #include <iostream>

  2. using std::string;
  3. class Person {
  4. protected:
  5.         string m_name;
  6.         int m_age, m_tel;
  7. };

  8. class Teacher :virtual public Person {
  9. protected:
  10.         string m_title;
  11. };


  12. class Cadre :virtual public Person {
  13. protected:
  14.         string m_post;
  15. };

  16. class TeacherCadre :public Teacher, public Cadre {
  17. public:
  18.         TeacherCadre(string, int, int, string, string, float);
  19.         void display();
  20. protected:
  21.         float m_wages;
  22. };

  23. using std::cout, std::endl;
  24. void TeacherCadre::display() {
  25.         cout
  26.                 << m_name << endl
  27.                 << m_age << endl
  28.                 << m_tel << endl
  29.                 << m_title << endl
  30.                 << m_post << endl
  31.                 << m_wages << endl;
  32. }

  33. TeacherCadre::TeacherCadre(string name, int age, int tel, string title, string post, float wages) {
  34.         m_name = name;
  35.         m_age = age;
  36.         m_tel = tel;
  37.         m_title = title;
  38.         m_post = post;
  39.         m_wages = wages;
  40. }

  41. int main(void) {
  42.         TeacherCadre T("小甲鱼", 88, 123456789, "数学", "教师", 88888);
  43.         T.display();
  44.         return 0;
  45. }
复制代码
  1. 小甲鱼
  2. 88
  3. 123456789
  4. 数学
  5. 教师
  6. 88888
复制代码
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

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

  2. using std::string;
  3. class Person {
  4. protected:
  5.         string m_name;
  6.         int m_age, m_tel;
  7. };

  8. class Teacher :virtual public Person {
  9. protected:
  10.         string m_title;
  11. };


  12. class Cadre :virtual public Person {
  13. protected:
  14.         string m_post;
  15. };

  16. class TeacherCadre :public Teacher, public Cadre {
  17. public:
  18.         TeacherCadre(string, int, int, string, string, float);
  19.         void display();
  20. protected:
  21.         float m_wages;
  22. };

  23. using std::cout, std::endl;
  24. void TeacherCadre::display() {
  25.         cout
  26.                 << m_name << endl
  27.                 << m_age << endl
  28.                 << m_tel << endl
  29.                 << m_title << endl
  30.                 << m_post << endl
  31.                 << m_wages << endl;
  32. }

  33. TeacherCadre::TeacherCadre(string name, int age, int tel, string title, string post, float wages) {
  34.         m_name = name;
  35.         m_age = age;
  36.         m_tel = tel;
  37.         m_title = title;
  38.         m_post = post;
  39.         m_wages = wages;
  40. }

  41. int main(void) {
  42.         TeacherCadre T("小甲鱼", 88, 123456789, "数学", "教师", 88888);
  43.         T.display();
  44.         return 0;
  45. }
复制代码
  1. 小甲鱼
  2. 88
  3. 123456789
  4. 数学
  5. 教师
  6. 88888
复制代码
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 1 反对 0

使用道具 举报

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

本版积分规则

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

GMT+8, 2024-5-20 17:39

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

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