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;

}

相关推荐
爱丫爱2 分钟前
Python中常见库 PyTorch和Pydantic 讲解
开发语言·pytorch·python
Ryan_Gosling3 分钟前
C++-构造函数-接口
开发语言·c++
ceffans13 分钟前
PDF文档中文本解析
c++·windows·pdf
SummerGao.19 分钟前
Windows 快速搭建C++开发环境,安装C++、CMake、QT、Visual Studio、Setup Factory
c++·windows·qt·cmake·visual studio·setup factory
查理零世23 分钟前
【蓝桥杯集训·每日一题2025】 AcWing 6134. 哞叫时间II python
python·算法·蓝桥杯
仟濹24 分钟前
【二分搜索 C/C++】洛谷 P1873 EKO / 砍树
c语言·c++·算法
紫雾凌寒32 分钟前
解锁机器学习核心算法|神经网络:AI 领域的 “超级引擎”
人工智能·python·神经网络·算法·机器学习·卷积神经网络
服务端相声演员1 小时前
Oracle JDK、Open JDK zulu下载地址
java·开发语言
YH_DevJourney1 小时前
Linux-C/C++《C/8、系统信息与系统资源》
linux·c语言·c++
京东零售技术1 小时前
AI Agent实战:打造京东广告主的超级助手 | 京东零售技术实践
算法