C++第五次实验-------多继承
来源:互联网 发布:winpe启动盘制作软件 编辑:程序博客网 时间:2024/05/18 13:10
一、问题及代码
[cpp] view plain copy/* * 文件名称: duojiicheng * 作 者:夏廷辉 * 完成日期: 2016 年 5 月 8 日 * 版 本 号:v1.0 * 对任务及求解方法的描述部分:无 * 输入描述: 无 * 问题描述: 多继承 * 程序输出: 略 * 问题分析: 略 * 算法设计: 略 */ #include<string> #include <iostream> using namespace std; class Teacher { public: Teacher(string nam,int a,string s,string tit); void display(); protected: string name; int age; string sex; string title; }; Teacher::Teacher(string nam,int a,string s,string tit): name(nam),age(a),sex(s),title(tit) { } void Teacher::display() { cout<<"姓名:"<<name<<endl; cout<<"年龄:"<<age<<endl; cout<<"性别:"<<sex<<endl; cout<<"职称:"<<title<<endl; } class Cadre { public: Cadre(string nam,int a,string s,string p); void display(); protected: string name; int age; string sex; string post; }; Cadre::Cadre(string nam,int a,string s,string p): name(nam),age(a),sex(s),post(p) {} void Cadre::display() { cout<<"姓名:"<<name<<endl; cout<<"年龄:"<<age<<endl; cout<<"性别:"<<sex<<endl; cout<<"职称:"<<post<<endl; } class Teacher_Cadre:public Teacher,public Cadre { public: Teacher_Cadre(string nam,int a,string s,string tit,string p,float w); void show( ); private: float wage; }; Teacher_Cadre::Teacher_Cadre(string nam,int a,string s,string t,string p,float w): Teacher(nam,a,s,t),Cadre(nam,a,s,p),wage(w) {} void Teacher_Cadre::show( ) { Teacher::display(); cout<<"职称:"<<Cadre::post<<endl; cout<<"薪水:"<<wage<<endl; } int main( ) { Teacher_Cadre te_ca("曾辉",42,"男","副教授","主任",1534.5); te_ca.show( ); return 0; }
二、运行结果
三、心得体会
进行多继承的程序设计时,概念有点混乱,看书后才有所理解,所谓多继承是指派生类具有多个基类,派生类与每个基类之间的关系仍可看作是一个单继承。
四、知识点总结
多继承同单继承一样,多继承构造派生类的对象时,也需要对基类的数据成员、对象的数据成员和新增数据成员进行初始化工作。
0 0
- C++第五次实验-------多继承
- c++第五次实验--多继承
- C++第五次实验—多继承 作业
- c++第五次实验——多继承
- 第五次C语言上机实验报告
- 第五次C程序设计实验报告
- 第五次C语言上机实验报告
- C语言第五次上机实验
- 第五次实验代码(其他班)——继承多态
- 第五次实验
- 第五次上机实验
- 第五次上机实验
- 第五次上机实验
- 第五次上机实验
- 第五次上机实验
- 第五次上机实验
- 第五次实验报告
- 第五次上机实验
- 求学的最后阶段,来一场说走就走的旅行,那该是一件多惬意的事
- 【Cocos2d-x(2)】魔塔MagicTown第二章之人物篇
- matlab2014a中help与参考页翻译 Tutorials – workspace variables
- java集合15--set架构
- 语法篇7之clr属性
- C++第五次实验-------多继承
- 语法篇8之特性
- Cent OS JDK8安装
- matlab2014a中help与参考页翻译 Character Strings
- Android Button
- JDBC查询数据库中的数据
- 进程与线程之间的区别及联系
- 手机移动端WEB资源整合
- Android Handler Message 在使用多个Handler时,接收不到消息的处理办法