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;

}

相关推荐
网安INF3 分钟前
RSA加密算法:非对称密码学的基石
java·开发语言·密码学
明月*清风4 分钟前
c++ —— 内存管理
开发语言·c++
蔡蓝8 分钟前
设计模式-观察着模式
java·开发语言·设计模式
WindSearcher24 分钟前
大模型微调相关知识
后端·算法
取酒鱼食--【余九】34 分钟前
rl_sar实现sim2real的整体思路
人工智能·笔记·算法·rl_sar
西北大程序猿1 小时前
单例模式与锁(死锁)
linux·开发语言·c++·单例模式
你不是我我1 小时前
【Java开发日记】说一说 SpringBoot 中 CommandLineRunner
java·开发语言·spring boot
心扬1 小时前
python网络编程
开发语言·网络·python·tcp/ip
qq_454175791 小时前
c++学习-this指针
开发语言·c++·学习
尘浮7282 小时前
60天python训练计划----day45
开发语言·python