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;
} 运行结果:
心得体会:继承的方式不同
知识点总结:多重继承的基类构造函数的使用
上机目的:掌握多重继承
/*
* 文件名称:教师干部类
* 作 者:陈德强
* 完成日期: 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;
} 运行结果:
心得体会:继承的方式不同
知识点总结:多重继承的基类构造函数的使用
相关文章推荐
- C++实现双链表
- C++实现双链表
- C++实现双链表
- 基于C语言EOF与getchar()的使用详解
- 第7周 C语言程序设计(新2版) 练习1-13 打印输入单词长度的直方图(水平与垂直)
- 栈的测试--四则运算表达式求值(C语言)
- C++程序设计语言练习5.1
- C语言 文件操作12--文件加密
- C++中的vector容器对象学习笔记
- C++ typedef用法小结
- iOSDay09C语言函数指针
- iOSDay08之C语言内存管理
- iOSDay07之C语言指针
- 《C程序设计语言》读书笔记及C语言知识备忘
- iOSDay05C语言函数
- iOSDay04C语言数组
- iOSDay03C语言循环结构
- iOSDay02C语言分支结构
- c++ 名字查找
- ios c++混编