- 设计一个Per类,类中包含私有成员:姓名、年龄、指针成员身高、体重,再设计一个Stu类,类中包含私有成员:成绩、Per类对象 p1,设计这两个类的构造函数、析构函数和拷贝构造函数。
#include <iostream>
using namespace std;
class per
{
string name;
int age;
int *high;
int *wid;
public:
per(string name,int age,int *high,int *wid)
{
this->name =name;
this->age =age;
this->high =high;
this->wid =wid;
}
per(int age)
{
this->age =age;
}
~per ()
{
delete high;
delete wid;
}
void show()
{
cout <<name <<endl;
cout <<age <<endl;
cout <<*high <<endl;
cout <<*wid <<endl;
}
};
class stu
{
int score;
public:
per p1;
public:
stu(int score):p1(score)
{
this->score=score;
}
~stu()
{
}
void show()
{
cout <<score <<endl;
}
};
int main()
{
int h=185;int w=165;
per p("lisi",18,&h,&w);
p.show();
stu s(98);
s.show();
return 0;
}
思维导图: