补全Calculator.h文件中的Calc、add、sub、mult、divi函数,以实现计算器功能
时间: 2023-07-04 20:06:37 浏览: 130
advanced.scientific.calculator.calc991.plus(1).apk
```c++
#ifndef CALCULATOR_H
#define CALCULATOR_H
class Calculator {
public:
static double Calc(double num1, char op, double num2);
static double add(double num1, double num2);
static double sub(double num1, double num2);
static double mult(double num1, double num2);
static double divi(double num1, double num2);
};
#endif // CALCULATOR_H
```
```c++
#include "Calculator.h"
double Calculator::Calc(double num1, char op, double num2) {
switch(op) {
case '+':
return add(num1, num2);
case '-':
return sub(num1, num2);
case '*':
return mult(num1, num2);
case '/':
return divi(num1, num2);
default:
return 0.0;
}
}
double Calculator::add(double num1, double num2) {
return num1 + num2;
}
double Calculator::sub(double num1, double num2) {
return num1 - num2;
}
double Calculator::mult(double num1, double num2) {
return num1 * num2;
}
double Calculator::divi(double num1, double num2) {
if(num2 == 0) return 0.0;
return num1 / num2;
}
```
阅读全文