第十二周实验报告(2)

来源:互联网 发布:软件冲突蓝屏怎么办 编辑:程序博客网 时间:2024/06/05 02:20
/* 程序头部注释开始* 程序的版权和版本声明部分* Copyright (c) 2012, 烟台大学计算机学院学生 * Copyright (c) 2012, 烟台大学计算机学院学生 * All rights reserved.* 文件名称:                         * 作    者:        李瑞                   * 完成日期:  2012 年 5月 6日* 版 本 号:        v1.0* 对任务及求解方法的描述部分* 输入描述:…… * 问题描述:…… * 程序输出:……* 程序头部的注释结束*/
 
/*【任务2】(教材P394习题9)分别定义Teacher(教师)类和Cadre(干部)类,采用多重继承方式由这两个类派生出新类Teacher_Cadre(教师兼干部)。   要求: (1)在两个基类中都包含姓名、年龄、性别、地址、电话等数据成员。 (2)在Teacher类中还包含数据成员title(职称),在Cadre类中还包含数据成员post(职务),在Teacher_Cadre类中还包含数据成员wages(工资)。 (3)对两个基类中的姓名、年龄、性别、地址、电话等数据成员用相同的名字,在引用这些数据成员时,指定作用域。 (4)在类体中声明成员函数,在类外定义成员函数。 (5)在派生类Teacher_Cadre的成员函数show中调用Teacher类中的display函数,输出姓名、年龄、性别、职称、地址、电话,然后再用cout语句输出职务与工资。*/#include<iostream>#include<string>using namespace std;class Teacher{public:Teacher(string n, int a, char s, string add, int te, string ti);void display();protected:string name;int age;char sex;string address;int tel;string title;};class Cadre{public:Cadre(string n, int a, char s, string add, int t, string p);void display();protected:string name;int age;char sex;string address;int tel;string post;};class Teacher_Cadre:public Teacher, public Cadre{public:Teacher_Cadre(string n, int a, char s, string add, int t, string ti, string p,double w);void show();protected:double wages;};Teacher::Teacher(string n, int a, char s, string add, int te, string ti){name = n;age = a;sex = s; address = add;tel = te;title = ti;}Cadre::Cadre(string n, int a, char s, string add, int t, string p){name = n;age = a;sex = s; address = add;tel = t;post = p;}void Teacher::display(){cout << "name: " << name << endl;cout << "age: " << age << endl;cout << "sex: " << sex << endl;cout << "address: " << address << endl;cout << "tel: " << tel << endl;cout << "title: " << title << endl;}void Cadre::display(){cout << "name: " << name << endl;cout << "age: " << age << endl;cout << "sex: " << sex << endl;cout << "address: " << address << endl;cout << "tel: " << tel << endl;cout << "post: " << post << endl;}void Teacher_Cadre::show(){Teacher::display();cout << "post: " << Cadre::post << endl;cout << "wages: " << wages << endl;}Teacher_Cadre::Teacher_Cadre(string n, int a, char s, string add, int t, string ti, string p,double w):Teacher(n, a, s, add, t, ti),Cadre(n, a, s, add, t, p){wages = w;}int main( ){Teacher t1("李", 21, 'm', "泰安", 18253590535, "student");Cadre c1("刘", 20, 'm', "青岛", 18253576744, "League branch secretary ");Teacher_Cadre ct1("时", 21, 'm', "青州", 18253591716, "student", "Director", 6000);t1.display();cout << endl;c1.display();cout << endl;ct1.show();cout << endl;system("pause");return 0;}


结果:

 

原创粉丝点击