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. 158A

    #include <iostream> #include <algorithm> using namespace std; int main() { int groups[10 ...

  2. 开发十年,只剩下这套Java开发体系了

    蓦然回首自己做开发已经十年了,这十年中我获得了很多,技术能力.培训.出国.大公司的经历,还有很多很好的朋友.但再仔细一想,这十年中我至少浪费了五年时间,这五年可以足够让自己成长为一个优秀的程序员,可惜 ...

  3. Django 模板中 变量 过滤器的使用方法

    一.变量       1.变量的形式是:{{variable}}, 当模板引擎碰到变量的时候,引擎使用变量的值代替变量.    2.使用dot(.)能够访问变量的属性    3.当模板引擎碰到dot的 ...

  4. Hadoop生态集群hdfs原理(转)

    初步掌握HDFS的架构及原理 原文地址:https://www.cnblogs.com/codeOfLife/p/5375120.html   目录 HDFS 是做什么的 HDFS 从何而来 为什么选 ...

  5. AOP 入门

    1,源码 Application.java package com.bf; import org.springframework.context.ApplicationContext; import ...

  6. spring的面向切面实现的两种方式

    面向切面:主要应用在日志记录方面.实现业务与日志记录分离开发. spring面向切面有两种实现方式:1.注解 2.xml配置. 1.注解实现如下: (1)配置如下: <?xml version= ...

  7. [LeetCode] 620. Not Boring Movies_Easy tag: SQL

    X city opened a new cinema, many people would like to go to this cinema. The cinema also gives out a ...

  8. [LeetCode] 455. Assign Cookies_Easy tag: Sort

    Assume you are an awesome parent and want to give your children some cookies. But, you should give e ...

  9. kdevelp 导入makefile工程

    比如upx工程,将upx/src/makefile中makefile改为makefile.am,自用kdevelop导入工程找到makefile.am,生成工程后去掉.am,这样就可以像vs一样调试程 ...

  10. dotnet 命令

    以下用实例串起dotnet常用命令,带你玩转dotnet命令. 1.创建(dotnet new) 首先我们创建一个项目,这里我们创建控制台程序,命令如下图所示. dotnet new dotnet n ...