|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
编程要求;定义—个
Pers0n类,包含姓名年龄、
性别、电话等数据成员;
2、虚基类派出 Teacher(教师)类和 Cadre类, Te:
acher中额外数据成员
title,在 Cadre类中
额外包含数据成员post(职务);3、来用多继承方式由
这两个派出出新Teac
her Cadre类,
包含数据成员 wages(工
资);4生成派生类 Teaah
er Cadre 的对象,用 display
函数显示对象信息。
- #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
复制代码
|
|