思维导图:
练习题:
#include <iostream> using namespace std; class Per { private: string name; int age; double *height; double *weight; public: Per(string name,int age,double hei,double wei) :name(name),age(age),height(new double(hei)),weight(new double(wei)) { } ~Per() { delete height; delete weight; height = nullptr; weight = nullptr; cout << "堆区空间已释放" << endl; } void Pershow() { cout << "name:" << name << endl; cout << "age:" << age << endl; cout << "height:" << *height << endl; cout << "weight:" << *weight << endl; } }; class Stu { private: double score; Per peo1; public: Stu(double sc,string name,int age,double hei,double wei) :score(sc),peo1(name,age,hei,wei) { } ~Stu() { //cout << "Stu析构函数" << endl; } void Stushow() { cout << "score=" << score << endl; peo1.Pershow(); } }; int main() { //Per p1("日月",27,186.5,80); //p1.Pershow(); Stu s1(90.5,"三儿",24,188.6,78.5); s1.Stushow(); return 0; }