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. 什么是AOP面向切面编程

    什么是AOP 连接地址:http://blog.csdn.net/moreevan/article/details/11977115/ AOP(Aspect-OrientedProgramming,面 ...

  2. [Java in NetBeans] Lesson 05. Method/function

    这个课程的参考视频和图片来自youtube. 主要学到的知识点有: Define a method:(motivation: write one time, but use it many times ...

  3. 《Java程序设计》第一周学习记录(2)

    目录 使用JDB调试程序 系统文件被覆盖的挽救 参考资料 使用JDB调试程序 JDB是JDK自带的基于命令行的调试程序.我们先来man一下吧(说到这里,我之前在翻娄老师的博客的时候看到一篇文章:做中学 ...

  4. python 判断字符串是否包含子字符串

    第一种方法:in string = 'helloworld' if 'world' in string: print 'Exist' else: print 'Not exist' 第二种方法:fin ...

  5. idc指令相关

    #按不同数据类型打印当前地址opcode print Byte(ea) print Word(ea) print Dword(ea)

  6. 如何遍历tabcontrol控件的所有的tabpage中的所有控件

    foreach(Control c in tabControl1.TabPages)这个循环的意思是说,遍历tabControl1中所有的TabPages,TabPages是包含在tabControl ...

  7. arcgis api for js简要笔记

    1.主要借助官网的接口文档和samplecode来学习 https://developers.arcgis.com/javascript/latest/api-reference/index.html ...

  8. RabbitMQ理论

    RabbitMQ理论   消息 = 有效载荷(数据) + 标签(包含载荷和收件人的信息)   信道:你的应用于RabbitMQ代理服务器之间的TCP连接(有唯一的ID),信道主要解决了每一个线程单独T ...

  9. Intel 80386 微处理器的存储器管理

    一.存储器的管理       存储器的管理是一种硬件机制,微处理器在总线地址上对物理存储器进行寻址.但是,为了给程序提供比物理存储器容量更大的空间,就引入了虚拟存储器的概念,它在外存(比如磁盘)的支持 ...

  10. php实现多进程

    转:http://www.jb51.net/article/71238.htm cd php-version/ext/pcntl phpize ./configure && make ...