C++作业第四天

#include <iostream>

using namespace std;

class Per

{

private:

string name;

int age;

int *high;

double *weight;

public:

//构造函数

Per()

{

cout << "Per的无参构造" << endl;

}

Per(string name,int age,int high,double weight):\

name(name),age(age),high(new int(high)),weight(new double(weight))

{

cout << "Per的有参构造" << endl;

}

//析构函数

~Per()

{

cout << "Per的析构函数" << endl;

delete (high);

delete (weight);

}

void show()

{

cout << name << " " << age << " " << *high << " " << *weight << endl;

}

};

class Stu

{

private:

double score;

Per p1;

public:

//构造函数

Stu()

{

cout << "Stu的无参构造" << endl;

}

Stu(double score,string name,int age,int high,double weight):\

score(score),p1(name,age,high,weight)

{

cout << "Stu的有参构造" << endl;

}

//析构函数

~Stu()

{

cout << "Stu的析构函数" << endl;

}

void show()

{

cout << score << " ";

p1.show();

}

};

int main()

{

Per p1;

Per p2("张三",1,190,90.5);

Stu s1;

Stu s2(10.2,"李四",2,185,85.3);

p2.show();

s2.show();

return 0;

}

相关推荐
程序员弘羽13 分钟前
C++ 第四阶段 内存管理 - 第二节:避免内存泄漏的技巧
java·jvm·c++
【ql君】qlexcel20 分钟前
Notepad++ 复制宏、编辑宏的方法
开发语言·javascript·notepad++··宏编辑·宏复制
爱思德学术26 分钟前
中国计算机学会(CCF)推荐学术会议-B(交叉/综合/新兴):BIBM 2025
算法
Zevalin爱灰灰29 分钟前
MATLAB GUI界面设计 第六章——常用库中的其它组件
开发语言·ui·matlab
冰糖猕猴桃36 分钟前
【Python】进阶 - 数据结构与算法
开发语言·数据结构·python·算法·时间复杂度、空间复杂度·树、二叉树·堆、图
lifallen1 小时前
Paimon vs. HBase:全链路开销对比
java·大数据·数据结构·数据库·算法·flink·hbase
wt_cs1 小时前
银行回单ocr api集成解析-图像文字识别-文字识别技术
开发语言·python
_WndProc1 小时前
【Python】Flask网页
开发语言·python·flask
liujing102329292 小时前
Day04_刷题niuke20250703
java·开发语言·算法
DolphinDB2 小时前
如何在C++交易系统中集成高性能回测与模拟撮合
c++