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 ...
随机推荐
- golang 与 c语言 之间传递指针的规则提案
https://go.googlesource.com/proposal/+/master/design/12416-cgo-pointers.md https://github.com/golang ...
- 百度云同同步盘 mac版
百度云同步盘
- check process id exists
kill -0 pid sending the signal 0 to a given PID just checks if any process with the given PID is run ...
- vue项目中别个访问你的本地调试需要改东西
- linux 系统 cp: omitting directory 问题解决
在linux系统中复制文件夹时提示如下: cp: omitting directory `foldera/' 其中foldera是我要复制的文件夹名,出现该警告的原因是因为foldera目录下还存在目 ...
- linux临时网络配置
1.设置IP地址: ifconfig ens33 192.168.60.231/24 2.添加默认网关路由 $Route add default gw <默认网关地址> 例:#route ...
- DES加解密 cbc模式 的简单讲解 && C++用openssl库来实现的注意事项
DES cbc是基于数据块加密的.数据块的长度为8字节64bit.以数据块为单位循环加密,再拼接.每个数据块加密的秘钥一样,IV向量不同.第一个数据快所需的IV向量,需要我们提供,从第二个数据块开始, ...
- Linux shell脚本 批量创建多个用户
Linux shell脚本 批量创建多个用户 #!/bin/bash groupadd charlesgroup for username in charles1 charles2 charles3 ...
- java.lang.ClassNotFoundException: org.hibernate.engine.FilterDefinition的解决方案
今天在GitHub上面看到一个有意思的项目,下载下来,使用tomcat部署失败,出现异常,网上说JDK版本太高,改低,还是失败. 由于本人有个习惯,更喜欢把项目直接放入tomcat webapps 里 ...
- E. Bear and Drawing
E. Bear and Drawing time limit per test 1 second memory limit per test 256 megabytes input stan ...