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 ...
随机推荐
- [LeetCode] 709. To Lower Case_Easy
Implement function ToLowerCase() that has a string parameter str, and returns the same string in low ...
- js抽红包分配
将 50000元随机分给10个人,其中3个人必须分到百位数,4个人分到千位数,3个人分到万位数,每个人所得金额 <!DOCTYPE html> <html lang="zh ...
- NodeJs--HTTP源码分析
在github上按下按键t,就可以呼出仓库搜索的面板(在大型项目中方便检索文件),检索出http.js文件检索出来,通过ctrl+F来搜索某个方法. _http_outgoing 带下划线的是私有模块 ...
- python gui messagebox
类似于win32的MessageBox框 //test.py from Tkinter import * from tkMessageBox import * root = Tk() li = ['C ...
- Jenkins自动化构建(一)执行selenium+python脚本
Jenkins执行python写的selenium自动化脚本,通常会遇到,执行打不开浏览器,查看jenkins构建Console Output控制台输出信息,发现脚本是执行了的,但是出错了,打开浏览器 ...
- System.Web.HttpException (0x80004005): 验证视图状态 MAC 失败。如果此应用程序由网络场或群集承载,请确保 <machineKey> 配置指定了相同的 validationKey 和验证算法。不能在群集中使用 AutoGenerate。
异常描述: Global.asax捕获到异常:System.Web.HttpException (0x80004005): 验证视图状态 MAC 失败.如果此应用程序由网络场或群集承载,请确保 < ...
- jquery简介未完成
jQuery jQuery是一个快速.简洁的javascript框架,是继prototype之后又一个优秀的代码库(或者javascript框架).jQuery设计的宗旨是writeLess,Do M ...
- 17.在自适应屏幕里通过JQ来获取宽高并赋给需要的
在自适应屏幕里通过JQ来获取宽高并赋给需要的div. var height = document.documentElement.clientHeight; $(window).height();(同 ...
- django-pagination 样式修改
默认 django-pagination 样式: 使用bootstrap后样式: (有些瑕疵,下面来完善一下) 修改后: 效果还不错吧.那么讲下如何修改. 首先找到其源码: (路径:site-pac ...
- STL之Deque容器
1.Deque容器 1)deque是“double-ended queue”的缩写,和vector一样都是STL的容器,deque是双端数组,而vector是单端的. 2)deque在接口上和vect ...