在派生类Teacher_Cadre的成员函数show中调用Teacher类中的display函数,输出姓名、年龄、性别、职称、地址、电话、然后再用cout语句输出职务与工资。
时间: 2023-06-16 13:08:14 浏览: 64
假设Teacher类和Teacher_Cadre类的定义如下:
```cpp
#include <iostream>
#include <string>
using namespace std;
class Teacher {
protected:
string name;
int age;
char gender;
string title;
string address;
string phone;
public:
Teacher(string name, int age, char gender, string title, string address, string phone) {
this->name = name;
this->age = age;
this->gender = gender;
this->title = title;
this->address = address;
this->phone = phone;
}
void display() {
cout << "姓名:" << name << endl;
cout << "年龄:" << age << endl;
cout << "性别:" << gender << endl;
cout << "职称:" << title << endl;
cout << "地址:" << address << endl;
cout << "电话:" << phone << endl;
}
};
class Teacher_Cadre : public Teacher {
private:
string duty;
float salary;
public:
Teacher_Cadre(string name, int age, char gender, string title, string address, string phone, string duty, float salary)
: Teacher(name, age, gender, title, address, phone) {
this->duty = duty;
this->salary = salary;
}
void show() {
display();
cout << "职务:" << duty << endl;
cout << "工资:" << salary << endl;
}
};
```
在Teacher_Cadre类的show函数中,可以直接调用Teacher类的display函数来输出姓名、年龄、性别、职称、地址、电话:
```cpp
void Teacher_Cadre::show() {
display();
cout << "职务:" << duty << endl;
cout << "工资:" << salary << endl;
}
```
其中,display函数是Teacher类中的成员函数,可以直接在Teacher_Cadre类的成员函数中调用。