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 ...
随机推荐
- jQuery-velocity.js 插件的简易使用
初识Velocity动画,感觉它并没有那么强大,但是渐渐感觉它的ui动画可以让我们简易的使用到我们的项目中. Velocity动画的简介: 下载地址:http://www.julian.com/res ...
- 【Tools】-NO.10.Tools.2.IDEA.1.001-【IDEA Configuration】-
1.0.0 Summary Tittle:[Tools]-NO.10.Tools.2.IDEA.1.001-[IDEA Configuration]- Style:Tools Series:IDEA ...
- [LeetCode] 162. Find Peak Element_Medium tag: Binary Search
A peak element is an element that is greater than its neighbors. Given an input array nums, where nu ...
- [LeetCode] 744. Find Smallest Letter Greater Than Target_Easy tag: **Binary Search
Given a list of sorted characters letters containing only lowercase letters, and given a target lett ...
- SDWebImage代码赏析
过NSOperationQueue来控制 为了保护变量,使用大量了sychronized 读的时候使用了dispatch_sync dispatch_sync(sself.barrierQueue, ...
- cocos2d JS-(JavaScript) JavaScript 中的简单继承关系
JavaScript 语言本身没有提供类,没有其他语言的类继承机制,它的继承时通过对象的原型实现的,但这不能满足我们对 Cocos2d-JS 引擎的要求,所有类都直接或间接继承实现的. var Per ...
- 1.Spring对JDBC整合支持
1.Spring对JDBC整合支持 Spring对DAO提供哪些支持 1)Spring对DAO异常提供统一处理 2)Spring对DAO编写提供支持的抽象类 3)提高编程效率,减少DAO编码量 Spr ...
- Nginx配置文件具体配置解释
Nginx配置文件具体配置解释 #定义Nginx运行的用户和用户组 user www www; #nginx进程数,建议设置为等于CPU总核心数. worker_processes 8; #全局错 ...
- AngularJs ng-change事件/指令(转)
from:http://blog.csdn.net/u011127019/article/details/52564111 定义和用法 ng-change 指令用于告诉 AngularJS 在 HTM ...
- Oracle数据库分区相干知识点
Partition Characteristics:1.Partition Key;2.Partitioning Strategies Partitioning Strategies:1. range ...