[C++]2つの整数を受け入れて演算する


名品c++第3章第10題
#include <iostream>
using namespace std;

class Add { 
private:
    int a ; int b ;
public:
    void setValue(int x, int y) {
        a = x ; b = y;
    };
    int calculate() {
        return a + b;
    };
};


class Sub { 
private:
    int a ; int b ;
public:
    void setValue(int x, int y) {
        a = x ; b = y;
    }; 
    int calculate() {
        return a - b;
    };
};
class Mul { 
private:
    int a ; int b ;
public:
    void setValue(int x, int y) {
        a = x ; b = y;
    };
    int calculate() {
        return a*b;
    };
};
class Div { 
private:
    int a ; int b ;
public:
    void setValue(int x, int y) {
        a = x ; b = y;
    };
    int calculate() {
        return a / b;
    };
};


int main () {
    Add a;
    Sub s;
    Mul m;
    Div d;

    char c; int x; int y;

    while(true){
        cout << "두 정수와 연산자를 입력하세요>>";
        cin >> x >> y >> c;  
        if(c == '+') {
       a.setValue(x,y);
       cout << a.calculate() << endl;
        }
        else if(c == '-') {
       s.setValue(x,y);
       cout << s.calculate() << endl;
        }
        else if(c == '*') {
       m.setValue(x,y);
       cout << m.calculate() << endl;
        }
        else if(c == '/') {
       d.setValue(x,y);
       cout << d.calculate() << endl;
        }
    }

};