#include <iostream>
#include <string>
using namespace std;
class Father
{
public:
void setHeight(int height)
{
this->height= height;
}
int getHeight()
{
return height;
}
void setWeight(int weight)
{
this->weight = weight;
}
int getWeight()
{
return weight;
}
void toString()
{
cout<<"体重:"<<this->weight<<"身高:"<<this->height<<endl;
}
private:
int height;
int weight;
};
class Son : public Father
{
public:
void setAge(int age)
{
this->age = age;
}
int getAge()
{
return age;
}
void toString()
{
cout<<"姓名:\t"<<this->name<<"\t体重:\t"<<Father::getWeight()<<"\t身高:\t"<<Father::getHeight()<<"\t年龄:\t"<<this->age<<endl;
}
void setName(string name)
{
this->name=name;
}
string getName()
{
return name;
}
private:
int age;
string name;
};
void main()
{
Son f ;
f.setName("张三丰");
f.setHeight(175);
f.setWeight(140);
f.setAge(25);
f.toString();
}
————————————————
版权声明:本文为CSDN博主「明明如月学长」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/w605283073/article/details/44246519