game to refactor for refactor
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的更多相关文章
- to refactor for refactor
v1.1 if all algorithm are in one function, it will expand. so each operate type should be separated. ...
- Delphi Refactor 重构
delphi refactor procedure TCameraComponentForm.btnRefreshConfigClick(Sender: TObject); var a:string; ...
- [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 ...
- Xcode的Refactor使用
最近在看<重构>的书,想到Xcode有一个Refactor的功能,不知道您用的多不多,用这个功能在我们开发过程中,可以提高开发效率. Refactor 右键显示 Refactor 一.Re ...
- [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. ...
- [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 ...
- [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 ...
- [React] Refactor componentWillReceiveProps() to getDerivedStateFromProps() in React 16.3
The componentWillReceiveProps() method is being deprecated in future version of React (17). Many of ...
- [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 ...
随机推荐
- js图的数据结构处理----普里姆算法
//求加权无向连通图的MST的贪心算法 //最小树,最小路径联通各个点 function PRIM(){ var graph = [ [], [undefined,Infinity, 23 ,Infi ...
- NPOI设置单元格格式
转自:http://www.cr173.com/html/18143_2.html //创建一个常用的xls文件 private void button3_Click(object sender, E ...
- cocos2d 利用cocosStudio制作合图(plist与png)
- Web API 入门 一
因为只是是一个简单的入门.所有暂时不去研究web API一些规范.比如RESTful API 这里有个接收RESTful API的.RESTful API 什么是WebApi 看这里:http://w ...
- 《2017年Q2中国城市研究报告
根据百度慧眼团队发布的<2017年Q2中国城市研究报告>,2017年第二季度人口吸引力排名前五的城市与第一季度相同,深圳继续保持第一的领先位置.
- Service Fabric下删除实例并注销应用
Service Fabric下删除实例并注销应用: 以应用名称:Application1为例 1.打开PowerShell 2.连接集群: Connect-ServiceFabricCluster - ...
- Self hosted OWIN 绑定地址127.0.0.1,外网无法访问
static void Main() { string baseAddress = "http://localhost:4004/"; ...
- C#中生成的随机数为什么不随机?
from:https://www.xcode.me/more/net-csharp-generate-random 随机数生成方法可以说是任何编程语言必备的功能,它的重要性不言而言,在C#中我们通常使 ...
- 环形数组 最大子段和 dp
题目链接:https://nanti.jisuanke.com/t/36118 环形数组的连续最大子段和,有两种情况. 1.最大和的这个子段没有包含头尾.所以直接dp[i] = max(dp[i-1] ...
- python自定义安装包
python的第三方模块越来越丰富,涉及的领域也非常广,如科学计算.图片处理.web应用.GUI开发等.当然也可以将自己写的模块进行打包或发布.一简单的方法是将你的类包直接copy到python的li ...