-
Notifications
You must be signed in to change notification settings - Fork 0
/
ch7 실습문제 10.cpp
63 lines (51 loc) · 1.01 KB
/
ch7 실습문제 10.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
#include <iostream>
using namespace std;
class Statistices {
int* p;
int size;
public:
Statistices() { int size = 0; p = new int[8]; }
bool operator! ();
Statistices& operator<<(int x);
void operator~();
void operator>>(int& avg);
};
bool Statistices::operator!()
{
if (this->size = 0)
return true;
else
return false;
}
Statistices& Statistices::operator<<(int x)
{
this->p[this->size] = x;
this->size++;
return *this;
}
void Statistices::operator~()
{
for (int i = 0; i < this->size; i++)
cout << this->p[i] << ' ';
}
void Statistices::operator>>(int& avg)
{
int sum = 0;
for (int i = 0; i < this->size; i++)
sum = sum + this->p[i];
avg = sum / this->size;
}
int main()
{
Statistices stat;
if (!stat) cout << "현재 통계 데이터가 업습니다" << endl;
int x[5];
cout << "5개의 정수를 입력하세요>>";
for (int i = 0; i < 5; i++) cin >> x[i];
for (int i = 0; i < 5; i++) stat << x[i];
stat << 100 << 200;
~stat;
int avg;
stat >> avg;
cout << "avg=" << avg << endl;
}