14.5继承与组合

来源:互联网 发布:南方所的药品销售数据 编辑:程序博客网 时间:2024/04/25 20:02
/** 程序的版权和版本声明部分* Copyright (c)2013, 烟台大学计算机学院学生* All rightsreserved.* 文件名称:a.cpp* 作    者:孔云* 完成日期:2014年5月29日* 版 本 号: v1.0* 输入描述:num,name,sex,year,month,day 和修改后的year,month,day* 问题描述:(1) BirthDate(生日类) 含有:year,month,day 等数据成员           (2) Teacher(教师类)含有:num,name,sex 等数据成员           (3) Professor(教授类)含有:教师类和生日类的数据成员         要求:           (1)通过对Teacher和BirthDate使用继承和组合的方式设计Professor           (2)定义Professor类对象prof,并给出所有数据的初值           (3)修改prof的生日数据           (4)输出prof的全部最新数据* 输出描述:num,name,sex,year,month,day*/#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<<year<<"/"<<month<<"/"<<day;}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 bd):Teacher(n,nam,s),birthday(bd) {}void Professor::display(){    Teacher::display();    cout<<"birthday:";    birthday.display();}void Professor::setbirthday(int y,int m,int d){    birthday.setbirthday(y,m,d);}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;}

心得体会:学以致用,不要学了不用哦,否则你不会知道教授类中的对象如何修改生日数据奋斗

0 0
原创粉丝点击
热门问题 老师的惩罚 人脸识别 我在镇武司摸鱼那些年 重生之率土为王 我在大康的咸鱼生活 盘龙之生命进化 天生仙种 凡人之先天五行 春回大明朝 姑娘不必设防,我是瞎子 拼多多商品驳回怎么办 京东结算不了怎么办 夏天白酒不好卖怎么办 个人支票丢了怎么办 鼻子长巨大脓包怎么办 微信里怎么提现怎么办 天猫账号被风控怎么办 618津贴不够用怎么办 天猫精灵不灵敏怎么办 淘宝被恶意退款怎么办 天猫红包失效怎么办 预约人数满了怎么办 淘宝签证拒签怎么办 天猫美的差评怎么办 直通车欠费三块怎么办 上海个人户口卡怎么办 网购信息泄露怎么办 单张券达到上限怎么办 未成年偷钱充q币怎么办 被香港中炎骗了怎么办 房东要收回店面怎么办 天猫字迹模糊怎么办 淘宝类目不叫上架怎么办 淘宝直播有延迟怎么办 淘宝直播间中奖怎么办 微信扫码付款后卖家不发货怎么办 淘宝打骚扰电话怎么办 淘宝卖家打骚扰电话怎么办 被商家打了怎么办 保底消费入坑怎么办 留党查看到期怎么办 遭遇淘宝控价怎么办 淘宝店没有了怎么办 淘宝店铺运费险不出单怎么办 闲鱼定金被骗怎么办 肯德基团购过期怎么办 word不可以修改怎么办 店铺预售不发货怎么办 埋件设置不符合怎么办 闲鱼付了款卖家不发货怎么办 微信里付了款卖家不发货怎么办