Top.Mail.Ru
Ответы

Помогите решить через С++

По дате
По рейтингу
Аватар пользователя
Новичок
123456789101112131415161718192021222324252627282930313233343536373839
 #include <cmath> 
#include <iostream> 
#include <iomanip> 
#include <limits> 
using namespace std; 
double input(const char* msg) { 
    cout << msg; 
    double value; 
    cin >> value; 
    cin.ignore(0x1000, '\n'); 
    return value; 
} 
double f(const double x, int choice) { 
    switch (choice) { 
        case 1: return sinh(x); 
        case 2: return pow(x, 2); 
        case 3: return exp(x); 
        default: numeric_limits<double>::quiet_NaN(); 
    } 
} 
int main() { 
    auto x = input("x: "); 
    auto y = input("y: "); 
    auto xy = x / y; 
    auto b = cbrt(fabs(sin(y))); 
    if (xy != 0) { 
        puts("1. sh(x)"); 
        puts("2. x^2"); 
        puts("3. e^x"); 
        cout << ">>> "; 
        int choice; 
        cin >> choice; 
        if (xy < 0) b = pow(pow(f(x, choice), 2) + y, 3); 
        else if (0 < xy) b = log(fabs(f(x, choice) / y)) + xy; 
    } 
    cout.setf(ios::fixed); 
    cout.precision(15); 
    cout << "b: " << b << '\n'; 
}