/* *copyright (c) 2016, College of Computer Science, Yantai University * Author: Liu Jinshi * Completion Date: May 9, 2016 * Problem description: Teacher and Cadre class * Requirements: Define teacher (Teacher) class and Cadre (cadre) category, the use of multiple inheritance by these two classes derived from the new class Teacher_cadre (teachers and cadres). Requirements: * (1) in two base classes include name, age, gender, address, telephone and other data members. * (2) in the teacher class also contains the data member title (title), in the Cadre class also contains the data member post (title), in the Teacher_cadre class also contains the data member wages (payroll). * (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>using namespace Std;class teacher{protected:string name; int age; char sex; String addr; String Tel; String Title;public:teacher (String na,int ag,char se,string ad,string te,string ti); void display ();}; void Teacher::d isplay () {cout<< "name:" <<name<<endl; cout<< "Age" <<age<<endl; cout<< "Sex:" <<sex<<endl; cout<< "Address:" <<addr<<endl; cout<< "Tel:" <<tel<<endl; cout<< "title:" <<title<<endl;} Teacher::teacher (String na,int ag,char se,string ad,string te,string ti): Name (NA), Age (AG), sex (SE), addr (AD), Tel (te), Title (TI) {}class cadre{protected:string name; int age; char sex; String addr; String Tel; String Post;public:cadre (String na,int ag,char se,string ad,string te,string po); void display ();}; Cadre::cadre (String na,int ag,char se,string ad,string te,string po): Name (NA), Age (AG), sex (SE), addr (AD), Tel (te), post ( PO) {}void cadre::d isplay () {cout<< "name:" <<name<<endl; cout<< "Age" <<age<<endl; cout<< "Sex:" <<sex<<endl; cout<< "Address:" <<addr<<endl; cout<< "Tel:" <<tel<<endl; cout<< "Post:" <<post<<endl;} Class Teacher_cadre:public Teacher,public cadre {double wages; Public:teacher_cadre (string Na,int ag,char Se,stri ng ad,string te,string ti,string po,double wa); void Show (); }; Teacher_cadre::teacher_cadre (String na,int ag,char se,string ad,string te,string ti,string po,double wa): Teacher (na,a G,se,ad,te,ti), cadre (NA,AG,SE,AD,TE,PO), Wages (WA) {} void Teacher_cadre::show () {Teacher::d isplay (); cout<< "Post:" <<cadre::p ost<<endl; cout<< "Wages:" <<wages<<endl;} int main () {Teacher_cadre Te_ca ("Wang-li", "021", ' F ', "Prof.", "President", "135 Beijing Road,shanghai", "() 61234567", 3523.5); Te_ca.show (); return 0;}
Operation Result:
Tenth week succession teacher and cadre category of Project four