本文主要是介绍第十三周 项目二:定义Teacher(教师)类和Cadre(干部)类,采用多重继承方式,派生出Teacher_Cadre(教师兼干部)类,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
/*
* 程序的版权和版本声明部分
* Copyright (c)2012, 烟台大学计算机学院学生
* All rightsreserved.
* 作者: 李洋
* 完成日期: 2013年 5 月 24 日
* 版本号: v1.0
* 输入描述:无
* 问题描述:无
* 程序输出:无
*/
#include <iostream>
#include <string.h>
using namespace std;
class Teacher
{
public:
Teacher(string,int,string,string,long,string);
void display();
protected:
string name;
int age;
string sex;
string address;
long phone;
string title;
};
Teacher::Teacher(string nam,int ag,string se,string addr,long phon,string titl):name(nam),age(ag),sex(se),address(addr),phone(phon),title(titl){}
void Teacher::display()
{
cout<<"name:"<<name<<endl;
cout<<"age:"<<age<<endl;
cout<<"sex:"<<sex<<endl;
cout<<"title:"<<title<<endl;
cout<<"address:"<<address<<endl;
cout<<"phone:"<<phone<<endl;
}
class Cadre
{
public:
Cadre(string,int,string,string,long,string);
protected:
string name;
int age;
string sex;
string address;
long phone;
string post;
};
Cadre::Cadre(string nam,int ag,string se,string addr,long phon,string pos):name(nam),age(ag),sex(se),address(addr),phone(phon),post(pos){}
class Teacher_Cadre: public Teacher,public Cadre
{
public:
Teacher_Cadre(string,int,string,string,long,string,string,float);
void display();
private:
float wages;
};
Teacher_Cadre::Teacher_Cadre(string nam,int ag,string se,string addr,long phon,string titl,string pos,float wage):Teacher(nam,ag,se,addr,phon,titl),Cadre(nam,ag,se,addr,phon,pos),wages(wage){}
void Teacher_Cadre::display()
{
Teacher::display();
cout<<"post:"<<post<<endl;
cout<<"wages:"<<wages<<endl;
}
int main()
{
Teacher_Cadre TC("李洋",20,"m","烟台大学",183888888,"教授","书记",10000);
TC.display();
return 0;
}
这篇关于第十三周 项目二:定义Teacher(教师)类和Cadre(干部)类,采用多重继承方式,派生出Teacher_Cadre(教师兼干部)类的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!