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;

}

相关推荐
止水编程 water_proof4 分钟前
JavaScript基础
开发语言·javascript·ecmascript
兩尛7 分钟前
215. 数组中的第K个最大元素
数据结构·算法·排序算法
952368 分钟前
数据结构-堆
java·数据结构·学习·算法
吃着火锅x唱着歌12 分钟前
LeetCode 面试题 16.24.数对和
算法·leetcode·职场和发展
不会编程的小寒13 分钟前
数据结构 2.0
数据结构·算法
欧阳x天14 分钟前
C++入门(一)
c++
专注VB编程开发20年18 分钟前
图片转矢量图(提取轮廓线条)Potrace:一个基于多边形的位图轮廓矢量化算法(translation)
算法·图片转矢量
小张成长计划..22 分钟前
【C++】:priority_queue的理解,使用和模拟实现
c++
小小测试开发30 分钟前
JMeter JSR223预处理程序高级用法:解锁自动化测试的灵活性上限
开发语言·jmeter·groovy