首页 > 其他 > 详细

to refactor for refactor

时间:2015-02-15 20:31:15      阅读:220      评论:0      收藏:0      [点我收藏+]

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;

}

 

to refactor for refactor

原文:http://www.cnblogs.com/dannykong/p/4293426.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!