c++第五次上机实验——教师干部类

上机内容:多重继承派生类的使用

上机目的:掌握多重继承

/* 
* 文件名称:教师干部类 
* 作    者:陈德强  
* 完成日期: 2016 年 5  月 7  日 
* 版 本 号:v1.0 
* 对任务及求解方法的描述部分:略
* 输入描述:略  
* 问题描述:略 
* 程序输出:略 
* 问题分析:略 
* 算法设计:略  
*/ 
#include<iostream>      
#include<string>     
using namespace std;    
class Teacher    
{    
public:    
    Teacher(string n, int a, string s, string ti);    
    void display();    
protected:    
    string name;    
    int age;    
    string sex;            
    string title; 
};    
  
class Cadre    
{    
public:    
    Cadre(string n,int a,string s,string p);    
    void display();    
protected:    
    string name;    
    int age;    
    string sex;           
    string post;
};    
  
class Teacher_Cadre:public Teacher, public Cadre 
{    
public:    
    Teacher_Cadre(string n,int a,string s,string ti,string p,double w);    
    void show();    
protected:    
    double wages;    
};    
  
Teacher::Teacher(string n,int a,string s,string ti)    
{    
    name = n;    
    age = a;    
    sex = s;  
    title = ti;    
}    
  
Cadre::Cadre(string n,int a,string s,string p)    
{    
    name = n;    
    age = a;    
    sex = s;            
    post = p; 
}    
  
void Teacher::display()    
{    
     cout << "姓名: " << name << endl;    
    cout << "年龄: " << age << endl;    
    cout << "性别: " << sex << endl;    
    cout << "职称: " << title << endl;            
}    
  
void Cadre::display()    
{    
    cout << "姓名: " << name << endl;    
    cout << "年龄: " << age << endl;    
    cout << "性别: " << sex << endl;    
    cout << "职称: " << post << endl;      
}    
  
void Teacher_Cadre::show()  
{    
    Teacher::display();    
    cout << "职称: " << Cadre::post << endl; 
    cout << "工资: " << wages << endl;    
}    
Teacher_Cadre::Teacher_Cadre(string n, int a, string s, string ti, string p,double w):Teacher(n, a, s, ti),Cadre(n, a, s, p)    
{    
    wages = w;    
}    
  
int main( )    
{        
    Teacher_Cadre p1("曾辉",42,"男","副教授","主任",1534.5);  
    p1.show();       
    return 0;    
}   
运行结果:

心得体会:继承的方式不同

知识点总结:多重继承的基类构造函数的使用


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值