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;
}