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
#include <iostream>
using namespace std;
 
class Statistics {
    int *stack;
    int index;
public:
    Statistics() { stack = new int[100]; index = 0; }
    ~Statistics() { delete[]stack; }
    bool operator!();
    Statistics& operator<< (int x);
    void operator~();
    void operator>>(int &avg);
};
 
bool Statistics::operator!() {
    if (index == 0return true;
    else return false;
}
 
Statistics& Statistics::operator<<(int x) {
    stack[index] = x;
    index++;
    return *this;
}
 
void Statistics::operator~() {
    for (int i = 0; i < index; i++cout << stack[i] << ' ';
    cout << '\n';
}
 
void Statistics::operator>>(int &avg) {
    int sum = 0;
    for (int i = 0; i < index; i++) sum += stack[i];
    avg = sum / index;
}
 
int main() {
    Statistics stat;
    if (!stat) cout << "현재 통계 데이타가 없습니다." << '\n';
 
    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 << '\n';
}
cs


+ Recent posts