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;

}

相关推荐
llz_1129 分钟前
蓝桥杯备赛-搜索(DFS/BFS)
c++·算法·蓝桥杯·深度优先·宽度优先
康小庄12 分钟前
Java读写锁降级
java·开发语言·spring boot·python·spring·java-ee
山顶夕景13 分钟前
【Math】数学知识点串联
人工智能·数学·算法·机器学习
毕设源码-钟学长16 分钟前
【开题答辩全过程】以 基于Java的停车场信息管理系统设计与实现为例,包含答辩的问题和答案
java·开发语言
Mr -老鬼17 分钟前
基于 Go 的脚本平台 APP 云控系统
开发语言·后端·golang
hewence119 分钟前
Kotlin CoroutineScope解密
android·开发语言·kotlin
咩图21 分钟前
VSCode+Python创建项目
开发语言·python
Hag_2021 分钟前
LeetCode Hot100 42.接雨水
算法·leetcode·职场和发展
zhanglu511623 分钟前
Java Lambda 表达式使用深度解析
开发语言·前端·python