第5章

1.

#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;  

}


2.

#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;  

}  

 

3.

#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;  

}  


4.

#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;  

}  


5.

#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;  

}  


6.

#include <iostream>  

using namespace std;  

class A  

{  

public:  

    void f1();  

protected:  

    void f2();  

private:  

    int i;  

};  

class B:public A  

{  

public:  

    void f3();  

    int k;  

private:  

    int m;  

};  

class C:protected B   

{  

public:  

    void f4();  

protected:  

    int n;  

private:  

    int p;  

};  

class D:private C  

{  

public:  

    void f5();  

protected:  

    int q;  

private:  

    int r;  

};  

int main()  

{  

 A a1;  

 B b1;  

 C c1;  

 D d1;  

 return 0;  

}  


7.

#include <iostream>  

using namespace std;  

class A  

{  

public:  

    A(){a=0;b=0;}  

    A(int i){a=i;b=0;}  

    A(int i,int j){a=i;b=j;}  

    void display()  

    {cout<<"a="<<a<<endl;  

    cout<<"b="<<b<<endl;}  

private:  

    int a;  

    int b;  

};  

class B:public A  

{  

public:  

    B(){c=0;}  

    B(int i):A(i){c=0;}  

    B(int i,int j):A(i,j){c=0;}  

    B(int i,int j,int k):A(i,j){c=k;}  

    void show()  

    {  

     display();  

     cout<<"c="<<c<<endl;  

    }  

private:  

    int c;  

};  

int main()  

{  

 B b1;  

 B b2(1);  

 B b3(1,2);  

 B b4(1,2,3);  

 b1.show();  

 b2.show();  

 b3.show();  

 b4.show();  

 return 0;  

}  


8.

#include <iostream>  

using namespace std;  

class A  

{  

public:  

    A(){cout<<"constructing A "<<endl;}  

    ~A(){cout<<"destructing A "<<endl;}  

};  

class B:public A  

{  

public:  

    B(){cout<<"constructing B "<<endl;}  

    ~B(){cout<<"destructing B "<<endl;}  

};  

class C:public B{  

public:  

    C(){cout<<"constructing C "<<endl;}  

    ~C(){cout<<"destructing C "<<endl;}  

};  

int main()  

{  

 C c1;  

 return 0;  

}  


9.

#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("yihuan",19,'F',"xuesheng","jian","hh","110",10000);  

 tc.show();  

 return 0;  

}  


10.

#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,"yihuan",'F',1996,4,15,100);  

 prof1.display();  

 prof1.change(2000,1,1);  

 prof1.display();  

 return 0;  

}  


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
经导师精心指导并认可、获 98 分的毕业设计项目!【项目资源】:微信小程序。【项目说明】:聚焦计算机相关专业毕设及实战操练,可作课程设计与期末大作业,含全部源码,能直用于毕设,经严格调试,运行有保障!【项目服务】:有任何使用上的问题,欢迎随时与博主沟通,博主会及时解答。 经导师精心指导并认可、获 98 分的毕业设计项目!【项目资源】:微信小程序。【项目说明】:聚焦计算机相关专业毕设及实战操练,可作课程设计与期末大作业,含全部源码,能直用于毕设,经严格调试,运行有保障!【项目服务】:有任何使用上的问题,欢迎随时与博主沟通,博主会及时解答。 经导师精心指导并认可、获 98 分的毕业设计项目!【项目资源】:微信小程序。【项目说明】:聚焦计算机相关专业毕设及实战操练,可作课程设计与期末大作业,含全部源码,能直用于毕设,经严格调试,运行有保障!【项目服务】:有任何使用上的问题,欢迎随时与博主沟通,博主会及时解答。 经导师精心指导并认可、获 98 分的毕业设计项目!【项目资源】:微信小程序。【项目说明】:聚焦计算机相关专业毕设及实战操练,可作课程设计与期末大作业,含全部源码,能直用于毕设,经严格调试,运行有保障!【项目服务】:有任何使用上的问题,欢迎随时与博主沟通,博主会及时解答。
经导师精心指导并认可、获 98 分的毕业设计项目!【项目资源】:微信小程序。【项目说明】:聚焦计算机相关专业毕设及实战操练,可作课程设计与期末大作业,含全部源码,能直用于毕设,经严格调试,运行有保障!【项目服务】:有任何使用上的问题,欢迎随时与博主沟通,博主会及时解答。 经导师精心指导并认可、获 98 分的毕业设计项目!【项目资源】:微信小程序。【项目说明】:聚焦计算机相关专业毕设及实战操练,可作课程设计与期末大作业,含全部源码,能直用于毕设,经严格调试,运行有保障!【项目服务】:有任何使用上的问题,欢迎随时与博主沟通,博主会及时解答。 经导师精心指导并认可、获 98 分的毕业设计项目!【项目资源】:微信小程序。【项目说明】:聚焦计算机相关专业毕设及实战操练,可作课程设计与期末大作业,含全部源码,能直用于毕设,经严格调试,运行有保障!【项目服务】:有任何使用上的问题,欢迎随时与博主沟通,博主会及时解答。 经导师精心指导并认可、获 98 分的毕业设计项目!【项目资源】:微信小程序。【项目说明】:聚焦计算机相关专业毕设及实战操练,可作课程设计与期末大作业,含全部源码,能直用于毕设,经严格调试,运行有保障!【项目服务】:有任何使用上的问题,欢迎随时与博主沟通,博主会及时解答。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值