上机内容:学习类的继承问题
上机目的:学习;
/* * 程序的版权和版本声明部分 * Copyright (c)2012, 烟台大学计算机学院学生 * All rightsreserved. * 文件名称: object.cpp * 作者:刘杰 * 完成日期:2013 年5月 29日 * 版本号: v1.0 * 输入描述:无 * 问题描述: * 程序输出:如下 */ #include<string> #include <iostream> using namespace std; class Teacher { public: Teacher(string na,int ag,char s,string ti,string ad,string te):name(na),age(ag),sex(s),title(ti),address(ad), telephone(te){} void show_Teacher(); protected: string name; int age; char sex; string title; string address; string telephone; }; void Teacher::show_Teacher() { cout<<"姓名: "<<name<<endl; cout<<"年龄: "<<age<<endl; cout<<"性别: "<<sex<<endl; cout<<"职称: "<<title<<endl; cout<<"住址: "<<address<<endl; cout<<"电话: "<<telephone<<endl; } class Cadre { public: Cadre(string na,int ag,char s,string po,string ad,string te):name(na),age(ag),sex(s),post(po),address(ad), telephone(te){} void show_Cadre(); protected: string name; int age; char sex; string address; string post; string telephone; }; void Cadre::show_Cadre() { cout<<"姓名: "<<name<<endl; cout<<"年龄: "<<age<<endl; cout<<"性别: "<<sex<<endl; cout<<"职务: "<<post<<endl; cout<<"住址: "<<address<<endl; cout<<"电话: "<<telephone<<endl; } class Teacher_Cadre:public Teacher,public Cadre { public: Teacher_Cadre(string na,int ag,char s,string ti,string po,string ad,string te,double wa); void show( ); private: double wages; }; Teacher_Cadre::Teacher_Cadre(string na,int ag,char s,string ti,string po,string ad,string te,double wa): Teacher(na,ag,s,ti,ad,te),Cadre(na,ag,s,po,ad,te),wages(wa) {} void Teacher_Cadre::show( ) { Teacher::show_Teacher(); cout<<"职务:"<<Cadre::post<<endl; cout<<"薪金:"<<wages<<endl; } int main( ) { Teacher_Cadre T("奥利奥",28,'m',"prof","president","135 gangchengdongdajie,yantai","(0535)6666666",8888); T.show( ); return 0; }
运行结果: