/* (程序头部注释开始)
* 程序的版权和版本声明部分
* Copyright (c) 2011, 烟台大学计算机学院学生
* All rights reserved.
* 文件名称:
* 作 者: 孙建朋
* 完成日期: 2012 年 5 月 9 日
* 版 本 号:
* 对任务及求解方法的描述部分
* 输入描述: (教材P394习题9)分别定义Teacher(教师)类和Cadre(干部)类,采用多重继承方式由这两个类派生出新类Teacher_Cadre(教师兼干部)。
* 问题描述:
* 程序输出:
* 程序头部的注释结束
*/
#include <iostream>
#include <string>
using namespace std;
class Teacther
{
public:
Teacther(string t,string nam,int n, char m,string p,string s):title(t),name(nam),age(n),sex(m),place(p),phone(s){}
void display();
protected:
string title;
string name;
int age;
char sex;
string place;
string phone;
};
void Teacther::display()
{
cout<<"姓名:"<<name<<endl;
cout<<"年龄:"<<age<<endl;
cout<<"性别:"<<sex<<endl;
cout<<"住址:"<<place<<endl;
cout<<"电话:"<<phone<<endl;
cout<<"职称:"<<title<<endl;
}
class Cadre
{
public:
Cadre(string a,string b,int c,char d,string e,int f,string h):title(a),name(b),age(c),sex(d),place(e),phone(f),post(h){}
protected:
string title;
string name;
int age;
char sex;
string place;
int phone;
string post;
};
class Teacther_Cadre:public Teacther,public Cadre
{
public:
Teacther_Cadre(string t,string nam,int n, char m,string p,string s,string a,string b,int c,char d,string e,int f,string h,int q):Teacther(t,nam,n,m,p,s),Cadre(a,b,c,d,e,f,h){wages=q;}
void show();
int wages;
};
void Teacther_Cadre::show()
{
display();
cout<<"职务:"<<post<<endl;
cout<<"工资:"<<wages<<endl;
}
void main()
{
Teacther_Cadre t("教授","小李", 20,'m',"烟台","18253590452","教学", "教师",21,'f',"济南",15457897845,"教学",100000);
t.show();
system("pause");
}
往往觉得程序对了 可是运行于想的总有差距!!