C + + experiment 5-Multiple inheritance

Source: Internet
Author: User

I. Questions and codes

  /* File name: Teacher Cadre class   author    : Chao     date    : 2016.5.11    platform    : Visual C + + 6.0         description of tasks and Solution Methods section:      * Input Description:        * Problem Description: Define teacher (Teacher) class and Cadre (Cadre) class respectively, adopt multiple succession way to derive new class Teacher_cadre (teacher and cadre) by these two classes.    * Program output: Slightly      * problem analysis: slightly      * Algorithm design: slightly */         

#include <iostream> #include <string> using namespace std;      Class Teacher {public:teacher (string,int,string,string);  void display ();      Private:string name;      int age;      string sex;  string title;  };      Teacher::teacher (String na,int a,string s,string ti) {name=na;      Age=a;      Sex=s;  Title=ti;      } 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);  String Get_post ();      Private:string name;      int age;      string sex;  String post;  };  Cadre::cadre (String p) {post=p;  } string Cadre::get_post () {return post; } class Teacher_cadre:public Teacher,public cadre {public:teacher_cadre (string, int, string, String, String, Flo      at);      void Show ();  float get_wages ();    Private  float wages;  }; Teacher_cadre::teacher_cadre (String na,int a,string s,string ti,string p,float W): Teacher (Na,a,s,ti), Cadre (p) {wage  S=w;  } void Teacher_cadre::show () {Teacher::d isplay ();  } float Teacher_cadre::get_wages () {return wages;      } int main () {Teacher_cadre T ("Zeng Hui", 42, "male", "Associate Professor", "director", 1535.5);      T.show ();      cout<< "title:" <<t.cadre::get_post () <<endl;      cout<< "Salary:" <<t.get_wages () <<endl;  return 0;   }

Ii. Results of operation


Third, experience

Iv. Summary of Knowledge points


C + + experiment 5-Multiple inheritance

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.