第五章

1.#include <iostream>  
02.using namespace std;  
03.class Student{  
04.public:  
05.   void get_value()  
06.   {cin>>num>>name>>sex;}  
07.   void display()  
08.   {  
09.    cout<<"num:"<<num<<endl;  
10.    cout<<"name:"<<name<<endl;  
11.    cout<<"sex:"<<sex<<endl;  
12.   }  
13.private:  
14.    int num;  
15.    char name[10];  
16.    char sex;  
17.};  
18.class Student1:public Student{  
19.public:  
20.    void getvalue()  
21.    {  
22.     get_value();  
23.     cin>>age>>addr;  
24.    }  
25.    void show()  
26.    {  
27.     display();  
28.     cout<<"age:"<<age<<endl;  
29.     cout<<"address:"<<addr<<endl;  
30.    }  
31.private:  
32.    int age;  
33.    char addr[10];  
34.};  
35.int main()  
36.{  
37. Student1 stud;  
38. stud.getvalue();  
39. stud.show();  
40. return 0;  
41.}  


01.2. #include <iostream>  
02.using namespace std;  
03.class Student{  
04.public:  
05.   void get_value()  
06.   {cin>>num>>name>>sex;}  
07.   void display()  
08.   {  
09.    cout<<"num:"<<num<<endl;  
10.    cout<<"name:"<<name<<endl;  
11.    cout<<"sex:"<<sex<<endl;  
12.   }  
13.private:  
14.    int num;  
15.    char name[10];  
16.    char sex;  
17.};  
18.class Student1:private Student{  
19.public:  
20.    void getvalue()  
21.    {  
22.     get_value();  
23.     cin>>age>>addr;  
24.    }  
25.    void show()  
26.    {  
27.     display();  
28.     cout<<"age:"<<age<<endl;  
29.     cout<<"address:"<<addr<<endl;  
30.    }  
31.private:  
32.    int age;  
33.    char addr[10];  
34.};  
35.int main()  
36.{  
37. Student1 stud;  
38. stud.getvalue();  
39. stud.show();  
40. return 0;  
41.}  


01.3.#include <iostream>  
02.using namespace std;  
03.class Student{  
04.public:  
05.   void get_value()  
06.   {cin>>num>>name>>sex;}  
07.   void display()  
08.   {  
09.    cout<<"num:"<<num<<endl;  
10.    cout<<"name:"<<name<<endl;  
11.    cout<<"sex:"<<sex<<endl;  
12.   }  
13.protected:  
14.    int num;  
15.    char name[10];  
16.    char sex;  
17.};  
18.class Student1:protected Student{  
19.public:  
20.    void getvalue()  
21.    {  
22.     get_value();  
23.     cin>>age>>addr;  
24.    }  
25.    void show()  
26.    {  
27.     cout<<"num:"<<num<<endl;  
28.     cout<<"name:"<<name<<endl;  
29.     cout<<"sex:"<<sex<<endl;  
30.     cout<<"age:"<<age<<endl;  
31.     cout<<"address:"<<addr<<endl;  
32.    }  
33.private:  
34.    int age;  
35.    char addr[10];  
36.};  
37.int main()  
38.{  
39. Student1 stud;  
40. stud.getvalue();  
41. stud.show();  
42. return 0;  
43.}  


01.4.#include <iostream>  
02.using namespace std;  
03.class Student{  
04.public:  
05.   void get_value()  
06.   {cin>>num>>name>>sex;}  
07.   void display()  
08.   {  
09.    cout<<"num:"<<num<<endl;  
10.    cout<<"name:"<<name<<endl;  
11.    cout<<"sex:"<<sex<<endl;  
12.   }  
13.protected:  
14.    int num;  
15.    char name[10];  
16.    char sex;  
17.};  
18.class Student1:public Student{  
19.public:  
20.    void getvalue()  
21.    {  
22.     get_value();  
23.     cin>>age>>addr;  
24.    }  
25.    void show()  
26.    {  
27.     cout<<"num:"<<num<<endl;  
28.     cout<<"name:"<<name<<endl;  
29.     cout<<"sex:"<<sex<<endl;  
30.     cout<<"age:"<<age<<endl;  
31.     cout<<"address:"<<addr<<endl;  
32.    }  
33.private:  
34.    int age;  
35.    char addr[10];  
36.};  
37.int main()  
38.{  
39. Student1 stud;  
40. stud.getvalue();  
41. stud.show();  
42. return 0;  
43.}  


01.5. #include <iostream>  
02.using namespace std;  
03.class A  
04.{  
05.public:  
06.    void f1();  
07.    int i;  
08.protected:  
09.    void f2();  
10.    int j;  
11.private:  
12.    int k;  
13.};  
14.class B:public A  
15.{  
16.public:  
17.    void f3();  
18.protected:  
19.    int m;  
20.private:  
21.    int n;  
22.};  
23.class C:public B   
24.{  
25.public:  
26.    void f4();  
27.private:  
28.    int p;  
29.};  
30.int main()  
31.{  
32. A a1;  
33. B b1;  
34. C c1;  
35. return 0;  
36.}  


01.6. #include <iostream>  
02.using namespace std;  
03.class A  
04.{  
05.public:  
06.    void f1();  
07.protected:  
08.    void f2();  
09.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;  
45.}  


01.7. #include <iostream>  
02.using namespace std;  
03.class A  
04.{  
05.public:  
06.    A(){a=0;b=0;}  
07.    A(int i){a=i;b=0;}  
08.    A(int i,int j){a=i;b=j;}  
09.    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.}  


01.8. #include <iostream>  
02.using namespace std;  
03.class A  
04.{  
05.public:  
06.    A(){cout<<"constructing A "<<endl;}  
07.    ~A(){cout<<"destructing A "<<endl;}  
08.};  
09.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.}  


01.9. #include <string>  
02.#include <iostream>  
03.using namespace std;  
04.class Teacher{  
05.public:  
06.    Teacher(string nam,int a,char s,string ti,string ad,string t);  
07.    void display();  
08.protected:  
09.    string name;  
10.    int age;  
11.    char sex;  
12.    string title;  
13.    string addr;  
14.    string tel;  
15.};  
16.Teacher::Teacher(string nam,int a,char s,string ti,string ad,string t)  
17.{  
18.    name=nam;  
19.    age=a;  
20.    sex=s;  
21.    title=t;  
22.    addr=ad;  
23.    tel=t;  
24.}  
25.void Teacher::display()  
26.{  
27. cout<<"name:"<<name<<endl;  
28. cout<<"age:"<<age<<endl;  
29. cout<<"sex:"<<sex<<endl;  
30. cout<<"title:"<<title<<endl;  
31. cout<<"addr:"<<addr<<endl;  
32. cout<<"tel:"<<tel<<endl;  
33.}  
34.class Cadre{  
35.public:  
36.    Cadre(string nam,int a,char s,string p,string ad,string t);  
37.    void display();  
38.protected:  
39.    string name;  
40.    int age;  
41.    char sex;  
42.    string post;  
43.    string addr;  
44.    string tel;  
45.};  
46.Cadre::Cadre(string nam,int a,char s,string p,string ad,string t):name(nam),  
47.age(a),sex(s),post(p),addr(ad),tel(t){}  
48.void Cadre::display()  
49.{  
50. cout<<"name:"<<name<<endl;  
51. cout<<"age:"<<age<<endl;  
52. cout<<"sex:"<<sex<<endl;  
53. cout<<"post:"<<post<<endl;  
54. cout<<"addr:"<<addr<<endl;  
55. cout<<"tel:"<<tel<<endl;  
56.}  
57.class Teacher_Cadre:public Teacher,public Cadre  
58.{  
59.public:  
60.    Teacher_Cadre(string nam,int a,char s,string ti,string p,string ad,string t,float w);  
61.    void show();  
62.private:  
63.    float wage;  
64.};  
65.Teacher_Cadre::Teacher_Cadre(string nam,int a,char s,string ti,string p,string ad,string t,float w):  
66.Teacher(nam,a,s,ti,ad,t),Cadre(nam,a,s,p,ad,t),wage(w){}  
67.void Teacher_Cadre::show()  
68.{  
69.    Teacher::display();  
70.    cout<<"post:"<<Cadre::post<<endl;  
71.    cout<<"wage:"<<wage<<endl;  
72.}  
73.int main()  
74.{  
75. Teacher_Cadre tc("xiongxian",18,'F',"xuesheng","nanchang","110","zuzhang",10000);  
76. tc.show();  
77. return 0;  
78.}  


01.10. #include <string>  
02.#include <iostream>  
03.using namespace std;  
04.class Teacher{  
05.public:  
06.    Teacher(int,string,char);  
07.    void display();  
08.private:  
09.    int num;  
10.    string name;  
11.    char sex;  
12.};  
13.Teacher::Teacher(int n,string nam,char s)  
14.{  
15. num=n;  
16. name=nam;  
17. sex=s;  
18.}  
19.void Teacher::display()  
20.{  
21. cout<<"num:"<<num<<endl;  
22. cout<<"name:"<<name<<endl;  
23. cout<<"sex:"<<sex<<endl;  
24.}  
25.class BirthDate{  
26.public:  
27.    BirthDate(int,int,int);  
28.    void display();  
29.    void change(int,int,int);  
30.private:  
31.    int year;  
32.    int month;  
33.    int day;  
34.};  
35.BirthDate::BirthDate(int y,int m,int d)  
36.{  
37. year=y;  
38. month=m;  
39. day=d;  
40.}  
41.void BirthDate::display()  
42.{  
43. cout<<"year:"<<year<<endl;  
44. cout<<"month:"<<month<<endl;  
45. cout<<"day:"<<day<<endl;  
46.}  
47.void BirthDate::change(int y,int m,int d)  
48.{  
49. year=y;  
50. month=m;  
51. day=d;  
52.}  
53.class Professor:public Teacher  
54.{  
55.public:  
56.    Professor(int,string,char,int,int,int,float);  
57.    void display();  
58.    void change(int,int,int);  
59.private:  
60.    float area;  
61.    BirthDate birthday;  
62.};  
63.Professor::Professor(int n,string nam,char s,int y,int m,int d,float a):  
64.Teacher(n,nam,s),birthday(y,m,d),area(a){}  
65.void Professor::display()  
66.{  
67.    Teacher::display();  
68.    birthday.display();  
69.    cout<<"area:"<<area<<endl;  
70.  
71.}  
72.void Professor::change(int y,int m,int d)  
73.{  
74. birthday.change(y,m,d);  
75.}  
76.int main()  
77.{  
78. Professor prof1(1,"xiongxian",'F',1996,10,12,100);  
79. prof1.display();  
80. prof1.change(2000,1,1);  
81. prof1.display();  
82. return 0;  
83.} 

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值