I. Questions and codes
[CPP] View plain copy/* * File name: Duojiicheng * Author: Xiatinghui * Completion Date: May 8, 2016 * version number: v1.0 * Description of task and solution method Section: No * Input Description: No * Description: Multiple inheritance * Program output: Slightly * problem analysis: slightly * algorithm design: Slightly */#include <string> #include <IOSTREAM&G T using namespace Std; Class Teacher {public:teacher (string nam,int a,string s,string tit); void display (); Protected:string name; int age; string sex; string title; }; Teacher::teacher (string nam,int a,string s,string Tit): Name (NAM), age (a), sex (s), title (tit) {} void Teacher: :d Isplay () {cout<< "name:" <<name<<endl; cout<< "Age:" <<age<<endl; cout<< "Gender:" <<sex<<endl; cout<< "title:" <<title<<endl; } class Cadre {Public:cadre (string nam,int a,string s,string p); void display (); Protected:string name; int age; string sEx String post; }; Cadre::cadre (String nam,int a,string s,string p): Name (NAM), age (a), sex (s), post (p) {} void Cadre::d isplay () {cout<< "name:" <<name<<endl; cout<< "Age:" <<age<<endl; cout<< "Gender:" <<sex<<endl; cout<< "title:" <<post<<endl; } class Teacher_cadre:public Teacher,public cadre {public:teacher_cadre (string nam,int a,string s,st Ring tit,string p,float W); void Show (); Private:float wage; }; Teacher_cadre::teacher_cadre (String nam,int a,string s,string t,string p,float W): Teacher (nam,a,s,t), Cadre (nam,a,s , p), wage (W) {} void Teacher_cadre::show () {Teacher::d isplay (); cout<< "title:" <<cadre::p ost<<endl; cout<< "Salary:" <<wage<<endl; } int main () {Teacher_cadre Te_ca ("Zeng Hui", 42, "male", "Associate Professor", "director", 1534.5); Te_ca.show (); return 0; }
Ii. Results of operation
Third, experience
In the design of multi-inheritance, the concept is a bit confusing, after reading only understand, so-called multi-inheritance refers to the derived class has more than one base class, the relationship between the derived class and each base class can still be considered a single inheritance.
Iv. Summary of Knowledge points
Multiple inheritance As with single inheritance, when multiple inheritance constructs an object of a derived class, you also need to initialize the data members of the base class, the data members of the object, and the new data members.
C + + Fifth experiment-------multiple inheritance