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
#include <iostream>
using namespace std;
 
class Add {
    int a;
    int b;
public:
    void setValue(int x, int y) { a = x; b = y; }
    int calculate() { return a + b; }
};
class Sub {
    int a;
    int b;
public:
    void setValue(int x, int y) { a = x; b = y; }
    int calculate() { return a - b; }
};
class Mul {
    int a;
    int b;
public:
    void setValue(int x, int y) { a = x; b = y; }
    int calculate() { return a * b; }
};
class Div {
    int a;
    int b;
public:
    void setValue(int x, int y) { a = x; b = y; }
    int calculate() { return a / b; }
};
 
int main() {
    int x, y;
    char op;
    while (1) {
        cout << "두 정수와 연산자를 입력하세요>>";
        cin >> x >> y >> op;
        switch (op) {
        case '+':Add a; a.setValue(x, y); cout << a.calculate() << endlbreak;
        case '-':Sub s; s.setValue(x, y); cout << s.calculate() << endlbreak;
        case '*':Mul m; m.setValue(x, y); cout << m.calculate() << endlbreak;
        case '/':Div d; d.setValue(x, y); cout << d.calculate() << endlbreak;
        default:cout << "잘못된 연산자 입니다" << endlbreak;
        }
    }
}
cs


+ Recent posts