第十一周【项目4- 教师兼干部类】
2016-05-16 20:00
316 查看
<pre name="code" class="cpp">/* *Copyright(c) 2016, 烟台大学计算机与控制工程学院 *All rights reserved. *文件名称:main.cpp *作 者:张珩瑞 *完成日期:2016年5月16日 *版本号: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<cmath> using namespace std; class Teacher { public: Teacher(string n1,int a1,string sex1,string ad1,string te1,string title1); void display(); private: string name; int age; string sex; string adress; string tellnum; string title; }; Teacher::Teacher(string n1,int a1,string sex1,string ad1,string te1,string title1) { name=n1; age=a1; sex=sex1; adress=ad1; tellnum=te1; title=title1; } void Teacher::display() { cout<<"姓名:"<<name<<endl; cout<<"年龄:"<<age<<endl; cout<<"性别:"<<sex<<endl; cout<<"地址:"<<adress<<endl; cout<<"电话:"<<tellnum<<endl; cout<<"职称:"<<title<<endl; } class Carde { public: Carde(string cn,int ca,string csex,string cad,string ctell,string cpost); string getPost(); void display(); private: string name; int age; string sex; string adress; string tellnum; string post; }; Carde::Carde(string cn,int ca,string csex,string cad,string ctell,string cpost) { name=cn; age=ca; sex=csex; adress=cad; tellnum=ctell; post=cpost; } string Carde::getPost() { return post; } void Carde::display() { cout<<endl; cout<<"干部信息"<<endl; cout<<"姓名:"<<name<<endl; cout<<"年龄:"<<age<<endl; cout<<"性别:"<<sex<<endl; cout<<"地址:"<<adress<<endl; cout<<"电话:"<<tellnum<<endl; cout<<"职务:"<<post<<endl; cout<<endl; } class Teacher_Carde:public Teacher,public Carde { public: Teacher_Carde(double wage,string n1,int a1,string sex1,string ad1,string te1,string title1,string cn,int ca,string csex,string cad,string ctell,string cpost); void show(); private: double wages; }; Teacher_Carde::Teacher_Carde(double wage,string n1,int a1,string sex1,string ad1,string te1,string title1,string cn,int ca,string csex,string cad,string ctell,string cpost):Teacher(n1,a1,sex1,ad1,te1,title1),Carde(cn,ca,csex,cad,ctell,cpost) { wages=wage; } void Teacher_Carde::show() { string a; cout<<"教师干部信息"<<endl; Teacher::display(); a=getPost(); cout<<"职务:"<<a<<endl; cout<<"工资:"<<wages<<endl; } int main() { Teacher_Carde s(8000,"贺老师",40,"男","烟台市莱山区烟台大学","17853535353","教授","贺老师",40,"男","烟台市莱山区烟台大学","17853535353","主任"); cout<<"教师信息"<<endl; s.Teacher::display(); s.Carde::display(); s.Teacher_Carde::show(); return 0; }
相关文章推荐
- 用logrotate管理每日增长的日志
- linux关于readlink函数获取运行路径的小程序
- Java---基于TCP协议的相互即时通讯小程序
- boost---shared_ptr笔记
- CSDN Latex 一些数学符号
- Python - 两圆相交求交点坐标
- kill -HUP pid
- MacOS虚拟机安装VMware tools 在主机与虚拟机之间共享文件和剪贴板
- JFrame中设置背景图片
- JTextField判断幸运数
- gcc&makefile
- 用C++实现堆排序
- NYOJ 42 一笔画问题(欧拉定理&&并查集)
- POJ 1837 Balance 类似01背包
- Intel官方的处理器识别工具软件
- hdu4712Hamming Distance(随机大法好)
- 计算机网络-----为什么同时需要IP地址和MAC地址
- `这个符号在mysql中的作用
- SDUT3333数据结构实验之栈六:下一较大值(二)
- hive 的优化