代码:
class Calculator {
double operand1, operand2;
char operation;
public:
Calculator(double, double, char);
double doOperation();
};
#include "Calculator.h"
#include
Calculator::Calculator(double op1, double op2,char* opcode) {
this->operand1 = op1;
this->operand2 = op2;
strcpy_s(operation,10,opcode);
}
double Calculator::doOperation() {
if (strcmp(operation,"div") == 0)
return operand1 / operand2;
else if (strcmp(operation, "plus") == 0)
return operand1 + operand2;
else if (strcmp(operation, "minus") == 0)
return operand1 - operand2;
else if (strcmp(operation, "multi") == 0)
return operand1*operand2;
};
#include
#include "Calculator.h"
#include
using namespace std;
int main(int argc, char *argv[]) {
if (argc != 4) {
cerr << "Please input valid arguments";
return -1;
}
double op1 = atof (argv[2]);
double op2 = atof (argv[3]);
char *opcode = argv[1];
Calculator one(op1, op2, opcode);
double m = one.doOperation();
cout << m<< endl;
return 0;
}
![调试中断的错误](https://img-ask.csdn.net/upload/201705/06/1494043273_141491.png)
![debugger stop](https://img-ask.csdn.net/upload/201705/06/1494043221_345985.png)