Tenth week 11th week on the Machine Practice project-Item 4-Teacher and cadre category

Source: Internet
Author: User

/*copyright (c) 2016. College of Computer Science, Yantai University * All rights reserved, * file name: text. CPP * Liu Tao * completion date: May 9, 2016 * version number: vc++6.0 * Description of the problem: the teacher (teacher) class and the Cadre (cadre) category are defined separately, and the new class Teacher_cadre (teachers and cadres) are derived from these two classes using multiple inheritance methods.  Requirements: (1) in two base classes include name, age, gender, address, telephone and other data members.  (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, 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) In the member function of the derived class Teacher_cadre, call the display function in the teacher class, output name, age, gender, title, address, phone, and then use the cout statement to output the job and salary. */#include <iostream> #include <cstring> using namespace std;    Class Teacher {private:string name;    int age;    string sex;    string address;    Long PhoneNumber;     string title;     Title Public:teacher (String nam,int a,string se,string addr,long phonenum,string ti); void display (); };     Teacher::teacher (String nam,int a,string se,string addr,long phonenum,string ti) {name=nam;     Age=a;     Sex=se;     ADDRESS=ADDR;     Phonenumber=phonenum; Title=ti;  } void Teacher::d isplay () {   cout<< "Name:" <<name<<endl;     cout<< "Age:" <<age<<endl;     cout<< "Gender:" <<sex<<endl;     cout<< "Address:" <<address<<endl;     cout<< "Phone number:" <<phoneNumber<<endl; cout<< "title:" <<title<<endl;} /*----------------------------------------------------------------------------------------*/class Cadre {string    Name    int age;    string sex;    string address;    Long PhoneNumber;      String post;    Title Public:cadre (String nam,int a,string se,string addr,long phonenum,string po);    void display (); String Getpost ();  };     Cadre::cadre (String nam,int a,string se,string addr,long phonenum,string po) {Name=nam;     Age=a;     Sex=se;     ADDRESS=ADDR;     Phonenumber=phonenum; Post=po;     } void Cadre::d isplay () {cout<< "name:" <<name<<endl;     cout<< "Age:" <<age<<endl;     cout<< "Gender:" <<sex<<endl; cout<< "Address:" &LT;&Lt;address<<endl;     cout<< "Phone number:" <<phoneNumber<<endl; cout<< "title:" <<post<<endl;} String Cadre::getpost () {return post;}/*------------------------------------------------------------------------- --------------------------*/class Teacher_cadre:public teacher,public cadre {private:double wages;public:teacher_ Cadre (string nam,int a,string se,string addr,long phonenum,string ti,string po,double WAG): Teacher (nam,a    , Se,addr,phonenum,ti), cadre (NAM,A,SE,ADDR,PHONENUM,PO), wages (WAG) {} void Show (); Double Getwages ();     };d ouble Teacher_cadre::getwages () {return wages;} void Teacher_cadre::show () {cout<< "output teacher Info" <<endl;     Teacher::d isplay ();     cout<<endl;     cout<< "cadre Position:" <<cadre::getpost () <<endl; cout<< "Teacher and cadre Salary:" <<getwages () <<endl;}     int main () {Teacher_cadre tc ("Liu Tao", "Man", "Naka Ward, Jinan, Shandong Province", 12345, "President", "CEO", 100000); Tc.show (); The result of the operation:
Summary of Knowledge points:
Multiple inheritance, a derived class of two base classes.
Also, when the function name is the same, the call needs to add the class name:: Make a distinction.
When the data member is private, the call requires the use of a member function. Or a data member is declared as a protected type.
Learning experience:
When there are more than one class, the function name or data member name should not be reused, so as to avoid errors.
When duplicate names are declared in a derived class, it is possible to differentiate directly with the base class name without repeating the definition.
Learning experience:

Tenth week 11th week on the Machine Practice project-Item 4-Teacher and cadre category

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.