11th Week Project 4-Teacher and cadre category

Source: Internet
Author: User

Questions and codes:

/* *copyright (c) 2016, *all right reserved, school of computer and Control engineering, Yantai University. * File name: 77.cpp * Author: Dong Kai * Date of Completion: May 6, 2016 * version number: v1.0 * * Problem Description: Define teacher (Teacher) class and Cadre (Cadre) class respectively, and use multiple inheritance method to derive new class from these two classes Teacher_cadre ( Teachers and cadres). 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: * Program output: */#include <iostream> #include <cstring>using namespace Std;class teacher{public:teacher (str    ing nam,int a,char s,string tit,string ad,string t);    void display ();p rotected:string name;    int age;    char sex;    string title;    String addr; string Tel;}; Teacher::teacher (String nam,int a,char s,string tit,string ad,string t): Name (NAM), age (a), sex (s), title (tit), addr (AD),    Tel (t) {} 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:" <<tel<<endl;        } class Cadre {Public:cadre (string nam,int a,char s,string p,string ad,string t);    void display ();        Protected:string name;        int age;        char sex;        String post;        String addr;    String Tel;    };    Cadre::cadre (String nam,int a,char s,string p,string ad,string t): Name (NAM), age (a), sex (s), post (p), addr (AD), tel (t) {}    void cadre::d isplay () {cout<< "name:" <<name<<endl;    cout<< "Age" <<age<<endl;    cout<< "Gender:" <<sex<<endl;    cout<< "Position:" <<post<<endl;    cout<< "Address:" <<addr<<endl; cout<< "Tel:" &LT;&LT;TEL&LT;&LT;ENDL;} Class Teacher_cadre:public Teacher,public Cadre{public:teacher_cadre (string nam,int a,char s,string tit,string p, String ad,string t,float W); void Show ();p rivate:float wage;}; Teacher_cadre::teacher_cadre (String nam,int a,char s,string t,string p,string ad,string tel,float W): Teacher (nam,a,s,t    , Ad,tel), cadre (Nam,a,s,p,ad,tel), wage (W) {}void teacher_cadre::show () {Teacher::d isplay ();    cout<< "Position:" <<cadre::p ost<<endl; cout<< "wages:" &LT;&LT;WAGE&LT;&LT;ENDL;}    int main () {Teacher_cadre Te_ca ("Zhang San", "N", "F", "teacher", "Professor", "Gangchengdongdajie,yantai", "1234567", 5241.5);    Te_ca.show (); return 0;}
Operation Result:

Summary of Knowledge points:

This program is a derived class of two base classes, and when defining a derived class, you should note the following two inheritance methods.

Learning experience:

Can be more proficient in mastering.



11th Week Project 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.