#include <iostream>
using namespace std;
struct Operation {
static double add(const double a, const double b) {
return a + b;
}
static double subtract(const double a, const double b) {
return a - b;
}
static double multiply(const double a, const double b) {
return a * b;
}
static double divide(const double a, const double b) {
return a / b;
}
static double power(const double a, const double b) {
return exp(b * log(a));
}
};
struct Calculator {
void calc() const {
double a, b, result;
char op;
bool error;
while (true) {
error = false;
cout << ">>> ";
cin >> a >> op >> b;
switch (op) {
case '+':
result = Operation::add(a, b);
break;
case '-':
result = Operation::subtract(a, b);
break;
case '*':
result = Operation::multiply(a, b);
break;
case '/':
if (!b) {
puts("Division by zero.");
error = true;
break;
}
result = Operation::divide(a, b);
break;
case '^':
result = Operation::power(a, b);
if (isnan(result)) {
puts("Invalid argument.");
error = true;
}
break;
default:
cout << "Unknown operation: " << op << '\n';
error = true;
}
if (!error) {
cout << "<<< " << result << '\n';
}
}
}
};
int main() {
Calculator calculator;
calculator.calc();
}
#include <iostream>
#include <cmath>
using namespace std;
int main()
{
char x;
int a, b;
const int e = 2.7;
setlocale(LC_ALL, "RUS");
cout << "Действие: ";
cin >> x;
cout << "Число a: ";
cin >> a;
cout << "Число b: ";
cin >> b;
switch (x) {
case '+': cout << sqrt(pow(e,b*log(a))) + b; break
case '-': cout << sqrt(pow(e, b * log(a))) - b; break
case '*': cout << sqrt(pow(e, b * log(a))) * b; break
case '/': cout << sqrt(pow(e, b * log(a))) / b; break
case '^': cout << pow(sqrt(pow(e, b * log(a))),b);
}
}
чё кароче в бошку взбрело то и написал