* 程序头部注释开始* 程序的版权和版本声明部分
* Copyright (c) 2011, 烟台大学计算机学院学生
* All rights reserved.* 文件名称:
* 作 者: 时永杰
* 完成日期:2012 年 4月 22日
* 版 本 号:v1.1
【任务2】(教材P394习题9)分别定义Teacher(教师)类和Cadre(干部)类,采用多重继承方式由这两个类派生出新类Teacher_Cadre(教师兼干部)。要求:#include <iostream> #include <string>
namespace std; class Teacher { public: Teacher(string n,char s,int a,string t,string adr,string tit):name(n),sex(s),age(a),tel(t),adress(adr),title(tit){} void show(); protected: string name; char sex; int age; string tel; string adress; string title; }; class Carder { public: Carder(string n,char s,int a,string t,string adr,string p):name(n),sex(s),age(a),tel(t),adress(adr),post(p){} void show(); protected: string name; char sex; int age; string tel; string adress; string post; }; class Teacher_Carder:public Teacher,public Carder { public: Teacher_Carder(string n,char s,int a,string t,string ade,string tit,string p,int w):Teacher(n,s,a,t,ade,tit),Carder(n,s,a,t,ade,p) { wages=w; }; void show(); private: int wages; }; void Teacher::show() { cout<<"name:"<<name<<" age:"<<age<<" sex:"<<sex<<" aderss:"<<adress<<" title:"<<title<<endl; } void Carder::show() { cout<<"name:"<<name<<" age:"<<age<<" sex:"<<sex<<" aderss:"<<adress<<" post:"<<post<<endl; } void Teacher_Carder::show() { cout<<"name:"<<Teacher::name<<" age:"<<Teacher::age<<" sex:"<<Teacher::sex<<" aderss:"<<Teacher::adress<<" title:"<<title<<" post:"<<post<<" wages:"<<wages<<endl; } int main() { Teacher_Carder stu1("shiyongjie",'m',21,"18253591716","china","student","no",0); stu1.Teacher::show(); stu1.Carder::show(); stu1.show(); system("pause"); return 0; }