#include <iostream> // cout, cin
#include <string> // to_string()
#include <limits> // numeric_limits<>
using namespace std;
const int kError = numeric_limits<int>::min();
int add(int, int);
int subtract(int, int);
int multiply(int, int);
int divide(int, int);
int invoke(int, int, int (*)(int, int));
int main() {
int op1, op2;
cout << "Operand 1: ";
cin >> op1;
cout << "Operand 2: ";
cin >> op2;
int quotient = invoke(op1, op2, divide);
cout << op1 << " + " << op2 << " = " << invoke(op1, op2, add) << '\n'
<< op1 << " - " << op2 << " = " << invoke(op1, op2, subtract) << '\n'
<< op1 << " x " << op2 << " = " << invoke(op1, op2, multiply) << '\n'
<< op1 << " / " << op2 << " = "
<< (quotient == kError ? "undefined" : to_string(quotient)) << '\n';
return 0;
}
int add(int x, int y) {
return x + y;
}
int subtract(int x, int y) {
return x - y;
}
int multiply(int x, int y) {
return x * y;
}
int divide(int x, int y) {
return y == 0 ? kError : x / y;
}
int invoke(int x, int y, int (*function)(int, int)) {
return function(x, y);
}