728x90
#include <iostream>
#include <string>
using namespace std;

class Adder {
protected:
	int add(int a, int b) { return a + b; }
};

class Subtractor {
protected:
	int minus(int a, int b) { return a - b; }
};

class Mul {
protected:
	int mul(int a, int b) { return a * b; }
};

class Div {
protected:
	int div(int a, int b) { return a / b; }
};

// 다중 상속
class Calculator : public Adder, public Subtractor, public Mul, public Div {
public:
	int calc(char op, int a, int b);
};

int Calculator::calc(char op, int a, int b) {
	int res = 0;
	switch (op) {
	case '+': res = add(a, b); break;
	case '-': res = minus(a, b); break;
	case '*': res = mul(a, b); break;
	case '/': res = div(a, b); break;
	}
	return res;
}

int main() {
	cout << "2018305065 전유정" << endl << endl;

	Calculator handCalculator;

	char answer, op;
	int x, y;

	while (true) {
		cout << "연산을 입력하세요 >> " << endl;
		cin >> x >> op >> y;

		cout << x << ' ' << op << ' ' << y << " = ";
		cout << handCalculator.calc(op, x, y) << endl;

		cout << "계속 하시겠습니까?(Y/N) >> ";
		cin >> answer;
		if (answer == 'N') break;
	}
		
}

반응형
  • 네이버 블러그 공유하기
  • 네이버 밴드에 공유하기
  • 페이스북 공유하기
  • 카카오스토리 공유하기