/* *Copyright (c)2014,烟台大学计算机与控制工程学院 *All rights reserved. *文件名称:d.cpp *作 者:张旺华 *完成日期:2015年6月1日 *版 本 号:v1.0 */ #include <iostream> using namespace std; class Person { public: Person(string nam,int a,char s,string ad,string t):name(nam),age(a),sex(s),addr(ad),tel(t) {} ~Person(); void show(); protected : string name; int age; char sex; string addr; string tel; }; Person:: ~Person() {} void Person::show() { cout<<"name:"<<name<<endl; cout<<"age"<<age<<endl; cout<<"sex:"<<sex<<endl; cout<<"address:"<<addr<<endl; cout<<"tel:"<<tel<<endl; } class Teacher: virtual public Person { public: Teacher(string nam,int a,char s,string tit,string ad,string t):Person(nam,a,s,ad,t),title(tit){} ~Teacher(); string gettitle() {return title;} void show(); protected: string title; }; Teacher::~Teacher(){} void Teacher::show() { Person::show(); cout<<"title"<<title<<endl; } class Cadre:virtual public Person { public: Cadre(string nam,int a,char s,string ad,string t,string p):Person(nam,a,s,ad,t),post(p){} ~Cadre(); string getpost() const {return post;} void show(); protected: string post; }; Cadre::~Cadre(){} void Cadre::show() { Person::show(); cout<<"post "<<post<<endl; } class Teacher_Cadre:public Teacher,public Cadre { public: Teacher_Cadre(string nam,int a,char s,string t,string p,string ad,string tel,double w); ~Teacher_Cadre(); void show(); protected: double wage; }; Teacher_Cadre::~Teacher_Cadre(){} Teacher_Cadre::Teacher_Cadre(string nam,int a,char s,string t,string p,string ad,string tel,double w): Person(nam,a,s,ad,t), Teacher(nam,a,s,t,ad,tel),Cadre(nam,a,s,p,ad,tel),wage(w) {} void Teacher_Cadre::show() { Person::show(); cout<<"wages"<<Cadre::getpost()<<endl; cout<<"title"<< Teacher::gettitle()<<endl; } int main( ) { Teacher_Cadre te_ca("Wang-li",50,'f',"prof.","president","135 Beijing Road,Shanghai","(021)61234567",1534.5); te_ca.show( ); return 0; }
原文地址:http://blog.csdn.net/wh201458501106/article/details/46318511