1 #include
2 #include
3 #include
4 #include
5
6 using namespacestd;7
8 //四则运算
9 template classElementaryArithmetic{10 private:11 T result;12 T operand1, operand2;13 charoperators;14 public:15 //四则运算
16 voidCalculate();17 //加法运算
18 voidadd(T, T);19 //减法运算
20 voidsubtraction(T, T);21 //乘法运算
22 voidmultiplication(T, T);23 //除法运算
24 voiddivide(T, T);25 //输出运算符重载
26 template friend ostream &operator< &);27 };28
29 //四则运算
30 template void ElementaryArithmetic::Calculate(){31 inttype;32
33 loop1:34 system("cls");35 cout << endl << "*******************" <>type;44 if (type != 1 && type != 2 && type != 3 && type != 4)45 throw 1;46 }47 catch (inte){48 cout << endl << "输入错误,请重新输入选项...";49 system("pause")