1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
|
#include <iostream>
#include <map>
using namespace std;
int main()
{
map<char,double (*)( double, double )> F =
{ { '+', []( double a, double b ){ return a + b; } },
{ '-', []( double a, double b ){ return a - b; } },
{ '*', []( double a, double b ){ return a * b; } },
{ '/', []( double a, double b ){ return a / b; } } };
double a, b;
char op;
cout << "Input a op b, where op is one of +, -, *, / \n";
cin >> a >> op >> b;
cout << F[op]( a, b ) << '\n';
}
| |