/*Copyright (c) 2016,烟台大学计算机学院 *All rights reserved. *文件名称 : *作 者 : 田志伟 *完成日期 : 2016年5月10号 *版 本 号 : v1.0 * *问题描述 : 教师兼干部类 *输入描述 : *程序输出 : 教师信息 */ #include <iostream> using namespace std; class Teacher { protected: int age; string name; string addr; string title; string sex; int tel; public: Teacher(int a,string n,string ad,string t,string s,int te); void display(); }; Teacher::Teacher(int a,string n,string ad,string t,string s,int te) { age=a; name=n; addr=ad; title=t; sex=s; tel=te; } void Teacher::display() { cout<<"年龄为:"<<age<<endl; cout<<"姓名为:"<<name<<endl; cout<<"地址为:"<<addr<<endl; cout<<"科目为:"<<title<<endl; cout<<"性别为:"<<sex<<endl; cout<<"电话为:"<<tel<<endl; } class Cadre { protected: int age; string name; string addr; string post; string sex; int tel; public: Cadre(int a,string n,string ad,string p,string s,int te); }; Cadre::Cadre(int a,string n,string ad,string p,string s,int te) { age=a; name=n; addr=ad; post=p; sex=s; tel=te; } class Teacher_Cadre:public Teacher,public Cadre { private: double wages; public: Teacher_Cadre(int a,string n,string ad,string p,string t,string s,int te,double wa); void display(); }; Teacher_Cadre::Teacher_Cadre(int a,string n,string ad,string p,string t,string s,int te,double wa):Teacher(a,n,ad,t,s,te),Cadre(a,n,ad,p,s,te),wages(wa){} void Teacher_Cadre::display() { Teacher::display(); cout<<"职务为:"<<post<<endl; cout<<"佣金为:"<<wages<<endl; } int main() { Teacher_Cadre f1(40,"laowang","shandongsheng zhaoyuanshi ","qingjiegong","tiyu","woman",10086,250); f1.display(); }
程序运行:
时间: 2024-10-06 02:57:54