问题及代码:
/*copyright(c)2016.烟台大学计算机学院
* All rights reserved,
* 文件名称:text.Cpp
* 作者:吴敬超
* 完成日期:2016年5月4日
* 版本号:codeblock
*
* 问题描述: 教师兼干部类
* 输入描述:
* 程序输出: 输出结果
*/
#include<iostream>
using namespace std;
class Teacher
{
public:
Teacher(string nam,int a,char s,string add,int nu,string ti);
void display();
protected:
string name;
int age;
char sex;
string addr;
int num;
string title;
};
Teacher::Teacher(string nam,int a,char s,string add,int nu,string ti)
{
name=nam;
age=a;
sex=s;
addr=add;
num=nu;
title=ti;
}
void Teacher::display()
{
cout<<"姓名:"<<name<<endl;
cout<<"年龄:"<<age<<endl;
cout<<"性别:"<<sex<<endl;
cout<<"地址:"<<addr<<endl;
cout<<"电话:"<<num<<endl;
cout<<"职务:"<<title<<endl;
}
class Cadre
{
public:
Cadre(string nam,int a,char s,string add,int nu,string ti);
void display();
protected:
string name;
int age;
char sex;
string addr;
int num;
string post;
};
Cadre::Cadre(string nam,int a,char s,string add,int nu,string ti)
{
name=nam;
age=a;
sex=s;
addr=add;
num=nu;
post=ti;
}
void Cadre::display()
{
cout<<"姓名:"<<name<<endl;
cout<<"年龄:"<<age<<endl;
cout<<"性别:"<<sex<<endl;
cout<<"地址:"<<addr<<endl;
cout<<"电话:"<<num<<endl;
cout<<"职务:"<<post<<endl;
}
class Teacher_Cadre:public Teacher,public Cadre
{
public:
Teacher_Cadre(string nam,int a,char s,string add,int nu,string ti,string p,double w);
void show();
private:
double wages;
};
Teacher_Cadre::Teacher_Cadre(string nam,int a,char s,string add,int nu,string ti,string p,double w):Teacher(nam,a,s,add,nu,ti),Cadre(nam,a,s,add,nu,p),wages(w){}
void Teacher_Cadre::show()
{
Teacher::display();
cout<<"职务:"<<Cadre::post<<endl;
cout<<"薪资:"<<wages<<endl;
}
int main( )
{
Teacher_Cadre te_ca("wangli",20,'f',"Beijing shanghai road",12456789,"prof","president",1526);
te_ca.show( );
return 0;
}
运行结果: