-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path28.cpp
97 lines (74 loc) · 1.95 KB
/
28.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <ctime>
#include <string>
using namespace std;
class Heart {
private:
float _purseRate; // 박동수
public:
Heart(float purseRate)
: _purseRate(purseRate)
{
cout << "Heart의 생성자" << endl;
}
~Heart() {
cout << "Heart의 소멸자" << endl;
}
void Show() {
cout << "심장이 " << _purseRate << "로 뛰고 있습니다." << endl;
}
};
class Watch {
private:
string _color;
public:
Watch(string color)
: _color(color) {
cout << "Watch의 생성자" << endl;
}
~Watch() {
cout << "Watch의 소멸자" << endl;
}
string GetColor() {
return _color;
}
void DisplayCurrentTime() {
time_t timer;
struct tm* t;
timer = time(NULL);
t = localtime(&timer);
cout << _color << "Watch의 현재시각은 : " << t->tm_year + 1900 << "년 " << t->tm_mon << "월 "
<< t->tm_mday << "일 " << t->tm_hour << "시 " << t->tm_min << "분 입니다." << endl;
}
};
class Human {
private:
Heart _heart; // 포함관계 Composition (강한결합) // 포함한객체와 생명주기를 같이함.
Watch& _refWatch; // 참조 관계 agreggation(약한결합) // 포함한 객체와 생명주기를 같이 하지 않음.
public:
Human(float purseRate, Watch& refWatch)
:_heart(purseRate), _refWatch(refWatch)
{
cout << "Human 생성자" << endl;
}
~Human() {
cout << "Human 소멸자" << endl;
}
void ShowHeartRate() {
_heart.Show();
}
void DisplayWatch() {
_refWatch.DisplayCurrentTime();
}
};
int main() {
Watch redWatch("빨간");
cout << "-------------------------- 프로그램 시작 -------------------------------\n";
{
Human human(70, redWatch);
human.ShowHeartRate();
human.DisplayWatch();
}
cout << "-------------------------- 프로그래밍 종료 -----------------------------\n";
}