Birthday(生日类)含有:year,month,day 等成员变量Teacher(教师类)含有:nu m,name,sex等成员变量Professor(教授 类)含有教师类和生日类动成员变量 以及research(研究方向)要求:Teache 为基类派生Professor类,Professor类 中包含一个Birthday类对象定义Professor 类对象prof,并给出所有数据动初值输 出profM全部数据)
时间: 2024-01-22 15:21:12 浏览: 61
下面是代码实现:
```c++
#include <iostream>
#include <string>
using namespace std;
class Birthday {
public:
int year;
int month;
int day;
};
class Teacher {
public:
int num;
string name;
char sex;
};
class Professor : public Teacher {
public:
Birthday birthday;
string research;
};
int main() {
Professor prof;
prof.num = 12345;
prof.name = "张三";
prof.sex = 'M';
prof.birthday.year = 1980;
prof.birthday.month = 5;
prof.birthday.day = 20;
prof.research = "计算机科学";
cout << "教工号:" << prof.num << endl;
cout << "姓名:" << prof.name << endl;
cout << "性别:" << prof.sex << endl;
cout << "生日:" << prof.birthday.year << "年" << prof.birthday.month << "月" << prof.birthday.day << "日" << endl;
cout << "研究方向:" << prof.research << endl;
return 0;
}
```
输出结果:
```
教工号:12345
姓名:张三
性别:M
生日:1980年5月20日
研究方向:计算机科学
```
阅读全文