c++第六次实验
来源:互联网 发布:5ghz网络设置 编辑:程序博客网 时间:2024/05/20 11:23
一、问题及代码
/*文件名称:sss.cpp * 作 者:谭皓文 * 完成日期:2016年 5月13日 * 版 本 号:v1.0 * 对任务及求解方法的描述部分:分别定义Teacher(教师)类和Cadre(干部)类,采用多重继承方式由这两个类派生出新类Teacher_Cadre(教师兼干部) * 程序输出:略 * 问题分析;略 */ #include<iostream> #include<string> using namespace std; class Teacher { public: Teacher(string n, int a, char s, string add, long int te, string ti); void display(); protected: string name; int age; char sex; string address; long int tel; string title; //职称 }; class Cadre { public: Cadre(string n, int a, char s, string add, long int t, string p); void display(); protected: string name; int age; char sex; string address; long int tel; string post; //职务 }; class Teacher_Cadre:public Teacher, public Cadre //声明多重继承的Teacher_Cadre类 { public: Teacher_Cadre(string n, int a, char s, string add, long int t, string ti, string p,double w); void show(); protected: double wages; }; Teacher::Teacher(string n, int a, char s, string add, long int te, string ti) { name = n; age = a; sex = s; address = add; tel = te; title = ti; } Cadre::Cadre(string n, int a, char s, string add, long int t, string p) { name = n; age = a; sex = s; address = add; tel = t; post = p; } void Teacher::display() { cout << "name: " << name << endl; cout << "age: " << age << endl; cout << "sex: " << sex << endl; cout << "address: " << address << endl; cout << "tel: " << tel << endl; cout << "title: " << title << endl; } void Cadre::display() { cout << "name: " << name << endl; cout << "age: " << age << endl; cout << "sex: " << sex << endl; cout << "address: " << address << endl; cout << "tel: " << tel << endl; cout << "post: " << post << endl; } void Teacher_Cadre::show() //在派生类Teacher_Cadre的成员函数show中调用Teacher类中的display函数 { Teacher::display(); cout << "post: " << Cadre::post << endl; //对两个基类中的数据成员用相同的名字,在引用这些数据成员时,指定作用域 cout << "wages: " << wages << endl; } Teacher_Cadre::Teacher_Cadre(string n, int a, char s, string add, long int t, string ti, string p,double w):Teacher(n, a, s, add, t, ti),Cadre(n, a, s, add, t, p) { wages = w; }
0 0
- C语言第六次上机实验
- 第六次c++实验
- 第六次实验
- 第六次上机实验
- 第六次上机实验
- C++第六次实验
- 第六次上机实验
- C++第六次实验
- 第六次c++实验
- c++第六次实验
- c++第六次实验
- C++第六次实验
- c++第六次实验
- C++第六次实验
- C++第六次实验
- C++第六次实验
- c++第六次实验
- C++第六次实验
- Encoding Convert py
- iOS开发探究--HTTP与HTTPS
- 小而巧的数字压缩算法:zigzag
- css3
- ACM天梯赛练习L1-015. 跟奥巴马一起画方块
- c++第六次实验
- 圆柱类族的设计3
- Eclipse中System.out.println()快捷键?
- JavaAPI之AccessibleObject
- 八皇后求解
- 棋盘
- c++第七次实验
- c++第七次实验
- Android Apktool安装及使用