Person类,私有成员(姓名,年龄,身高,体重),公有成员方法(有参构造函数、析构函数、show函数)Stu类,继承派生自Person类,私有成员(成绩,班级),公有成员方法(有参构造函数,析构函数,Show函数),实例化一个St对象并调用show函数
#include <iostream>
using namespace std;
class Person
{
int age;
string name;
int high;
public:
Person()
{
cout<<"Person无参构造"<<endl;
}
Person(int a,string n,int h):age(a),name(n),high(h)
{
cout<<"Person参构造"<<endl;
}
~Person()
{
cout<<"Person析构函数"<<endl;
}
void show()
{
cout<<name<<"\n"<<age<<"\n"<<high<<"\n"<<endl;
}
};
class Stu:public Person
{
int score;
public:
Stu(int a,string n,int h,int s):Person(a,n,h),score(s)
{
cout<<"Stu有参构造"<<endl;
}
Stu()
{
cout<<"Stu无参构造"<<endl;
}
~Stu()
{
cout<<"Stu析构函数"<<endl;
}
void show()
{
Person::show();
cout<<"成绩:"<<score<< endl;
}
};
int main()
{
return 0;
}