OJ2476继承与转化

/*
* Copyright (c)2013, 烟台大学计算机学院学生
* All rightsreserved.
* 文件名称: array.cpp
* 作    者:   李中意
* 完成日期:2014  年6 月 11  日
* 版本号: v1.0
* 输入描述:无
*/

#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 y,int m,int d):year(y),month(m),day(d){}
void BirthDate::display()
{
    cout<<"birthday:"<<year<<"/"<<month<<"/"<<day<<endl;
}
void BirthDate::setbirthday(int y,int m,int d)
{
    year=y;
    month=m;
    day=d;
}
Teacher::Teacher(int n,string nam,char s):num(n),name(nam),sex(s){}
void Teacher::display()
{
    cout<<"num:"<<num<<endl;
    cout<<"name:"<<name<<endl;
    cout<<"sex:"<<sex<<endl;
}
Professor::Professor(int n,string nam,char s,BirthDate Birthday):Teacher(n,nam,s),birthday(Birthday){}
void Professor::display()
{
    Teacher::display();
    birthday.display();
}
void Professor::setbirthday(int y,int m,int d)
{
    birthday.setbirthday(y,m,d);
}
/* 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;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值