6.5 作业 + 思维导图

#include <iostream>

using namespace std;

class Per {
private:
	string name;
	unsigned int age;
	unsigned int* height;
	unsigned int* weight;

public:
	Per() : name("undefined"), age(0), height(new unsigned int(0)), weight(new unsigned int(0)) {
		cout << "Per()" << endl;
	}
	Per(const string& n, const unsigned int a, const unsigned int h, const unsigned int w)
		: name(n), age(a), height(new unsigned int(h)), weight(new unsigned int(w)) {
		cout << "Per(const string& n, ..." << endl;
	}
	~Per() {
		cout << "~Per()" << endl;
		delete height;
		delete weight;
	}

	friend ostream& operator<<(ostream& os, const Per& p) {
		os << p.name << " " << p.age << " " << *(p.height) << " " << *(p.weight);
		return os;
	}
};

class Stu {
private:
	Per p1;
	double score;

public:
	Stu() : score(0) { cout << "Stu()" << endl; };
	Stu(const string& n,
		const unsigned int a,
		const unsigned int h,
		const unsigned int w,
		const double s)
		: p1(n, a, h, w), score(s) {
		cout << "Stu(const string& n, ..." << endl;
	}
	Stu(const Per& p, double s) : p1(p), score(s) { cout << "Stu(const Per& p, double s)" << endl; }
	~Stu() { cout << "~Stu()" << endl; }

	friend ostream& operator<<(ostream& os, const Stu& s) {
		os << s.p1 << " " << s.score;
		return os;
	}
};

int main() {
	Stu s1;
	cout << "========================" << endl;
	Stu s2("lucy", 18, 160, 50, 99);
	cout << s2 << endl;
	cout << "========================" << endl;
}

  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值