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;

}

相关推荐
朝朝辞暮i5 分钟前
C++ 第 21 课:struct —— 把一组相关数据打包在一起
开发语言·c++·算法
青梅橘子皮11 分钟前
Blue---二分算法(二分查找与二分答案)
算法
长河23 分钟前
Java的GC(垃圾回收)中,标记无用对象的核心方法是可达性分析算法
java·jvm·算法
月光船幽幽41 分钟前
加性偏移外推提升参数识别可靠性
python·算法
SHARK_pssm1 小时前
【C++——类和对象(下)】
开发语言·c++·经验分享·笔记
凯哥Java1 小时前
写代码怎么避免逻辑漏洞?
java·开发语言·人工智能·自动化
汉克老师1 小时前
GESP2026年9月认证C++二级( 第一部分选择题(1~7题)精讲
c++·gesp·小学生·学c++编程
Ivanqhz1 小时前
层归一化、残差、前馈网络与激活函数简述
服务器·数据库·人工智能·深度学习·算法
Ai-_Man1 小时前
您您这可以把Dola的多个会话比如说。左侧的多个会话一次性导出吗?不是单条会话里面的多次会对话。用AI导出鸭,答案是可以的
开发语言·前端·人工智能·小程序
Java后端的Ai之路1 小时前
Python进阶探索23 - Python中的Time与Datetime模块
开发语言·数据库·python·datetime·time