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:" <<TELE<<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:" <<POSE<<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:" <<WAGES<<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