#include "Calculator.h"
#include
#include
Calculator::Calculator(double i, double j, char *prt) {
operand1 = i;
operand1 = j;
operation = new char[20];
strcpy_s(operation, 10, prt);
};
double Calculator::doOperation() {
if (strcmp(operation, "div") == 0) {
if (operand2 == 0) {
std::cout << "operand2 can't be 0" << std::endl;
return 1;
}
return operand1 / operand2;
}
else if(strcmp(operation, "minus") == 0)
return operand1 - operand2;
else if(strcmp(operation, "multi") == 0)
return operand1 * operand2;
else if(strcmp(operation, "plus") == 0)
return operand1 + operand2;
};
using namespace std;
int main(int argc, char *argv[]) {
if (argc != 4) {
cout << "You must give 4 arguments!" << endl;
return 1;
}
double op1, op2,m;
char *opcode;
op1 = atof(argv[2]);
op2 = atof(argv[3]);
opcode = argv[1];
Calculator one(op1, op2, opcode);
m = one.doOperation();
cout << m << endl;
return 0;
}
include的部分显示不出来,其实是没问题的,这个编辑器真难用