first step, only aim to work.

it works, but i have not seen the necessaty to use class yet.

my question, why use class?

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的更多相关文章

  1. to refactor for refactor

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

  2. Delphi Refactor 重构

    delphi refactor procedure TCameraComponentForm.btnRefreshConfigClick(Sender: TObject); var a:string; ...

  3. [React] Refactor a Class Component with React hooks to a Function

    We have a render prop based class component that allows us to make a GraphQL request with a given qu ...

  4. Xcode的Refactor使用

    最近在看<重构>的书,想到Xcode有一个Refactor的功能,不知道您用的多不多,用这个功能在我们开发过程中,可以提高开发效率. Refactor 右键显示 Refactor 一.Re ...

  5. [Algorithms] Refactor a Linear Search into a Binary Search with JavaScript

    Binary search is an algorithm that accepts a sorted list and returns a search element from the list. ...

  6. [Algorithms] Refactor a Loop in JavaScript to Use Recursion

    Recursion is when a function calls itself. This self calling function handles at least two cases, th ...

  7. [React] Refactor a connected Redux component to use Unstated

    In this lesson, I refactor a simple Counter component connected to Redux to use Unstated instead. I ...

  8. [React] Refactor componentWillReceiveProps() to getDerivedStateFromProps() in React 16.3

    The componentWillReceiveProps() method is being deprecated in future version of React (17). Many of ...

  9. [Ramda] Refactor to Point Free Functions with Ramda using compose and converge

    In this lesson we'll take some existing code and refactor it using some functions from the Ramda lib ...

随机推荐

  1. mysql的查询

    1.单表查询 单表查询的语法 SELECT 字段1,字段2... FROM 表名 WHERE 条件 GROUP BY field HAVING 筛选 ORDER BY field LIMIT 限制条数 ...

  2. 编辑文件 vi,vim的基本操作

    vim   文件名字进入文件后   按i  进行编辑编辑确认后   按 Esc  停止编辑然后              按:   输入  wq     (是root权限时才行:若是强制修改 需要  ...

  3. 2018-2019-1 20189221《Linux内核原理与分析》第三周作业

    2018-2019-1 20189221<Linux内核原理与分析>第三周作业 实验二 完成一个简单的时间片轮转多道程序内核代码 实验过程 在实验楼中编译内核 编写mymain.c函数和m ...

  4. 给下拉列表添加options

    var myOptions = { val1 : 'text1', val2 : 'text2' }; var mySelect = $('#mySelect'); $.each(myOptions, ...

  5. mybatis调用oracle存储过程 out游标类型参数 如何赋给java map

    <resultMap id="ticketInfosResultMap" type="Map"> <!--result要是默认用列名的话完全不 ...

  6. php二维数组搜索

    $ar = array(     2 => array(         'catid' => 2,         'catdir' => 'notice',     ),     ...

  7. 使用socat查看ios日志

    仅供记录自己查看 mac连接ios后进程ios shell apt-get socat安装 socat socat - UNIX-CONNECT:/var/run/lockdown/syslog.so ...

  8. 前端获取的数据是undefined

    var id = $("id1").val(); var username = $("username1").val(); var password = $(& ...

  9. winform下picturebox控件显示图片问题

    viewData_pictureBox.SizeMode=PictureBoxSizeMode.StretchImage;图片会自动按照比例缩放来完全显示在你的PictureBox中.

  10. C# HtmlDocument和HtmlNode的使用以及节点的模糊查询

    C#HtmlAgilityPack.HtmlDocument和HtmlAgilityPack.HtmlNode的使用 HtmlAgilityPack.HtmlDocument response = n ...