to refactor for refactor

时间:2022-04-25 16:26:33

v1.1 if all algorithm are in one function, it will expand. so each operate type should be separated.

question: if add scientific

operation.cpp:

#include "operation.h"

int OperationAdd(string number1, string number2){

int result= atoi(number1.c_str())+atoi(number2.c_str());

return result;

}

int OperationMinus(string number1, string number2){

int result= atoi(number1.c_str())-atoi(number2.c_str());

return result;

}

int OperationBy(string number1, string number2){

int result= atoi(number1.c_str())*atoi(number2.c_str());

return result;

}

int OperationDivide(string number1, string number2){

int result= atoi(number1.c_str())/atoi(number2.c_str());

return result;

}

int Operation(string number1, string number2, string operateType){

int result=0;

if(operateType=="+"){

result = OperationAdd(number1, number2);

}

else if(operateType=="-"){

result = OperationMinus(number1, number2);

}

else if(operateType=="*"){

result = OperationBy(number1, number2);

}

else if(operateType=="/"){

result = OperationDivide(number1, number2);

}

else{

result =0;

}

return result;

}