📄 13_6.cpp
字号:
/*派生类的构造函数*/
# include <iostream.h>
# include <string.h>
class hum
{
protected:
int age;
char name[20];
public:
void display();
int get_age();
void set_age(int);
hum(int a,char str[])
{
age = a;
strcpy(name,str);
}
};
void hum::display()
{
cout <<"年龄:"<<age<<endl;
cout <<"姓名:"<<name<<endl;
}
class human: public hum
{
private:
int height;
public:
int get_height();
void set_height(int);
void show();
human(int b,int a, char str[]):hum(a, str)
{
height = b;
}
};
void human::show()
{
cout <<"姓名:"<<name<<endl;
cout <<"身高:"<<height<<endl;
cout <<"年龄:"<<age <<endl;
}
void main()
{
human student1(170,20,"Wang");
human student2(200,25,"Lei");
student1.show();
student2.show();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -