整理思维导图
Person类,私有成员(姓名,年龄,縞,体重),公有成员方法(有参构造函数、析构函数、show函数)
Stu类,继承派生自Person类,私有成员(成绩,班级),公有成员方法(有参构造函数、析构函数、show函数), 实例化一个Stu
对象并调用show函数
#include <iostream>
using namespace std;
class person
{
string name;
int age;
int high;
int weight;
public:
person(string name,int age,int high,int weight):name(name),age(age),high(high),weight(weight)
{
cout<<"有参构造函数"<<endl;
}
~person()
{
cout<<"析构函数"<<endl;
}
void show()
{
cout<<"age="<<age<<endl;
cout<<"high="<<high<<endl;
cout<<"weight="<<weight<<endl;
cout<<"name="<<name<<endl;
cout<<"-----------"<<endl;
}
};
class stu:public person
{
int score;
string c;
public:
stu(string name,int age,int high,int weight,int score,string c):person(name,age,high,weight),score(score),c(c)
{
cout<<"stu有参构造"<<endl;
}
~stu()
{
cout<<"stu析构函数"<<endl;
}
void show()
{
cout<<"class="<<c<<endl;
cout<<"score="<<score<<endl;
cout<<"-----------"<<endl;
}
};
int main()
{
stu stu1("zs",12,180,80,90,"xx");
stu1.person::show();
stu1.show();
return 0;
}