Загрузка данных


#include <iostream>
#include <cmath>
#include <windows.h>

using namespace std;

class Ring
{
private:
    double x;
    double y;
    double outerRadius;
    double innerRadius;

public:
    Ring();
    Ring(double xValue, double yValue, double outerValue, double innerValue);

    void assign(double xValue, double yValue, double outerValue, double innerValue);

    double getX() const;
    double getY() const;
    double getOuterRadius() const;
    double getInnerRadius() const;

    double area() const;
    bool containsPoint(double pointX, double pointY) const;

    void print() const;
};

Ring::Ring()
{
    assign(0, 0, 1, 0.5);
}

Ring::Ring(double xValue, double yValue, double outerValue, double innerValue)
{
    assign(xValue, yValue, outerValue, innerValue);
}

void Ring::assign(double xValue, double yValue, double outerValue, double innerValue)
{
    x = xValue;
    y = yValue;

    if (outerValue > 0)
        outerRadius = outerValue;
    else
        outerRadius = 1;

    if (innerValue > 0 && innerValue < outerRadius)
        innerRadius = innerValue;
    else
        innerRadius = outerRadius / 2;
}

double Ring::getX() const
{
    return x;
}

double Ring::getY() const
{
    return y;
}

double Ring::getOuterRadius() const
{
    return outerRadius;
}

double Ring::getInnerRadius() const
{
    return innerRadius;
}

double Ring::area() const
{
    return 3.1415926535 * (outerRadius * outerRadius - innerRadius * innerRadius);
}

bool Ring::containsPoint(double pointX, double pointY) const
{
    double dx = pointX - x;
    double dy = pointY - y;
    double distance = sqrt(dx * dx + dy * dy);

    return distance >= innerRadius && distance <= outerRadius;
}

void Ring::print() const
{
    cout << "Параметры кольца:" << endl;
    cout << "центр = (" << x << "; " << y << ")" << endl;
    cout << "внешний радиус = " << outerRadius << endl;
    cout << "внутренний радиус = " << innerRadius << endl;
    cout << "площадь = " << area() << endl;
}

int main()
{
    SetConsoleCP(1251);
    SetConsoleOutputCP(1251);

    double x, y;
    double outerRadius, innerRadius;
    double pointX, pointY;

    cout << "Введите координату X центра кольца: ";
    cin >> x;
    cout << "Введите координату Y центра кольца: ";
    cin >> y;
    cout << "Введите внешний радиус кольца: ";
    cin >> outerRadius;
    cout << "Введите внутренний радиус кольца: ";
    cin >> innerRadius;

    Ring ring(x, y, outerRadius, innerRadius);

    cout << endl;
    ring.print();

    cout << endl;
    cout << "Введите координату X точки: ";
    cin >> pointX;
    cout << "Введите координату Y точки: ";
    cin >> pointY;

    if (ring.containsPoint(pointX, pointY))
        cout << "Точка принадлежит кольцу" << endl;
    else
        cout << "Точка не принадлежит кольцу" << endl;

    system("pause");
    return 0;
}