zoukankan      html  css  js  c++  java
  • 多重继承派生类的构造函数

     1 #include <iostream>
     2 #include <string.h>
     3 /* run this program using the console pauser or add your own getch, system("pause") or input loop */
     4 using namespace std;
     5 class Teacher
     6 {
     7     public:
     8         Teacher(string nam,int a,string t)
     9         {
    10             name=nam;
    11             age=a;
    12             title=t;
    13         }
    14         void display()
    15         {
    16             cout<<"name:"<<name<<endl;
    17             cout<<"age:"<<age<<endl;
    18             cout<<"title:"<<title<<endl;
    19         }
    20         protected:
    21             string name;
    22             int age;
    23             string title;
    24 };
    25 
    26 class Student
    27 {
    28     public:
    29         Student(string nam,char s,float sco)
    30         {
    31             name1=nam;
    32             sex=s;
    33             score=sco;
    34         }
    35         void display1()
    36         {
    37             cout<<"name:"<<name1<<endl;
    38             cout<<"sex:"<<sex<<endl;
    39             cout<<"score:"<<score<<endl;
    40         }
    41         protected:
    42             string name1;
    43             char sex;
    44             float score;
    45 };
    46 
    47 class Graduate:public Teacher,public Student
    48 {
    49     public:
    50         Graduate(string nam,int a,char s,string t,float sco,float w):
    51             Teacher(nam,a,t),Student(nam,s,sco),wage(w){
    52 
    53             }
    54             void show()
    55             {
    56                 cout<<"name:"<<name<<endl;
    57                 cout<<"age:"<<age<<endl;
    58                 cout<<"sex:"<<sex<<endl;
    59                 cout<<"score:"<<score<<endl;
    60                 cout<<"title:"<<title<<endl;
    61                 cout<<"wages:"<<wage<<endl;
    62             }
    63             private:
    64                 float wage;
    65 };
    66 int main(int argc, char** argv) {
    67     Graduate grad1("wang",24,'f',"assistant",99,123);
    68     grad1.show();
    69     return 0;
    70 }
  • 相关阅读:
    2020软件工程作业05
    2020软件工程作业00--问题清单
    2020软件工程作业03
    2020软件工程作业02
    2020软件工程作业01
    软件工程个人作业06
    软件工程作业04
    软件工程作业05
    软件工称作业03
    2020软件工程作业02
  • 原文地址:https://www.cnblogs.com/borter/p/9405479.html
Copyright © 2011-2022 走看看