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. Python笔记:调用函数,带扩号和和不带括号的区别

    调用函数,如果带括号,那么是调用函数运行后的结果, 调用函数不带括号,调用的是函数本身 例如: def cun (a,b): return a+b print(cun) : 调用函数,打印的是函数 p ...

  2. kickstart模式实现批量安装centos7.x系统

    1.1 安装系统的方法 l  光盘(ISO文件,光盘的镜像文件)===>>每一台物理机都得给一个光驱,如果用外置光驱的话,是不是每台机器都需要插一下 l  U盘:ISO镜像刻录到U盘==& ...

  3. [py]python __file__ 与argv[0]

    http://andylin02.iteye.com/blog/933237 BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__ ...

  4. div+CSS实现页面的布局要点记录

    1.页面任何控件可以通过div包装为一个模块,然后通过margin(外补丁)和padding(内补丁)对控件位置的摆放进行控制,以实现想要的效果. 2.position:absolute;对控件实现绝 ...

  5. 2019.03.25 git

    Git简介: Git是一个分布式版本控制软件. 背景故事: Linus在1991年创建了开源的Linux. 在2002年以前:世界各地的志愿者把源代码文件通过diff的方式发给Linus,然后Linu ...

  6. 采用Extjs MVVM + ThinkPHP 架构开发的思考

    前后台号称都是MVC模式, 后台ThinkPHP框架实际上只提供web操作接口,直接返回json数据,因此只能算有Model和Controller两层, 前台ExtjsMVVM模式实际上就是分模块后的 ...

  7. ELK(下)

    ELK架构图: 架构图一: 这是最简单的一种ELK架构方式.优点是搭建简单,易于上手.缺点是Logstash耗资源较大,运行占用CPU和内存高.另外没有消息队列缓存,存在数据丢失隐患. 此架构由Log ...

  8. Windows(华硕/联想)笔记本上安装黑苹果与win双系统教程

    声明:电脑小白者请谨慎安装,如有需要可私聊或留言提供安装工具 首先说明:Windows PC的文件操作系统也就是磁盘格式是FAT32或 NTFS ,而 Mac 的文件操作系统格式是 HFS ,所以这时 ...

  9. 43.HTML--a标签之mailto邮箱属性用法

    HTML 属性标记之 mailto 的用法详解   大家知道,mailto是网页设计制作中的一个非常实用的html标签,许多拥有个人网页的朋友都喜欢在网站的醒目位置处写上自己的电子邮件地址,这样网页浏 ...

  10. webapp定位

    <!doctype html> <html> <head> <meta charset="utf-8"> <meta http ...