I. Questions and codes
/* File name: Teacher Cadre class author : Chao date : 2016.5.11 platform : Visual C + + 6.0 description of tasks and Solution Methods section: * Input Description: * Problem Description: Define teacher (Teacher) class and Cadre (Cadre) class respectively, adopt multiple succession way to derive new class Teacher_cadre (teacher and cadre) by these two classes. * Program output: Slightly * problem analysis: slightly * Algorithm design: slightly */
#include <iostream> #include <string> using namespace std; Class Teacher {public:teacher (string,int,string,string); void display (); Private:string name; int age; string sex; string title; }; Teacher::teacher (String na,int a,string s,string ti) {name=na; Age=a; Sex=s; Title=ti; } void Teacher::d isplay () {cout<< "name:" <<name<<endl; cout<< "Age:" <<age<<endl; cout<< "Gender:" <<sex<<endl; cout<< "title:" <<title<<endl; } class Cadre {Public:cadre (string); String Get_post (); Private:string name; int age; string sex; String post; }; Cadre::cadre (String p) {post=p; } string Cadre::get_post () {return post; } class Teacher_cadre:public Teacher,public cadre {public:teacher_cadre (string, int, string, String, String, Flo at); void Show (); float get_wages (); Private float wages; }; Teacher_cadre::teacher_cadre (String na,int a,string s,string ti,string p,float W): Teacher (Na,a,s,ti), Cadre (p) {wage S=w; } void Teacher_cadre::show () {Teacher::d isplay (); } float Teacher_cadre::get_wages () {return wages; } int main () {Teacher_cadre T ("Zeng Hui", 42, "male", "Associate Professor", "director", 1535.5); T.show (); cout<< "title:" <<t.cadre::get_post () <<endl; cout<< "Salary:" <<t.get_wages () <<endl; return 0; }
Ii. Results of operation
Third, experience
Iv. Summary of Knowledge points
C + + experiment 5-Multiple inheritance