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;

}

相关推荐
AI_Keymaker几秒前
一句话生成3D世界:腾讯开源混元3D模型
算法
Leon_vibs3 分钟前
当 think 遇上 tool:深入解析 Agent 的规划之道
算法
惜.己10 分钟前
pytest中使用ordering控制函数的执行顺序
开发语言·python·pytest
旧时光巷11 分钟前
【机器学习-2】 | 决策树算法基础/信息熵
算法·决策树·机器学习·id3算法·信息熵·c4.5算法
落羽的落羽12 分钟前
【C++】论如何封装红黑树模拟实现set和map
数据结构·c++·学习
落了一地秋38 分钟前
4.5 优化器中常见的梯度下降算法
人工智能·算法·机器学习
前端伪大叔1 小时前
第 5 篇:策略参数怎么调优?Freqtrade hyperopt 快速入门
算法·代码规范
Code季风1 小时前
深入理解令牌桶算法:实现分布式系统高效限流的秘籍
java·算法·微服务
mrbone111 小时前
C++-一篇文章入门coroutines协程
c++