Teacher(教師)クラスとCadre(幹部)クラスをそれぞれ定義し,多重継承方式を用いてこの2つのクラスから新しいクラスTeacher_Cadre(教師兼幹部)を派生させる.

2715 ワード

/* (        )
*             
* Copyright (c) 2011,             
* All rights reserved.
*     :                              
*       :                                
*     :       2012     5         7      
*      :          


*              
*     : 
*     : 
*     : 
*          
*/
#include  
  
#include  
  
using namespace std;  
  
class Teacher  
{  
public:  
    Teacher(string nam, int a, char s, string tit, string ad, string t) : name(nam), age(a), sex(s), title(tit), addr(ad), tel(t) 
    void display();  
protected:  
    string name;  
    int age;  
    char sex;  
    string title;  
    string addr;  
    string tel;  
};  
  
void Teacher :: display()  
{  
    cout << "name:" << name << endl;  
    cout << "age:" << age << endl;  
    cout << "sex:" << sex << endl;  
    cout << "title:" << title << endl;  
    cout << "addr:" << addr << endl;  
    cout << "tel:" << tel << endl;  
}  
  
class Cadre  
{  
public:  
    Cadre(string nam, int a, char s, string p, string ad, string t) : name(nam), age(a), sex(s), post(p), addr(ad), tel(t){}
    void display();  
protected:  
    string name;  
    int age;  
    char sex;  
    string post;  
    string addr;  
    string tel;  
};  
  
void Cadre :: display()  
{  
    cout << "name:" << name << endl;  
    cout << "age:" << age << endl;  
    cout << "sex:" << sex << endl;  
    cout << "post:" << post << endl;  
    cout << "addr:" << addr << endl;  
    cout << "tel:" << tel << endl;  
}  
  
class Teacher_Cadre : public Teacher, public Cadre  
{  
public:  
    Teacher_Cadre(string nam, int a, char s, string tit, string p, string ad, string t, float w) : Teacher(nam, a, s, tit, ad, t), Cadre(nam, a, s, p, ad, t), wages(w){}  //      
    void show();  
private:  
    float wages;  
};  
  
void Teacher_Cadre :: show()  
{  
    Teacher :: display();  
 //     teacher  
cout << "post:"<< Cadre::post << endl;//役割ドメインCadreクラスcout<"wages:"<休みに帰ってきてたくさん忘れました