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;

}

相关推荐
ss2733 分钟前
CompletionService:Java并发工具包
java·开发语言·算法
额呃呃7 分钟前
select和poll之间的性能对比
开发语言·算法
智航GIS8 分钟前
7.2 Try Except语句
开发语言·python
王哈哈^_^8 分钟前
【完整源码+数据集】道路交通事故数据集,yolo车祸检测数据集 7869 张,交通事故级别检测数据集,交通事故检测系统实战教程
人工智能·深度学习·算法·yolo·目标检测·计算机视觉·毕业设计
星轨初途9 分钟前
C++ string 类详解:概念、常用操作与实践(算法竞赛类)
开发语言·c++·经验分享·笔记·算法
二进制_博客9 分钟前
JWT权限认证快速入门
java·开发语言·jwt
先做个垃圾出来………13 分钟前
53. 最大子数组和
算法·leetcode
程序员佳佳15 分钟前
026年AI开发实战:从GPT-5.2到Gemini-3,如何构建下一代企业级Agent架构?
开发语言·python·gpt·重构·api·ai写作·agi
橙露21 分钟前
Python 图形任意角度旋转完整解决方案:原理、实现与可视化展示
开发语言·python
csbysj202026 分钟前
Perl 数组
开发语言