1. 程式人生 > >第11周專案1教師兼幹部類

第11周專案1教師兼幹部類

編號及程式碼:
/*
*Copyright(c)2015,煙臺大學計算機與工程學院
*All rights reserved;
*檔名稱:score.cpp
*作者:範星月
*完成日期:2015年5月25日
*版本號:v1.0
*
*問題描述:定義教師和幹部類,採用多重繼承方式有這兩個類派生出新類Teacher_Cadre類
*問題輸入:
*問題輸出:
*/

#include <iostream>

using namespace std;
class Teacher
{
protected:
    string name;
    int age;
    char sex;
    string addr;
   string tele;
    string title;
public:
    Teacher(string n,int a,char s,string ad,string tel,string t):name(n),age(a),sex(s),addr(ad),tele(tel),title(t) {}
    void display();
};
void Teacher::display()
{
    cout<<"姓名:"<<name<<endl;
    cout<<"年齡:"<<age<<endl;
    cout<<"性別:"<<sex<<endl;
    cout<<"住址:"<<addr<<endl;
    cout<<"電話號碼:"<<tele<<endl;
    cout<<"職稱:"<<title<<endl;
}
class Cadre
{
protected:
    string name;
    int age;
    char sex;
    string addr;
   string tele;
    string post;
public:
    Cadre(string n,int a,char s,string ad,string tel,string p):name(n),age(a),sex(s),addr(ad),tele(tel),post(p) {}
    void display();
};
void Cadre::display()
{
    cout<<"姓名:"<<name<<endl;
    cout<<"年齡:"<<age<<endl;
    cout<<"性別:"<<sex<<endl;
    cout<<"住址:"<<addr<<endl;
    cout<<"電話號碼:"<<tele<<endl;
    cout<<"職務:"<<post<<endl;
}
class Teacher_Cadre: public Teacher,public Cadre
{
public:
    Teacher_Cadre(string n,int a,char s,string addr,string tel,string t,string p,double w):
        Teacher(n,a,s,addr,tel,t),Cadre(n,a,s,addr,tel,p),wage(w) {}
    void show();
private:
    double wage;


};
void Teacher_Cadre::show()
{
    Teacher::display();
    cout<<"職務:"<<Cadre::post<<endl;
    cout<<"工資:"<<wage<<endl;
}
int main()
{

  Teacher_Cadre t_c("fanyongfeng",44,'f',"henansheng","123456","banzhang","yisheng",3000);
  t_c.show();
  return 0;
}