您的位置:首页 > 编程语言 > C语言/C++

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

2016-05-11 17:05 465 查看
上机内容:多重继承派生类的使用

上机目的:掌握多重继承

/*
* 文件名称:教师干部类
* 作 者:陈德强
* 完成日期: 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;
} 运行结果:



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

知识点总结:多重继承的基类构造函数的使用
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: