/*
已知类如下:
(1) BirthDate(生日类) 含有:year,month,day 等数据成员
(2) Teacher(教师类)含有:num,name,sex 等数据成员
(3) Professor(教授类)含有:教师类和生日类的数据成员
要求:
(1)通过对Teacher和BirthDate使用继承和组合的方式设计Professor
(2)定义Professor类对象prof,并给出所有数据的初值
(3)修改prof的生日数据
(4)输出prof的全部最新数据
) 在派生类Teacher_Cadre的成员函数show中调用Teacher类中的display函数,输出姓名、年龄、性别、职称、地址、电话,然后再用cout语句输出职务与工资。
*/
#include <iostream>
#include <string>
using namespace std;
class BirthDate {
public:
BirthDate(int,int,int);
void display();
void setbirthday(int,int,int);
private:
int year;
int month;
int day;
};
class Teacher
{
public:
Teacher(int,string,char);
void display();
private:
int num;
string name;
char sex;
};
class Professor:public Teacher
{
public:
Professor(int,string,char,BirthDate);
void display();
void setbirthday(int,int,int);
private:
BirthDate birthday;
};
BirthDate::BirthDate(int a,int b,int c):year(a),month(b),day(c) {}
void BirthDate::display()
{
cout<<"birthday:"<<year<<"/"<<month<<"/"<<day;
}
void BirthDate::setbirthday(int a,int b,int c)
{
year=a;
month=b;
day=c;
}
Teacher::Teacher(int q,string w,char e):num(q),name(w),sex(e) {}
void Teacher::display()
{
cout<<"num:"<<num<<endl;
cout<<"name:"<<name<<endl;
cout<<"sex:"<<sex<<endl;
}
Professor::Professor(int z,string x,char v,BirthDate n):Teacher(z,x,v),birthday(n) {}
void Professor::display()
{
Teacher::display();
birthday.display();
}
void Professor::setbirthday(int a,int b,int c)
{
birthday.setbirthday(a,b,c);
}
int main()
{
int num;
string name;
char sex;
int year,month,day;
cin>>num>>name>>sex;
cin>>year>>month>>day;
Professor prof(num,name,sex,BirthDate(year,month,day));
cin>>year>>month>>day;
prof.setbirthday(year,month,day);
prof.display();
return 0;
}
OJ 1.F
最新推荐文章于 2023-06-03 13:09:19 发布