第十二周 项目1-教师兼干部类

/*

*Copyright (c) 2015,烟台大学计算机学院

*All rights reserved.

*文件名称:time.cpp

*作者:刘天恩

*完成时间:2015年5月24号

*版本号:v1.0

*问题描述:分别定义Teacher(教师)类和Cadre(干部)类,采用多重继承方式由这两个类派生出新类Teacher_Cadre(教师兼干部)。

要求:

(1)在两个基类中都包含姓名、年龄、性别、地址、电话等数据成员。

(2)在Teacher类中还包含数据成员title(职称),在Cadre类中还包含数据成员post(职务),在Teacher_Cadre类中还包含数据成员wages(工资)。

(3)对两个基类中的姓名、年龄、性别、地址、电话等数据成员用相同的名字,在引用这些数据成员时,指定作用域。

(4)在类体中声明成员函数,在类外定义成员函数。

(5)在派生类Teacher_Cadre的成员函数show中调用Teacher类中的display函数,输出姓名、年龄、性别、职称、地址、电话,然后再用cout语句输出职务与工资。

*输入描述:无

*程序输出:基本信息

*/

#include <iostream>
#include <cstring>
using namespace std;
class Teacher
{
protected:
    string name;  // 姓名
    int age;      // 年龄
    string sex;   //性别
    string address; //地址
    string phone;    //电话
    string title;  //职称
public:
    Teacher(string nam,int ag,string se,string add,string ph,string tit);
    void display();
};
Teacher::Teacher(string nam,int ag,string se,string add,string ph,string tit):
    name(nam),age(ag),sex(se),address(add),phone(ph),title(tit){}
void Teacher::display()
{
    cout<<"姓名"<<name<<endl;
    cout<<"年龄"<<age<<endl;
    cout<<"性别"<<sex<<endl;
    cout<<"地址"<<address<<endl;
    cout<<"电话"<<phone<<endl;
    cout<<"职称"<<title<<endl;
    cout<<endl;
}
class Cadre
{
protected:
    string name;  // 姓名
    int age;      // 年龄
    string sex;   //性别
    string address; //地址
    string phone;    //电话
    string post;  //职务
public:
    Cadre(string nam,int ag,string se,string add,string ph,string po);
    void display();
};
Cadre::Cadre(string nam,int ag,string se,string add,string ph,string po):
    name(nam),age(ag),sex(se),address(add),phone(ph),post(po){}
void Cadre::display()
{
    cout<<"姓名"<<name<<endl;
    cout<<"年龄"<<age<<endl;
    cout<<"性别"<<sex<<endl;
    cout<<"地址"<<address<<endl;
    cout<<"电话"<<phone<<endl;
    cout<<"职务"<<post<<endl;
    cout<<endl;
}
class Teacher_Cadre:public Teacher,public Cadre
{
public:
    Teacher_Cadre(string nam,int ag,string se,string add,string ph,string tit,string po,float w);
    void show();
private:
    float wage;
};
Teacher_Cadre::Teacher_Cadre(string nam,int ag,string se,string add,string ph,string tit,string po,float w):
    Teacher(nam,ag,se,add,ph,tit),Cadre(nam,ag,se,add,ph,po),wage(w) {}
void Teacher_Cadre::show()
{
    Teacher::display();
    cout<<"职务"<<Cadre::post<<endl;
    cout<<"工资"<<wage<<endl;
}
int main()
{
    Teacher_Cadre T("Wang-li",50,"f","135 Beijing Road,Shanghai","(021)61234567","prof.","president",1534.5);
    T.show();
    return 0;
}


运行结果:

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值