/* *copyright (c) 2016, College of Computer and Control engineering, Yantai University *all rights reserved * File name: 123.cpp * Author: Wang Lui * Completion date: May 10, 2016 * Version number: v1.0 * * Problem Description: Set separately The teacher class and the Cadre class are derived from these two classes in a multiple-inheritance manner teacher_cadre the new class. */#include <iostream> #include <cstring>using namespace Std;class teacher{private:string title; string address; String name; int age; char sex; int Telephone;public:teacher (string n,int a,char s,string t,string ad,int Tel): Name (n), age (a), sex (s), title (t), address (AD), telephone (tel) {} void display ();}; void Teacher::d isplay () {cout<< "Name:" <<name<<endl; cout<< "Age:" <<age<<endl; cout<< "Sex:" <<sex<<endl; cout<< "Title:" <<title<<endl; cout<< "Address:" <<address<<endl; cout<< "Tel:" <<TELEPHONE<<ENDL;} Class Cadre{private:string post; string address; String name; int age; char sex; int Telephone;public:cadre (string n,int a,char s,string p,string ad,iNT Tel): Name (n), age (a), sex (s), post (p), address (AD), telephone (tel) {} string printpost (); void display ();}; void cadre::d isplay () {cout<< "Name:" <<name<<endl; cout<< "Age:" <<age<<endl; cout<< "Sex:" <<sex<<endl; cout<< "Post:" <<post<<endl; cout<< "Address:" <<address<<endl; cout<< "Tel:" <<TELEPHONE<<ENDL;} String cadre::p rintpost () {return post;} Class Teacher_cadre:public Teacher,public cadre{private:double wages;public:teacher_cadre (string n,int a,char s,st Ring t,string p,string Ad,int tel,double W): Teacher (N,a,s,t,ad,tel), cadre (N,a,s,p,ad,tel), Wages (w) {} void Show (); ; void Teacher_cadre::show () {Teacher::d isplay (); cout<< "Post:" <<cadre::p rintpost () <<endl; cout<< "Wages:" <<WAGES<<ENDL;} int main () {Teacher_cadre Colin ("Shu Baba", +, ' F ', "Professor", "Headmasters", "Zhongguo", 123456789,300000); Colin.show (); return 0;}
Operation Result:
Learning experience:
Learn how to solve problems with inheritance, as well as the constructors of derived classes.
Tenth to tenth week item four-teacher and cadre category