C + + experimental 5--Project 2: Teacher cadre category

Source: Internet
Author: User

One, problem and code

/* File name: Teacher Cadre class. cpp Author: Tang Junpeng Date: 2016.5.6 platform: Visual C + + 6.0 project name: Teacher Cadre class problem details: Define teacher (Teacher) class and CAD respectively Re (cadre) class, using multiple inheritance method from these two classes derived from the new class Teacher_cadre (teachers and cadres). Requirements: (1) The names, age, gender and other data members are included in the two base classes. (2) The teacher class also contains the data member title (title), which also contains the data member post (title) in the Cadre class, and the data member wages (payroll) in the Teacher_cadre class. (3) The name, age, gender 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) In the member function of the derived class Teacher_cadre, call the display function in the teacher class, output the name, age, gender, title, and then use the cout statement to output the job and salary. The code is as follows: */#include <iostream> #include <string>using namespace Std;class teacher{public:teacher (strin g,int,string,string); void display ();p rivate: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 ();p rivate: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, float); void Show (); float get_wages ();p rivate: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) {wages= 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<< "Wages:" <<t.get_wages () < <endl;return 0;}
Second, the results of the operation

Third, experience

this time again learned Multiple-Inheritance Related Applications

Iv. Summary of Knowledge points

Multiple inheritance is a subclass that inherits multiple base classes, and note that constructors sometimes have to be called in the form of parameters to initialize the list, the base class, and the function of the derived class.

C + + experimental 5--Project 2: Teacher cadre category

Related Article

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.