#include <cmath>
#include <iostream>
using namespace std;
struct Function {
double x = 0;
void args(const double _x) {
x = _x;
}
private:
inline static const auto n = 16.0;
double f() const {
const auto y = n - pow(x, 2);
if (y > 0) return log(y);
if (y < 0) return sin(y);
return -2.0;
}
friend ostream& operator<<(ostream& out, const Function& table) {
if (Function::n != pow(table.x, 2)) {
cout.setf(ios::fixed);
cout.precision(15);
}
return out << table.f();
}
};
double input(const char* prompt) {
cout << prompt;
double value;
cin >> value;
cin.ignore(0x1000, '\n');
return value;
}
int main() {
const auto x = input("x: ");
Function fn;
fn.args(x);
cout << "z(x) = " << fn << '\n';
}
С++