-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path3-10.cpp
91 lines (81 loc) · 1.19 KB
/
3-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
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
#include <iostream>
using namespace std;
class Add {
int a, b;
public:
void setValue(int x, int y);
int calculate() {
return a + b;
}
};
class Sub {
int a, b;
public:
void setValue(int x, int y);
int calculate() {
return a - b;
}
};
class Mul {
int a, b;
public:
void setValue(int x, int y);
int calculate() {
return a * b;
}
};
class Div {
int a, b;
public:
void setValue(int x, int y);
int calculate() {
return a / b;
}
};
void Add::setValue(int x, int y) {
a = x;
b = y;
}
void Sub::setValue(int x, int y) {
a = x;
b = y;
}
void Mul::setValue(int x, int y) {
a = x;
b = y;
}
void Div::setValue(int x, int y) {
a = x;
b = y;
}
int main() {
class Add a;
class Sub s;
class Mul m;
class Div d;
int x, y;
char z;
while (1) {
cout << "두 정수와 연산자를 입력하세요 >> ";
cin >> x >> y >> z;
if (z == '+') {
a.setValue(x, y);
cout << a.calculate() << endl;
}
else if (z == '-') {
s.setValue(x, y);
cout << s.calculate() << endl;
}
else if(z == '*'){
m.setValue(x, y);
cout << m.calculate() << endl;
}
else if (z == '/') {
d.setValue(x, y);
cout << d.calculate() << endl;
}
else {
cout << "잘못 입력하셨습니다." << endl;
}
}
}