10th, 11 weeks-item 4-Teacher and cadre category

Source: Internet
Author: User

Questions and codes:

/*copyright (c) 2016, *all Rights reserved, School of computer and Control engineering, Yantai University. * File name: Main.cpp * Author: Wang * completion date: May 10, 2016 * Version number: v1.0 * Description of the problem: the teacher (teacher) class and the Cadre (Cadre) class are defined separately, and the new class is derived from these two classes using multiple inheritance methods Teacher_ Cadre (teacher and cadre).           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. * Input Description: * Output Description: */#include <iostream> #include <string>using namespace Std;class teacher{protected:string na    Me    int age;    char sex;    String addr;    String Tele;    String Title;public:teacher (String,int, char, String, String, string); void display ();}; Teacher::teacher (String n,int a,char s,string ad,string tel,string titl): Name (n), age (a), sex (s), addr (AD), Tele (tel), Title (TITL) {}void Teacher::d isplay () {cout<< "name:" <<name<<endl;    cout<< "Age:" <<age<<endl;    cout<< "Gender:" <<sex<<endl;    cout<< "title:" <<title<<endl;    cout<< "Address:" <<addr<<endl; cout<< "Tel:" &LT;&LT;TELE&LT;&LT;ENDL;}    class cadre{protected:string name;    int age;    char sex;    String addr;    String Tele;    String Pose;public:cadre (String,int, char, String, String, string); void display ();}; Cadre::cadre (String n,int a,char s,string ad,string tel,string p): Name (n), age (a), sex (s), addr (AD), Tele (tel), pose (p) {}    void cadre::d isplay () {cout<< "name:" <<name<<endl;    cout<< "Age:" <<age<<endl;    cout<< "Gender:" <<sex<<endl;    cout<< "Address:" <<addr<<endl;    cout<< "Tel:" <<tele<<endl; cout<< "Duties:" &LT;&LT;POSE&LT;&LT;ENDL;} Class Teacher_cadre:public Teacher,public cadre{private:float wages;public:teacher_cadre (String,int, Char, stri Ng, String, String, string, float); void Show ();}; Teacher_cadre::teacher_cadre (String n,int a,char s,string ad,string tel,string titl, String p,float W): Teacher (N,a,s,ad    , TEL,TITL), cadre (n,a,s,ad,tel,p), Wages (w) {}void teacher_cadre::show () {Teacher::d isplay ();    cout<< "title:" <<cadre::p ose<<endl; cout<< "wages:" &LT;&LT;WAGES&LT;&LT;ENDL;}    int main () {Teacher_cadre TC ("Lizhao", +, ' f ', "Taian Feicheng", "17853535000", "Npy", "Xhwyl", 10000);    Tc.show (); return 0;}

Operation Result:

Learning experience:

The constructor is very cumbersome to write.

10th, 11 weeks-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.