码迷,mamicode.com
首页 > 其他好文 > 详细

game to refactor for refactor

时间:2015-02-14 14:56:14      阅读:119      评论:0      收藏:0      [点我收藏+]

标签:

main.cpp:

#include <iostream>

#include <iostream>

#include "operation.h"

using namespace std;

 

 

int main(int argc, const char * argv[]) {

    // insert code here...

    std::cout << "Hello!\n";

    string numberA,numberB,operateType;

    std::cout<<"please input numberA:\n";

    std::cin >>numberA;

    std::cout<<"operate type";

    std::cin>>operateType;

    std::cout<<"please input numberB:\n";

    std::cin>>numberB;

    

    

    std::cout<<"output:"<<Operation(numberA,numberB,operateType);

    //why use class to

    

    return 0;

}

 

operation.h:

#include <iostream>

using namespace std;

 

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

 

operation.cpp:

#include "operation.h"

 

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

    int result=0;

    if(operateType=="+"){

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

    }

    else if(operateType=="-"){

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

    }

    else if(operateType=="*"){

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

    }

    else if(operateType=="/"){

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

    }

    else{

        result =0;

    }

    return result;

}

game to refactor for refactor

标签:

原文地址:http://www.cnblogs.com/dannykong/p/4291536.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!