参考方法:
#include
using namespace std;
float add(float num1,float num2){return num1+num2;}
float mns(float num1,float num2){return num1-num2;}
float tms(float num1,float num2){return num1*num2;}
float div(float num1,float num2){return num1/num2;}
mapfun;
int main()
{
char op;
float num1, num2;
cout << "输入运算符:+、-、*、/ : ";
cin >> op;
cout << "输入两个数: ";
cin >> num1 >> num2;
try
{
if(fun.count(op))fun(num1,num2);
else cout << "Error! 请输入正确运算符。";
}
catch(ZeroDivisionError){cout << "Error! 不能除以0。";}
return 0;
}
314
314
211***7774@qq.com2年前 (2019-02-15)