Как тестируются задачи

Вам нужно написать программу, которая содержит только требуемую функцию (можно несколько функций, если одна функция будет вызывать другую). Программа не должна содержать никакого кода вне функций.

В тестирующей системе после вашей программы будет добавлен следующий код, после чего решение будет проверено на тестах.

Задание A

#define TEST(cond) {cout << ""#cond": " ; cond; cout << endl;}
#define TEST1(base_type, name) { \
    complex <base_type> name; \
    TEST(complex <base_type> name); \
    TEST(cout << sizeof(name.re())); \
    TEST(cout << sizeof(name.im())); \
    TEST(name = complex<base_type>(1.5, 2.5)); \
    TEST(cout << name.re()); \
    TEST(cout << name.im()); \
    TEST(name = complex<base_type>(3.5)); \
    TEST(cout << name.re()); \
    TEST(cout << name.im()); \
    TEST(name = complex<base_type>()); \
    TEST(cout << name.re()); \
    TEST(cout << name.im()); \
    cout << endl; \
}
int main()
{
    TEST1(double, z1);
    TEST1(long double, z2);
    TEST1(float, z3);
    TEST1(int, z4);
    TEST1(long, z5);
    TEST1(long long, z6);
    return 0;
}

Задание B

#define TEST(cond) {cout << ""#cond": " ; cond; cout << endl;}
int main()
{
    TEST(cout << sizeof(5_i));
    TEST(cout << 5_i .re());
    TEST(cout << 5_i .im());
    cout << endl;
    TEST(cout << sizeof(6.5_i));
    TEST(cout << 6.5_i .re());
    TEST(cout << 6.5_i .im());
    cout << endl;
    TEST(cout << sizeof(57_if));
    TEST(cout << 7_if .re());
    TEST(cout << 7_if .im());
    cout << endl;
    TEST(cout << sizeof(8.5_if));
    TEST(cout << 8.5_if .re());
    TEST(cout << 8.5_if .im());
    cout << endl;
    TEST(cout << sizeof(3_il));
    TEST(cout << 3_il .re());
    TEST(cout << 3_il .im());
    cout << endl;
    TEST(cout << sizeof(5.0_il));
    TEST(cout << 4.5_il .re());
    TEST(cout << 4.5_il .im());
    cout << endl;
    return 0;
}

Задание C

#define TEST(cond) {cout << ""#cond": " ; cond; cout << endl;}
int main()
{
    TEST(cout << 1_i << endl);
    TEST(cout << 1_if << endl);
    TEST(cout << 1_il << endl);
    for (long double x = -2; x <= 2; x += 0.5)
        for (long double y = -2; y <= 2; y += 0.5)
        {
            TEST(cout << x << " " << y);
            TEST(cout << complex<long double>(x, y));
            cout << endl;
        }
    TEST(cout << complex<long double>(+1e+1000L, +1e+1000L));
    TEST(cout << complex<long double>(+1e+1000L, +1e-1000L));
    TEST(cout << complex<long double>(+1e+1000L, -1e+1000L));
    TEST(cout << complex<long double>(+1e+1000L, -1e-1000L));
    TEST(cout << complex<long double>(+1e-1000L, +1e+1000L));
    TEST(cout << complex<long double>(+1e-1000L, +1e-1000L));
    TEST(cout << complex<long double>(+1e-1000L, -1e+1000L));
    TEST(cout << complex<long double>(+1e-1000L, -1e-1000L));
    TEST(cout << complex<long double>(-1e+1000L, +1e+1000L));
    TEST(cout << complex<long double>(-1e+1000L, +1e-1000L));
    TEST(cout << complex<long double>(-1e+1000L, -1e+1000L));
    TEST(cout << complex<long double>(-1e+1000L, -1e-1000L));
    TEST(cout << complex<long double>(-1e-1000L, +1e+1000L));
    TEST(cout << complex<long double>(-1e-1000L, +1e-1000L));
    TEST(cout << complex<long double>(-1e-1000L, -1e+1000L));
    TEST(cout << complex<long double>(-1e-1000L, -1e-1000L));
    TEST(cout << complex<long double>(+1e+1000L, 0));
    TEST(cout << complex<long double>(+1e-1000L, 0));
    TEST(cout << complex<long double>(-1e+1000L, 0));
    TEST(cout << complex<long double>(-1e-1000L, 0));
    TEST(cout << complex<long double>(0, +1e+1000L));
    TEST(cout << complex<long double>(0, +1e-1000L));
    TEST(cout << complex<long double>(0, -1e+1000L));
    TEST(cout << complex<long double>(0, -1e-1000L));
    cout << "TESTING CERR" << endl;
    for (long double x = -2; x <= 2; x += 0.5)
        for (long double y = -2; y <= 2; y += 0.5)
        {
            cerr << complex<long double>(x, y) << endl;
        }
    return 0;
}

Задание D

#define TEST(cond) {cout << ""#cond": " ; cond; cout << endl;}
int main()
{
    TEST(cout << 1_i .conj() << endl);
    TEST(cout << 1_il .conj() << endl);
    TEST(cout << 1_if .conj() << endl);
    for (double x = -2; x <= 2; x += 0.5)
        for (double y = -2; y <= 2; y += 0.5)
        {
            complex<double> z;
            TEST(cout << x << " " << y);
            TEST(z = complex<double>(x, y));
            TEST(cout << z.conj());
            TEST(cout << z);
            cout << endl;
        }
    return 0;
}

Задание E

#define TEST(cond) {cout << ""#cond": " ; cond; cout << endl;}
int main()
{
    TEST(cout << 1_i + 1_i << endl);
    TEST(cout << 1.0  + 1_i << endl);
    TEST(cout << 1_i + 1.0 << endl);
    TEST(cout << 1_if + 1_if << endl);
    TEST(cout << 1.0F  + 1_if << endl);
    TEST(cout << 1_if + 1.0F << endl);
    TEST(cout << 1e1000_il + 1e1000_il << endl);
    TEST(cout << 1e1000L  + 1e1000_il << endl);
    TEST(cout << 1e1000_il + 1e1000L << endl);
    for (double x1 = -2; x1 <= 2; x1 += 0.5)
        for (double y1 = -2; y1 <= 2; y1 += 0.5)
            for (double x2 = -2; x2 <= 2; x2 += 0.5)
            {
                for (double y2 = -2; y2 <= 2; y2 += 0.5)
                {
                    TEST(cout << x1 << " " << y1 << " " << x2 << " " << y2);
                    TEST(cout << complex<double>(x1, y1) + complex<double>(x2, y2));
                    cout << endl;
                }
                TEST(cout << x1 << " " << y1 << " " << x2);
                TEST(cout << complex<double>(x1, y1) + x2);
                TEST(cout << x2 + complex<double>(x1, y1));
                cout << endl;
            }
    return 0;
}

Задание F

#define TEST(cond) {cout << ""#cond": " ; cond; cout << endl;}
int main()
{
    TEST(cout << 2_i - 1_i << endl);
    TEST(cout << 2.0  - 1_i << endl);
    TEST(cout << 2_i - 1.0 << endl);
    TEST(cout << 2_if - 1_if << endl);
    TEST(cout << 2.0F - 1_if << endl);
    TEST(cout << 2_if - 1.0F << endl);
    TEST(cout << 2e1000_il - 1e1000_il << endl);
    TEST(cout << 2e1000L - 1e1000_il << endl);
    TEST(cout << 2e1000_il - 1e1000L << endl);
    for (double x1 = -2; x1 <= 2; x1 += 0.5)
        for (double y1 = -2; y1 <= 2; y1 += 0.5)
            for (double x2 = -2; x2 <= 2; x2 += 0.5)
            {
                for (double y2 = -2; y2 <= 2; y2 += 0.5)
                {
                    TEST(cout << x1 << " " << y1 << " " << x2 << " " << y2);
                    TEST(cout << complex<double>(x1, y1) - complex<double>(x2, y2));
                    cout << endl;
                }
                TEST(cout << x1 << " " << y1 << " " << x2);
                TEST(cout << complex<double>(x1, y1) - x2);
                TEST(cout << x2 - complex<double>(x1, y1));
                cout << endl;
            }
    return 0;
}

Задание G

#define TEST(cond) {cout << ""#cond": " ; cond; cout << endl;}
int main()
{
    TEST(cout << 2_i * 1_i << endl);
    TEST(cout << 2.0 * 1_i << endl);
    TEST(cout << 2_i * 1.0 << endl);
    TEST(cout << 2_if * 1_if << endl);
    TEST(cout << 2.0F * 1_if << endl);
    TEST(cout << 2_if * 1.0F << endl);
    TEST(cout << 2e1000_il * 1e1000_il << endl);
    TEST(cout << 2e1000L * 1e1000_il << endl);
    TEST(cout << 2e1000_il * 1e1000L << endl);
    for (double x1 = -2; x1 <= 2; x1 += 0.5)
        for (double y1 = -2; y1 <= 2; y1 += 0.5)
            for (double x2 = -2; x2 <= 2; x2 += 0.5)
            {
                for (double y2 = -2; y2 <= 2; y2 += 0.5)
                {
                    TEST(cout << x1 << " " << y1 << " " << x2 << " " << y2);
                    TEST(cout << complex<double>(x1, y1) * complex<double>(x2, y2));
                    cout << endl;
                }
                TEST(cout << x1 << " " << y1 << " " << x2);
                TEST(cout << complex<double>(x1, y1) * x2);
                TEST(cout << x2 * complex<double>(x1, y1));
                cout << endl;
            }
    return 0;
}

Задание H

#define TEST(cond) {cout << ""#cond": " ; cond; cout << endl;}
int main()
{
    TEST(cout << 1_i / 2_i << endl);
    TEST(cout << 1.0 / 2_i << endl);
    TEST(cout << 1_i / 2.0 << endl);
    TEST(cout << 1_if / 2_if << endl);
    TEST(cout << 1.0F / 2_if << endl);
    TEST(cout << 1_if / 2.0F << endl);
    TEST(cout << 1e1000_il * 2e1000_il << endl);
    TEST(cout << 1e1000L * 2e1000_il << endl);
    TEST(cout << 1e1000_il * 2e1000L << endl);
    for (double x1 = -2; x1 <= 2; x1 += 0.5)
        for (double y1 = -2; y1 <= 2; y1 += 0.5)
            for (double x2 = -2; x2 <= 2; x2 += 0.5)
            {
                for (double y2 = -2; y2 <= 2; y2 += 0.5)
                    if (x2 != 0 || y2 != 0)
                    {
                        TEST(cout << x1 << " " << y1 << " " << x2 << " " << y2);
                        TEST(cout << complex<double>(x1, y1) / complex<double>(x2, y2));
                        cout << endl;
                    }
                TEST(cout << x1 << " " << y1 << " " << x2);
                if (x2 != 0)
                    TEST(cout << complex<double>(x1, y1) / x2);
                if (x1 != 0 || y1 != 0)
                    TEST(cout << x2 / complex<double>(x1, y1));
                cout << endl;
            }
    return 0;
}

Задание I

#define TEST(cond) {cout << ""#cond": " ; cond; cout << endl;}
int main()
{
    TEST(cout << + 2_i << endl);
    TEST(cout << - 2_i << endl);
    TEST(cout << + 2_if << endl);
    TEST(cout << - 2_if << endl);
    TEST(cout << + 2e1000_il << endl);
    TEST(cout << - 2e1000_il << endl);
    for (double x = -2; x <= 2; x += 0.5)
        for (double y = -2; y <= 2; y += 0.5)
        {
            complex<double> z;
            TEST(cout << x << " " << y);
            TEST(cout << (z = complex<double>(x, y)));
            TEST(cout << +z);
            TEST(cout << -z);
            TEST(cout << z);
            cout << endl;
        }
    return 0;
}

Задание J

#define TEST(cond) {cout << ""#cond": " ; cond; cout << endl;}
int main()
{
    TEST(cout << 2_i .abs() << endl);
    TEST(cout << 2_i .arg() << endl);
    TEST(cout << 2_if .abs() << endl);
    TEST(cout << 2_if .arg() << endl);
    TEST(cout << 2e1000_il .abs() << endl);
    TEST(cout << 2e1000_il .arg() << endl);
    for (double x = -2; x <= 2; x += 0.5)
        for (double y = -2; y <= 2; y += 0.5)
        {
            complex<double> z;
            TEST(cout << x << " " << y);
            TEST(cout << (z = complex<double>(x, y)));
            TEST(cout << z.abs());
            TEST(cout << z.arg());
            TEST(cout << z);
            cout << endl;
        }
    return 0;
}

Задание K

#define TEST(cond) {cout << ""#cond": " ; cond; cout << endl;}
int main()
{
    TEST(cout << complex<double>::polar(1, 0) << endl);
    TEST(cout << complex<long double>::polar(1, 0) << endl);
    TEST(cout << complex<float>::polar(1, 0) << endl);
    for (double r = 0; r <= 10; r += 0.5)
        for (double a = -10; a <= 10; a += 0.5)
        {
            complex<double> z;
            TEST(cout << r << " " << a);
            TEST(cout << complex<double>::polar(r, a));
            cout << endl;
        }
    return 0;
}

Задание L

#define TEST(cond) {cout << ""#cond": " ; cond; cout << endl;}
template<typename T>
string eq(complex<T> z, complex<T> w)
{
    if ((z - w).abs() < 1e-6)
        return "OK";
    else
        return "FAIL";
}
int main()
{
    for (double x = 0; x <= 10; x += 0.5)
        for (double y = -10; y <= 10; y += 0.5)
        {
            complex<double> z, w;
            TEST(cout << (z = complex<double>(x, y)));
            TEST(w = complex<double>::sqrt(z));
            TEST(cout << eq(w * w, z));
            cout << endl;
        }
    return 0;
}

Задание M

#define TEST(cond) {cout << ""#cond": " ; cond; cout << "\n";}
template<typename T>
bool eq(complex<T> z, complex<T> w)
{
    return ((z - w).abs() < 1e-6);
}
int main()
{
    const int M = 4;
    complex<double> x1, x2, zero;
    for (double ax = -M; ax <= M; ax += 0.5)
        for (double ay = -M; ay <= M; ay += 0.5)
            if (ax != 0 || ay != 0)
            {
                complex<double> a(ax, ay);
                for (double bx = -M; bx <= M; bx += 0.5)
                    for (double by = -M; by <= M; by += 0.5)
                    {
                        complex<double> b(bx, by);
                        for (double cx = -M; cx <= M; cx += 0.5)
                            for (double cy = -M; cy <= M; cy += 0.5)
                            {
                                complex<double> c(cx, cy);
                                complex<double>::solve_quadratic_equation(a, b, c, x1, x2);
                                if (!eq((x1 * x2) * a, c)
                                 || !eq((x1 + x2) * a, -b)
                                 || !eq(a * x1 * x1 + b * x1 + c, zero)
                                 || !eq(a * x2 * x2 + b * x2 + c, zero))
                                {
                                    cout << "FAIL on a = " << a << ", b = " << b << ", c = " << c << endl;
                                    return 0;
                                }
                            }
                    }
            }
    cout << "OK" << endl;
    return 0;
}

Задание N

#define TEST(cond) {cout << ""#cond": " ; cond; cout << endl;}
int main()
{
    TEST(cout << (1_i == 1_i) << endl);
    TEST(cout << (1_i != 1_i) << endl);
    TEST(cout << (1_i == 2_i) << endl);
    TEST(cout << (1_i != 2_i) << endl);
    TEST(cout << (1.0 + 0_i == 1.0) << endl);
    TEST(cout << (1.0 + 0_i != 1.0) << endl);
    TEST(cout << (1.0 + 0_i == 2.0) << endl);
    TEST(cout << (1.0 + 0_i != 2.0) << endl);
    TEST(cout << (1.0 == 1.0 + 0_i) << endl);
    TEST(cout << (1.0 == 1.0 + 0_i) << endl);
    TEST(cout << (2.0 == 1.0 + 0_i) << endl);
    TEST(cout << (2.0 == 1.0 + 0_i) << endl);
    float eps_f = numeric_limits<float>::epsilon();
    double eps_d = numeric_limits<double>::epsilon();
    long double eps_l = numeric_limits<long double>::epsilon();
    TEST(cout << (1.0F + 0_if == 1.0F + 0_if + eps_f) << endl);
    TEST(cout << (1.0F + 0_if == 1.0F + 0_if - eps_f) << endl);
    TEST(cout << (1.0F + 0_if != 1.0F + 0_if + eps_f) << endl);
    TEST(cout << (1.0F + 0_if != 1.0F + 0_if - eps_f) << endl);
    TEST(cout << (1_if == 1_if + eps_f * 1_if) << endl);
    TEST(cout << (1_if == 1_if - eps_f * 1_if) << endl);
    TEST(cout << (1_if != 1_if + eps_f * 1_if) << endl);
    TEST(cout << (1_if != 1_if - eps_f * 1_if) << endl);
    TEST(cout << (1.0 + 0_i == 1.0 + 0_i + eps_d) << endl);
    TEST(cout << (1.0 + 0_i == 1.0 + 0_i - eps_d) << endl);
    TEST(cout << (1.0 + 0_i != 1.0 + 0_i + eps_d) << endl);
    TEST(cout << (1.0 + 0_i != 1.0 + 0_i - eps_d) << endl);
    TEST(cout << (1_i == 1_i + eps_d * 1_i) << endl);
    TEST(cout << (1_i == 1_i - eps_d * 1_i) << endl);
    TEST(cout << (1_i != 1_i + eps_d * 1_i) << endl);
    TEST(cout << (1_i != 1_i - eps_d * 1_i) << endl);
    TEST(cout << (1.0L + 0_il == 1.0L + 0_il + eps_l) << endl);
    TEST(cout << (1.0L + 0_il == 1.0L + 0_il - eps_l) << endl);
    TEST(cout << (1.0L + 0_il != 1.0L + 0_il + eps_l) << endl);
    TEST(cout << (1.0L + 0_il != 1.0L + 0_il - eps_l) << endl);
    TEST(cout << (1_il == 1_il + eps_l * 1_il) << endl);
    TEST(cout << (1_il == 1_il - eps_l * 1_il) << endl);
    TEST(cout << (1_il != 1_il + eps_l * 1_il) << endl);
    TEST(cout << (1_il != 1_il - eps_l * 1_il) << endl);
    TEST(cout << (1_if == 1_if) << endl);
    TEST(cout << (1_if != 1_if) << endl);
    TEST(cout << (1_if == 2_if) << endl);
    TEST(cout << (1_if != 2_if) << endl);
    TEST(cout << (1.0F + 0_if == 1.0F) << endl);
    TEST(cout << (1.0F + 0_if != 1.0F) << endl);
    TEST(cout << (1.0F + 0_if == 2.0F) << endl);
    TEST(cout << (1.0F + 0_if != 2.0F) << endl);
    TEST(cout << (1.0F == 1.0F + 0_if) << endl);
    TEST(cout << (1.0F == 1.0F + 0_if) << endl);
    TEST(cout << (2.0F == 1.0F + 0_if) << endl);
    TEST(cout << (2.0F == 1.0F + 0_if) << endl);
    TEST(cout << (1e1000_il == 1e1000_il) << endl);
    TEST(cout << (1e1000_il != 1e1000_il) << endl);
    TEST(cout << (1e1000_il == 2e1000_il) << endl);
    TEST(cout << (1e1000_il != 2e1000_il) << endl);
    TEST(cout << (1.0e1000L + 0_il == 1.0e1000L) << endl);
    TEST(cout << (1.0e1000L + 0_il != 1.0e1000L) << endl);
    TEST(cout << (1.0e1000L + 0_il == 2.0e1000L) << endl);
    TEST(cout << (1.0e1000L + 0_il != 2.0e1000L) << endl);
    TEST(cout << (1.0e1000L == 1.0e1000L + 0_il) << endl);
    TEST(cout << (1.0e1000L == 1.0e1000L + 0_il) << endl);
    TEST(cout << (2.0e1000L == 1.0e1000L + 0_il) << endl);
    TEST(cout << (2.0e1000L == 1.0e1000L + 0_il) << endl);
    for (double x1 = -2; x1 <= 2; x1 += 0.5)
        for (double y1 = -2; y1 <= 2; y1 += 0.5)
            for (double x2 = -2; x2 <= 2; x2 += 0.5)
            {
                for (double y2 = -2; y2 <= 2; y2 += 0.5)
                {
                    TEST(cout << x1 << " " << y1 << " " << x2 << " " << y2);
                    TEST(cout << (complex<double>(x1, y1) == complex<double>(x2, y2)));
                    TEST(cout << (complex<double>(x1, y1) != complex<double>(x2, y2)));
                    cout << endl;
                }
                TEST(cout << x1 << " " << y1 << " " << x2);
                TEST(cout << (complex<double>(x1, y1) == x2));
                TEST(cout << (complex<double>(x1, y1) != x2));
                TEST(cout << (x2 == complex<double>(x1, y1)));
                TEST(cout << (x2 != complex<double>(x1, y1)));
                cout << endl;
            }
    return 0;
}

Задание O

#define TEST(cond) {cout << ""#cond": " ; cond; cout << endl;}
int main()
{
    TEST(cout << (1_i < 1_i) << endl);
    TEST(cout << (1_if < 1_if) << endl);
    TEST(cout << (1e1000_il < 1e1000_il) << endl);
    for (double x1 = -2; x1 <= 2; x1 += 0.5)
        for (double y1 = -2; y1 <= 2; y1 += 0.5)
            for (double x2 = -2; x2 <= 2; x2 += 0.5)
            {
                for (double y2 = -2; y2 <= 2; y2 += 0.5)
                {
                    TEST(cout << x1 << " " << y1 << " " << x2 << " " << y2);
                    TEST(cout << (complex<double>(x1, y1) < complex<double>(x2, y2)));
                    cout << endl;
                }
            }
    vector <complex<double> > a;
    for (double x = -10; x <= 10; x += 0.5)
        for (double y = -10; y <= 10; y += 0.5)
            a.push_back(complex<double>(x, y));
    sort(a.begin(), a.end());
    for (int i = 0; i < a.size(); ++i)
        cout << a[i] << endl;
    return 0;
}

Задание P

#define TEST(cond) {cout << ""#cond": " ; cond; cout << endl;}
int main()
{
    TEST(cout << complex<double>::pow(1_i, 2) << endl);
    TEST(cout << complex<float>::pow(1_if, 2) << endl);
    TEST(cout << complex<long double>::pow(1_il, 2) << endl);
    for (double x = -5; x <= 5; x += 0.5)
        for (double y = -5; y <= 5; y += 0.5)
            for (int n = -10; n <= 10; ++n)
                if (n > 0 || x != 0 || y != 0)
                {
                    TEST(cout << x << " " << y << " " << n);
                    TEST(cout << complex<long double>::pow(complex<long double>(x, y), n));
                }
    for (int i = 0; i < 10; ++i)
    {
        complex<long double> a  = complex<long double>::polar(1.001, 0.1 * i);
        for (int n = 1000; n <= 3000; ++n)
        {
            cout << complex<long double>::pow(a, n) << endl;
        }
    }
    return 0;
}

Задание Q

#define TEST(cond) {cout << ""#cond": " ; cond; cout << endl;}
int main()
{
    cout << fixed;
    TEST(cout << complex<double>::pow(1_i, (double)2.5) << endl);
    TEST(cout << complex<float>::pow(1_if, (float)2.5) << endl);
    TEST(cout << complex<long double>::pow(1_il, (long double)2.5) << endl);
    for (long double x = -5; x <= 5; x += 0.45)
        for (long double y = -5; y <= 5; y += 0.45)
            for (long double p = -3; p <= 3; p += 0.26)
            {
                if (x != 0 || y != 0 || p != 0)
                {
                    TEST(cout << x << " " << y << " " << p);
                    TEST(cout << complex<long double>::pow(complex<long double>(x, y), p));
                }
            }
    return 0;
}

Задание R

#define TEST(cond) {cout << ""#cond": " ; cond; cout << endl;}
int main()
{
    cout << fixed;
    TEST(cout << complex<double>::exp(1_i) << endl);
    TEST(cout << complex<float>::exp(1_if) << endl);
    TEST(cout << complex<long double>::exp(1_il) << endl);
    for (long double x = -5; x <= 5; x += 0.25)
        for (long double y = -5; y <= 5; y += 0.25)
        {
            TEST(cout << x << " " << y);
            TEST(cout << complex<long double>::exp(complex<long double>(x, y)));
        }
    return 0;
}

Задание S

#define TEST(cond) {cout << ""#cond": " ; cond; cout << endl;}
int main()
{
    cout << fixed;
    TEST(cout << complex<double>::sin(1_i) << endl);
    TEST(cout << complex<float>::sin(1_if) << endl);
    TEST(cout << complex<long double>::sin(1_il) << endl);
    for (long double x = -5; x <= 5; x += 0.25)
        for (long double y = -5; y <= 5; y += 0.25)
        {
            TEST(cout << x << " " << y);
            TEST(cout << complex<long double>::sin(complex<long double>(x, y)));
        }
    return 0;
}

Задание T

#define TEST(cond) {cout << ""#cond": " ; cond; cout << endl;}
int main()
{
    cout << fixed;
    TEST(cout << complex<double>::cos(1_i) << endl);
    TEST(cout << complex<float>::cos(1_if) << endl);
    TEST(cout << complex<long double>::cos(1_il) << endl);
    for (long double x = -5; x <= 5; x += 0.25)
        for (long double y = -5; y <= 5; y += 0.25)
        {
            TEST(cout << x << " " << y);
            TEST(cout << complex<long double>::cos(complex<long double>(x, y)));
        }
    return 0;
}

Задание U

#define TEST(cond) {cout << ""#cond": " ; cond; cout << endl;}
int main()
{
    cout << fixed;
    TEST(cout << complex<double>::log(1_i) << endl);
    TEST(cout << complex<float>::log(1_if) << endl);
    TEST(cout << complex<long double>::log(1_il) << endl);
    for (long double x = -5; x <= 5; x += 0.25)
        for (long double y = -5; y <= 5; y += 0.25)
            if (x != 0 || y != 0)
            {
                TEST(cout << x << " " << y);
                TEST(cout << complex<long double>::log(complex<long double>(x, y)));
            }
    return 0;
}

Задание V

#define TEST(cond) {cout << ""#cond": " ; cond; cout << endl;}
int main()
{
    cout << fixed;
    TEST(cout << complex<double>::pow(complex<double>(1, 1.5), complex<double>(2)) << endl);
    TEST(cout << complex<float>::pow(complex<float>(1, 1.5), complex<float>(2)) << endl);
    TEST(cout << complex<long double>::pow(complex<long double>(1, 1.5), complex<long double>(2)) << endl);
    for (long double x1 = -2; x1 <= 2; x1 += 0.45)
        for (long double y1 = -2; y1 <= 2; y1 += 0.45)
            for (long double x2 = -2; x2 <= 2; x2 += 0.45)
                for (long double y2 = -2; y2 <= 2; y2 += 0.45)
                    if (x1 != 0 || y1 != 0)
                    {
                        TEST(cout << x1 << " " << y1 << " " << x2 << " " << y2);
                        TEST(cout << complex<long double>::pow(complex<long double>(x1, y1), complex<long double>(x2, y2)));
                        cout << endl;
                    }
    return 0;
}

Задание Y

#include<sstream>
int main()
{
    complex <long double> _z;
    while (cin >> _z)
        cout << _z << endl;
    cout << "=== Testing stringstream === " << endl;
    istringstream _s("1 1i 0 0i (1+1i) (1) (0) (-i) (-1-i) (-1-0i) (1.0+1.0e2i)");
    while (_s >> _z)
        cout << _z << endl;
    return 0;
}

Задание Z

#define TEST(cond) {cout << ""#cond": " ; cond; cout << "\n";}
template<typename T>
bool eq(complex<T> z, complex<T> w)
{
    return ((z - w).abs() < 1e-4);
}
int main()
{
    const int M = 2, N = 4;
    complex<double> x1, x2, x3, zero;
    for (double ax = -M; ax <= M; ax += 0.5)
        for (double ay = -M; ay <= M; ay += 0.5)
            if (ax != 0 || ay != 0)
            {
                complex<double> a(ax, ay);
                for (double bx = -M; bx <= M; bx += 0.5)
                    for (double by = -M; by <= M; by += 0.5)
                    {
                        complex<double> b(bx, by);
                        for (double cx = -M; cx <= M; cx += 0.5)
                            for (double cy = -M; cy <= M; cy += 0.5)
                            {
                                complex<double> c(cx, cy);
                                for (double dx = -M; dx <= M; dx += 0.5)
                                    for (double dy = -M; dy <= M; dy += 0.5)
                                    {
                                        complex<double> d(dx, dy);
                                        complex<double>::solve_cubic_equation(a, b, c, d, x1, x2, x3);
                                        if (!eq((x1 * x2 * x3) * a, -d)
                                             || !eq((x1 * x2 + x2 * x3 + x3 * x1) * a, c)
                                             || !eq((x1 + x2 + x3) * a, -b)
                                             || !eq(a * x1 * x1 * x1 + b * x1 * x1 + c * x1 + d, zero)
                                             || !eq(a * x2 * x2 * x2 + b * x2 * x2 + c * x2 + d, zero)
                                             || !eq(a * x3 * x3 * x3 + b * x3 * x3 + c * x3 + d, zero))
                                            {
                                                cout << "FAIL on a = " << a << ", b = " << b << ", c = " << c << ", d = " << d << endl;
                                                cout << "Your answer: " << endl;
                                                cout << "x1 = " << x1 << endl;
                                                cout << "x2 = " << x2 << endl;
                                                cout << "x3 = " << x3 << endl;
                                                return 0;
                                            }
                                    }
                            }
                    }
            }
    complex<double> a(1), b, c, d;
    for (double ax = -N; ax <= N; ax += 0.5)
        for (double ay = -N; ay <= N; ay += 0.5)
        {
            complex<double> z1(ax, ay);
            for (double bx = -N; bx <= N; bx += 0.5)
                for (double by = -N; by <= N; by += 0.5)
                {
                    complex<double> z2(bx, by);
                    for (double cx = -N; cx <= N; cx += 0.5)
                        for (double cy = -N; cy <= N; cy += 0.5)
                        {
                            complex<double> z3(cx, cy);
                            b = -(z1 + z2 + z3);
                            c = (z1 * z2 + z2 * z3 + z3 * z1);
                            d = -(z1 * z2 * z3);
                            complex<double>::solve_cubic_equation(a, b, c, d, x1, x2, x3);
                            if (!eq((x1 * x2 * x3) * a, -d)
                                 || !eq((x1 * x2 + x2 * x3 + x3 * x1) * a, c)
                                 || !eq((x1 + x2 + x3) * a, -b)
                                 || !eq(a * x1 * x1 * x1 + b * x1 * x1 + c * x1 + d, zero)
                                 || !eq(a * x2 * x2 * x2 + b * x2 * x2 + c * x2 + d, zero)
                                 || !eq(a * x3 * x3 * x3 + b * x3 * x3 + c * x3 + d, zero))
                                {
                                    cout << "FAIL on a = " << a << ", b = " << b << ", c = " << c << ", d = " << d << endl;
                                    cout << "Your answer: " << endl;
                                    cout << "x1 = " << x1 << endl;
                                    cout << "x2 = " << x2 << endl;
                                    cout << "x3 = " << x3 << endl;
                                    return 0;
                                }
                        }
                }
        }
    cout << "OK" << endl;
    return 0;
}