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() << endl; break; case '-':Sub s; s.setValue(x, y); cout << s.calculate() << endl; break; case '*':Mul m; m.setValue(x, y); cout << m.calculate() << endl; break; case '/':Div d; d.setValue(x, y); cout << d.calculate() << endl; break; default:cout << "잘못된 연산자 입니다" << endl; break; } } } | cs |
'Programming > 명품 C++ Programming' 카테고리의 다른 글
| 명품 C++ Programming 실습문제 3장 9번 (0) | 2018.04.28 |
|---|---|
| 명품 C++ Programming 실습문제 3장 8-(2)번 (0) | 2018.04.28 |
| 명품 C++ Programming 실습문제 3장 7번 (0) | 2018.04.28 |
| 명품 C++ Programming 실습문제 3장 6번 (0) | 2018.04.28 |
| 명품 C++ Programming 실습문제 3장 5번 (0) | 2018.04.28 |