/* *Copyright (c) 2016,烟台大学计算机学院 *All rights reserved. *文件名称 : *作 者 : 刘云 *完成日期 : 2016年5月8号 *版 本 号 : v6.0 * *问题描述 : 教师兼干部类 *输入描述 : 无 *程序输出 : */ #include<iostream> #include<cstring> using namespace std; class Teacher { public: Teacher(string nam,int a,char c,string ad,long phone,string zhicheng):name(nam),age(a),sex(c),addr(ad),tell(phone),title(zhicheng){} void Teacherdisplay(); string name; int age; char sex; string addr; long tell; string title; }; void Teacher::Teacherdisplay() { cout<<"姓名:"<<name<<endl; cout<<"年龄:"<<age<<endl; cout<<"性别:"<<sex<<endl; cout<<"地址:"<<addr<<endl; cout<<"电话号码:"<<tell<<endl; cout<<"职称:"<<title<<endl; } class Cardre { public: Cardre(string nam,int a,char c,string ad,long phone,string po):name(nam),age(a),sex(c),addr(ad),tell(phone),post(po){} void Cardredisplay(); string getpost(){return post;} string name; int age; char sex; string addr; long tell; string post; }; void Cardre::Cardredisplay() { cout<<"姓名:"<<name<<endl; cout<<"年龄:"<<age<<endl; cout<<"性别:"<<sex<<endl; cout<<"地址:"<<addr<<endl; cout<<"电话号码:"<<tell<<endl; cout<<"职务:"<<post<<endl; } class Teacher_Cardre:public Teacher,public Cardre { public: Teacher_Cardre(string nam,int a,char c,string ad,long phone,double wage,string zhicheng,string po):Teacher(nam,a,c,ad,phone,zhicheng),Cardre(nam,a,c,ad,phone,po),wages(wage){} void showTeacher_Cardre(); string name; int age; char sex; string addr; long tell; double wages; }; void Teacher_Cardre::showTeacher_Cardre() { Teacherdisplay(); cout<<"职务:"<<getpost()<<endl; cout<<"工资:"<<wages<<endl; } int main() { Teacher_Cardre tc("小明",'f',23,"山东省烟台市海港街道",15263642506,2000,"历史老师","级部主任"); tc.showTeacher_Cardre(); return 0; }
运行结果: