C/C++

Помогите решить лабораторную c++

Помогите решить это, пожалуйста
Otto Man
Otto Man
248
#include <iostream>
#include <iomanip>
#include <string>
using namespace std;
const double ε = 1e-18;
double Abs(double x)
{ return (x < 0) ? -x : x; }
double Sin(double x)
{ double y = - x * x, p = x, s = x, q = 1.;
while (Abs(p) > ε) { q += 2.; p *= y / (q * (q - 1.));
s += p; } return s; }
double Cos(double x)
{ double y = - x * x, p = 1., s = p, q = 0.;
while (Abs(p) > ε) { q += 2.; p *= y / (q * (q - 1.));
s += p; } return s; }
double Arctg(double x)
{ double y = - x * x, p = x, s = x, q = 1., e = q;
while (Abs(e) > ε) { q += 2.; p *= y; e = p / q;
s += e; } return s; }
double Exp(double x)
{ if (x < 0) return 1. / Exp(-x); double p = 1., s = p,
q = 0.; while (p / s > ε) { q++; p *= x / q; s += p; }
return s; }
double Sh(double x)
{ return (Exp(x) - Exp(-x)) * 0.5; }
double Max(double (*f)(double), double a,
double b, double h) { int i, n = (int)((b - a) / h);
double H = (b - a) / n; double y, max = f(a); for (i = 1;
i <= n; i++) { y = f(a + i * H); if (y > max) max = y; }
return max; }
int main()
{ double a, b, h, x; cout << "a b h » "; cin >> a >>
b >> h; string s[4] = {"sin »", "cos »", "arctg »",
"sh »"}; double max, y[4] = { Max(Sin, a, b, h),
Max(Cos, a, b, h), Max(Arctg, a, b, h), Max(Sh, a, b, h) };
for (int i = 0; i < 4; i++) { cout << s[i] << setprecision(15)
<< fixed << setw(22) << y[i] << endl; if (y[i] > max)
max = y[i]; } cout << "max »" << setprecision(15)
<< setw(22) << max << endl; }
P.S. Значения a и b пришлось ограничить диапазоном (-1;1), да шаг табуляции h меньше h=1e-7 лучше не брать, а так - всё работает!.
Михаил Заика
Михаил Заика
29 440
Лучший ответ
Otto Man Пишет много ошибок компиляции (