The teacher (teacher) class and the Cadre (Cadre) class are defined separately, and the new class Teacher_cadre (teacher and cadre) are derived from these two classes by multiple inheritance methods. Requirements:
(1) in two base classes, they contain data members such as name, age, gender, address, telephone, and so on.
(2) in the teacher class also contains the data member title (title), in the Cadre class also contains the data member post (title),
// Data member wages (payroll) is also included in the Teacher_cadre class.
(3) The name, age, gender, address, telephone and other data members in the two base classes are given the same name, specifying the scope when referencing the data members.
(4) Declare member functions in the class body, and define member functions outside the class.
(5) The display function in the teacher class is called in the member function show of the derived class Teacher_cadre.
// Export your name, age, gender, title, address, phone, and then use the cout statement to export your job title and salary.
#include <iostream>
#include <string>
using namespace Std;
Class Teacher
{
Public
void display ();
Teacher (string n, int a, int s, string ad, String t,string ti)
{
name = N; age = A; sex = s; add = AD; tel = t; title = Ti;
}
Protected
String name;
int age;
int Sex;//1-man 0-women
string add;
String Tel;
string title;
};
void Teacher::d isplay ()
{
cout << "Name:" << name << "Age:" << ages << "Gender:";
if (age = = 0)
cout << "Women";
Else
cout << "man";
cout << "Address:" << add << "Phone:" << tel << endl << "title:" << title << End L
}
Class Cadre
{
Public
void display ();
Cadre (string n, int a, int s, string ad, string t,string p)
{
name = N; age = A; sex = s; add = AD; tel = t; Post = P;
}
Protected
String name;
int age;
int Sex;//1-man 0-women
string add;
String Tel;
String post;
};
/*void cadre::d isplay ()
{
cout << "Name:" << name << "Age:" << ages << "Gender:";
if (age = = 0)
cout << "Women";
Else
cout << "man";
cout << "Address:" << add << "Phone:" << Tel << "title:" << post;
}*/
Class Teacher_cadre:public Teacher,public Cadre
{
Public
void Show ();
Teacher_cadre (string n, int a, int s, string ad, String t, String Ti, String p,float w):
Teacher (n, a, S, ad, T, TI), cadre (n, a, S, AD, T, p)
{
Wages = W;
}
Private
float wages;
};
void Teacher_cadre::show ()
{
Teacher::d isplay ();
cout << "title:" << cadre::p ost << Endl << "Salary:" << wages;
}
int main ()
{
Teacher_cadre A ("Zhang San", 1, "Xiaobude", "10010", "Wage earners", "workers", 10000);
A.show ();
while (1);
}
12th Week Item-1