Write a small calculator calc(a, op, b): op is one of '+', '-', '*', '/', and you return the result of a op b. For example, calc(6, '/', 4) is 1.5. For any other sign, return 0. When dividing, b is never 0.
calc(3, '+', 5)→8.0calc(6, '/', 4)→1.5double calc(double a, char op, double b)double calc(double a, char op, double b) {
double r = 0;
switch (op) {
case '+': r = a + b; break;
// your code here: the cases for minus, times and divide, each with break
}
return r;
}
Run tries the examples. When they look right, Submit.