第五章

#include <iostream>  
using namespace std;  
class Student{  
public:  
   void get_value()  
   {cin>>num>>name>>sex;}  
   void display()  
   {  
    cout<<"num:"<<num<<endl;  
    cout<<"name:"<<name<<endl;  
    cout<<"sex:"<<sex<<endl;  
   }  
private:  
    int num;  
    char name[10];  
    char sex;  
};  
class Student1:public Student{  
public:  
    void getvalue()  
    {  
     get_value();  
     cin>>age>>addr;  
    }  
    void show()  
    {  
     display();  
     cout<<"age:"<<age<<endl;  
     cout<<"address:"<<addr<<endl;  
    }  
private:  
    int age;  
    char addr[10];  
};  
int main()  
{  
 Student1 stud;  
 stud.getvalue();  
 stud.show();  
 return 0;  

}  

#include <iostream>  
using namespace std;  
class Student{  
public:  
   void get_value()  
   {cin>>num>>name>>sex;}  
   void display()  
   {  
    cout<<"num:"<<num<<endl;  
    cout<<"name:"<<name<<endl;  
    cout<<"sex:"<<sex<<endl;  
   }  
private:  
    int num;  
    char name[10];  
    char sex;  
};  
class Student1:private Student{  
public:  
    void getvalue()  
    {  
     get_value();  
     cin>>age>>addr;  
    }  
    void show()  
    {  
     display();  
     cout<<"age:"<<age<<endl;  
     cout<<"address:"<<addr<<endl;  
    }  
private:  
    int age;  
    char addr[10];  
};  
int main()  
{  
 Student1 stud;  
 stud.getvalue();  
 stud.show();  
 return 0;  
}

#include <iostream>  
using namespace std;  
class Student{  
public:  
   void get_value()  
   {cin>>num>>name>>sex;}  
   void display()  
   {  
    cout<<"num:"<<num<<endl;  
    cout<<"name:"<<name<<endl;  
    cout<<"sex:"<<sex<<endl;  
   }  
protected:  
    int num;  
    char name[10];  
    char sex;  
};  
class Student1:protected Student{  
public:  
    void getvalue()  
    {  
     get_value();  
     cin>>age>>addr;  
    }  
    void show()  
    {  
     cout<<"num:"<<num<<endl;  
     cout<<"name:"<<name<<endl;  
     cout<<"sex:"<<sex<<endl;  
     cout<<"age:"<<age<<endl;  
     cout<<"address:"<<addr<<endl;  
    }  
private:  
    int age;  
    char addr[10];  
};  
int main()  
{  
 Student1 stud;  
 stud.getvalue();  
 stud.show();  
 return 0;  
}

#include <iostream>  
using namespace std;  
class Student{  
public:  
   void get_value()  
   {cin>>num>>name>>sex;}  
   void display()  
   {  
    cout<<"num:"<<num<<endl;  
    cout<<"name:"<<name<<endl;  
    cout<<"sex:"<<sex<<endl;  
   }  
protected:  
    int num;  
    char name[10];  
    char sex;  
};  
class Student1:public Student{  
public:  
    void getvalue()  
    {  
     get_value();  
     cin>>age>>addr;  
    }  
    void show()  
    {  
     cout<<"num:"<<num<<endl;  
     cout<<"name:"<<name<<endl;  
     cout<<"sex:"<<sex<<endl;  
     cout<<"age:"<<age<<endl;  
     cout<<"address:"<<addr<<endl;  
    }  
private:  
    int age;  
    char addr[10];  
};  
int main()  
{  
 Student1 stud;  
 stud.getvalue();  
 stud.show();  
 return 0;  
}

#include <iostream>  
using namespace std;  
class A  
{  
public:  
    void f1();  
    int i;  
protected:  
    void f2();  
    int j;  
private:  
    int k;  
};  
class B:public A  
{  
public:  
    void f3();  
protected:  
    int m;  
private:  
    int n;  
};  
class C:public B   
{  
public:  
    void f4();  
private:  
    int p;  
};  
int main()  
{  
 A a1;  
 B b1;  
 C c1;  
 return 0;  
}

  1. #include <iostream>  
  2. using namespace std;  
  3. class A  
  4. {  
  5. public:  
  6.     void f1();  
  7. protected:  
  8.     void f2();  
  9. private:  
  10.     int i;  
  11. };  
  12. class B:public A  
  13. {  
  14. public:  
  15.     void f3();  
  16.     int k;  
  17. private:  
  18.     int m;  
  19. };  
  20. class C:protected B   
  21. {  
  22. public:  
  23.     void f4();  
  24. protected:  
  25.     int n;  
  26. private:  
  27.     int p;  
  28. };  
  29. class D:private C  
  30. {  
  31. public:  
  32.     void f5();  
  33. protected:  
  34.     int q;  
  35. private:  
  36.     int r;  
  37. };  
  38. int main()  
  39. {  
  40.  A a1;  
  41.  B b1;  
  42.  C c1;  
  43.  D d1;  
  44.  return 0;  


  1. #include <iostream>  
  2. using namespace std;  
  3. class A  
  4. {  
  5. public:  
  6.     A(){a=0;b=0;}  
  7.     A(int i){a=i;b=0;}  
  8.     A(int i,int j){a=i;b=j;}  
  9.     void display()  
  10.     {cout<<"a="<<a<<endl;  
  11.     cout<<"b="<<b<<endl;}  
  12. private:  
  13.     int a;  
  14.     int b;  
  15. };  
  16. class B:public A  
  17. {  
  18. public:  
  19.     B(){c=0;}  
  20.     B(int i):A(i){c=0;}  
  21.     B(int i,int j):A(i,j){c=0;}  
  22.     B(int i,int j,int k):A(i,j){c=k;}  
  23.     void show()  
  24.     {  
  25.      display();  
  26.      cout<<"c="<<c<<endl;  
  27.     }  
  28. private:  
  29.     int c;  
  30. };  
  31. int main()  
  32. {  
  33.  B b1;  
  34.  B b2(1);  
  35.  B b3(1,2);  
  36.  B b4(1,2,3);  
  37.  b1.show();  
  38.  b2.show();  
  39.  b3.show();  
  40.  b4.show();  
  41.  return 0;  
  42. }  

  1. #include <iostream>  
  2. using namespace std;  
  3. class A  
  4. {  
  5. public:  
  6.     A(){cout<<"constructing A "<<endl;}  
  7.     ~A(){cout<<"destructing A "<<endl;}  
  8. };  
  9. class B:public A  
  10. {  
  11. public:  
  12.     B(){cout<<"constructing B "<<endl;}  
  13.     ~B(){cout<<"destructing B "<<endl;}  
  14. };  
  15. class C:public B{  
  16. public:  
  17.     C(){cout<<"constructing C "<<endl;}  
  18.     ~C(){cout<<"destructing C "<<endl;}  
  19. };  
  20. int main()  
  21. {  
  22.  C c1;  
  23.  return 0;  
  24. }  


  1. #include <string>  
    #include <iostream>  
    using namespace std;  
    class Teacher{  
    public:  
        Teacher(string nam,int a,char s,string ti,string ad,string t);  
        void display();  
    protected:  
        string name;  
        int age;  
        char sex;  
        string title;  
        string addr;  
        string tel;  
    };  
    Teacher::Teacher(string nam,int a,char s,string ti,string ad,string t)  
    {  
        name=nam;  
        age=a;  
        sex=s;  
        title=t;  
        addr=ad;  
        tel=t;  
    }  
    void Teacher::display()  
    {  
     cout<<"name:"<<name<<endl;  
     cout<<"age:"<<age<<endl;  
     cout<<"sex:"<<sex<<endl;  
     cout<<"title:"<<title<<endl;  
     cout<<"addr:"<<addr<<endl;  
     cout<<"tel:"<<tel<<endl;  
    }  
    class Cadre{  
    public:  
        Cadre(string nam,int a,char s,string p,string ad,string t);  
        void display();  
    protected:  
        string name;  
        int age;  
        char sex;  
        string post;  
        string addr;  
        string tel;  
    };  
    Cadre::Cadre(string nam,int a,char s,string p,string ad,string t):name(nam),  
    age(a),sex(s),post(p),addr(ad),tel(t){}  
    void Cadre::display()  
    {  
     cout<<"name:"<<name<<endl;  
     cout<<"age:"<<age<<endl;  
     cout<<"sex:"<<sex<<endl;  
     cout<<"post:"<<post<<endl;  
     cout<<"addr:"<<addr<<endl;  
     cout<<"tel:"<<tel<<endl;  
    }  
    class Teacher_Cadre:public Teacher,public Cadre  
    {  
    public:  
        Teacher_Cadre(string nam,int a,char s,string ti,string p,string ad,string t,float w);  
        void show();  
    private:  
        float wage;  
    };  
    Teacher_Cadre::Teacher_Cadre(string nam,int a,char s,string ti,string p,string ad,string t,float w):  
    Teacher(nam,a,s,ti,ad,t),Cadre(nam,a,s,p,ad,t),wage(w){}  
    void Teacher_Cadre::show()  
    {  
        Teacher::display();  
        cout<<"post:"<<Cadre::post<<endl;  
        cout<<"wage:"<<wage<<endl;  
    }  
    int main()  
    {  
     Teacher_Cadre tc("gfafg",18,'F',"xuesheng","nanchang","110","zuzhang",10000);  
     tc.show();  
     return 0;  
    }

 #include <string>  
#include <iostream>  
using namespace std;  
class Teacher{  
public:  
    Teacher(int,string,char);  
    void display();  
private:  
    int num;  
    string name;  
    char sex;  
};  
Teacher::Teacher(int n,string nam,char s)  
{  
 num=n;  
 name=nam;  
 sex=s;  
}  
void Teacher::display()  
{  
 cout<<"num:"<<num<<endl;  
 cout<<"name:"<<name<<endl;  
 cout<<"sex:"<<sex<<endl;  
}  
class BirthDate{  
public:  
    BirthDate(int,int,int);  
    void display();  
    void change(int,int,int);  
private:  
    int year;  
    int month;  
    int day;  
};  
BirthDate::BirthDate(int y,int m,int d)  
{  
 year=y;  
 month=m;  
 day=d;  
}  
void BirthDate::display()  
{  
 cout<<"year:"<<year<<endl;  
 cout<<"month:"<<month<<endl;  
 cout<<"day:"<<day<<endl;  
}  
void BirthDate::change(int y,int m,int d)  
{  
 year=y;  
 month=m;  
 day=d;  
}  
class Professor:public Teacher  
{  
public:  
    Professor(int,string,char,int,int,int,float);  
    void display();  
    void change(int,int,int);  
private:  
    float area;  
    BirthDate birthday;  
};  
Professor::Professor(int n,string nam,char s,int y,int m,int d,float a):  
Teacher(n,nam,s),birthday(y,m,d),area(a){}  
void Professor::display()  
{  
    Teacher::display();  
    birthday.display();  
    cout<<"area:"<<area<<endl;  
  
}  
void Professor::change(int y,int m,int d)  
{  
 birthday.change(y,m,d);  
}  
int main()  
{  
 Professor prof1(1,"adfad",'F',1996,10,12,100);  
 prof1.display();  
 prof1.change(2000,1,1);  
 prof1.display();  
 return 0;  


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值