C++第五次实验
来源:互联网 发布:java 切面 编辑:程序博客网 时间:2024/06/01 09:43
一、问题及代码
/* * 文件名称:exe.cpp * 作 者:刘旭 * 完成日期:2016 年 5 月 20日 * 版 本 号:v1.0 * 对任务及求解方法的描述部分:使用多继承 * 输入描述: 无 * 问题描述: 分别定义Teacher(教师)类和Cadre(干部)类, 采用多重继承方式由这两个类派生出新类Teacher_Cadre(教师兼干部) * 程序输出: 略 * 问题分析: 无 * 算法设计: 无 */ #include <iostream> #include <string> using namespace std; class Teacher { public: Teacher(string n,int a,string s,string t):name(n),age(a),sex(s),title(t){} void display(); private: string name; int age; string sex; string title; }; void Teacher::display() { cout<<"姓名:"<<name<<endl; cout<<"年龄:"<<age<<endl; cout<<"性别:"<<sex<<endl; cout<<"职称:"<<title<<endl; } class Cadre { public: Cadre(string n,int a,string s,string p):name(n),age(a),sex(s),post(p){} void showpost(); void display(); private: string name; int age; string sex; string post; }; void Cadre::showpost() { cout<<"职务:"<<post<<endl; } class Teacher_Cadre:public Teacher,public Cadre { public: Teacher_Cadre(string n1,int a1,string s1,string t,string n2,int a2,string s2,string p,double w):Teacher(n1,a1,s1,t),Cadre(n2,a2,s2,p),wages(w){} void showwages(); void show(Teacher_Cadre &tc); private: double wages; }; void Teacher_Cadre::showwages() { cout<<"工资:"<<wages<<endl; } void Teacher_Cadre::show(Teacher_Cadre &tc) { tc.Teacher::display(); tc.Cadre::showpost(); tc.showwages(); } int main() { Teacher_Cadre tc("曾辉",42,"男","职称","曾辉",42,"男","职务",1535.5); tc.show(tc); return 0; }
二、运行结果
三、心得体会
多继承要注意使用构造函数时的一些注意实项和继承顺序。
四、知识点总结
多继承构造函数使用。
0 0
- 第五次C语言上机实验报告
- 第五次C程序设计实验报告
- 第五次C语言上机实验报告
- C语言第五次上机实验
- 第五次实验
- 第五次上机实验
- 第五次上机实验
- 第五次上机实验
- 第五次上机实验
- 第五次上机实验
- 第五次上机实验
- 第五次实验报告
- 第五次上机实验
- 第五次上机实验
- 第五次上机实验
- 第五次上机实验
- 第五次上机实验
- 第五次上机实验
- 线程与进程
- caffe学习笔记(2): type: "LRN"
- java发http,https请求获取数据
- Spring源码解读-Spring IoC容器初始化之资源定位
- 给大家分享下仿QQ消息页面横向滑出菜单,Item内容较多的情况
- C++第五次实验
- 左连接查询优化
- C语言基础
- Swift-字符串和字符
- 解决魅族layer-list中图片拉伸的bug
- 在Eclipse中在线安装插件SVN和Android studio中配置SVN的一些坑
- 欢迎使用CSDN-markdown编辑器
- android 自定义view
- 解密SparkStreaming运行机制和架构