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


#include <iostream>

using namespace std;

struct figure
{
    int circle;     // 1 - круг, 0 - прямоугольник

    double x0;      // координата центра X
    double y0;      // координата центра Y

    double w;       // ширина прямоугольника
    double h;       // высота прямоугольника

    double R;       // радиус круга
};


// Проверка принадлежности точки фигуре
int checkPoint(figure f, double x, double y)
{
    // Если фигура - круг
    if (f.circle == 1)
    {
        if ((x - f.x0) * (x - f.x0) +
            (y - f.y0) * (y - f.y0) <= f.R * f.R)
        {
            return 1;
        }
        else
        {
            return 0;
        }
    }

    // Если фигура - прямоугольник
    else
    {
        if (x >= f.x0 - f.w / 2 &&
            x <= f.x0 + f.w / 2 &&
            y >= f.y0 - f.h / 2 &&
            y <= f.y0 + f.h / 2)
        {
            return 1;
        }
        else
        {
            return 0;
        }
    }
}


int main()
{
    figure A, B, C, D;

    int menu;
    int figuresEntered = 0;

    double x, y;

    int inA, inB, inC, inD;
    int result;

    do
    {
        cout << endl;
        cout << "1 - Input figures" << endl;
        cout << "2 - Check point" << endl;
        cout << "0 - Exit" << endl;
        cout << "Choose: ";

        cin >> menu;


        // =============================
        // ВВОД ФИГУР
        // =============================

        if (menu == 1)
        {
            // ---------- A ----------

            cout << endl << "Figure A" << endl;
            cout << "1 - circle, 0 - rectangle: ";
            cin >> A.circle;

            cout << "x0 = ";
            cin >> A.x0;

            cout << "y0 = ";
            cin >> A.y0;

            if (A.circle == 1)
            {
                cout << "R = ";
                cin >> A.R;
            }
            else
            {
                cout << "Width = ";
                cin >> A.w;

                cout << "Height = ";
                cin >> A.h;
            }


            // ---------- B ----------

            cout << endl << "Figure B" << endl;
            cout << "1 - circle, 0 - rectangle: ";
            cin >> B.circle;

            cout << "x0 = ";
            cin >> B.x0;

            cout << "y0 = ";
            cin >> B.y0;

            if (B.circle == 1)
            {
                cout << "R = ";
                cin >> B.R;
            }
            else
            {
                cout << "Width = ";
                cin >> B.w;

                cout << "Height = ";
                cin >> B.h;
            }


            // ---------- C ----------

            cout << endl << "Figure C" << endl;
            cout << "1 - circle, 0 - rectangle: ";
            cin >> C.circle;

            cout << "x0 = ";
            cin >> C.x0;

            cout << "y0 = ";
            cin >> C.y0;

            if (C.circle == 1)
            {
                cout << "R = ";
                cin >> C.R;
            }
            else
            {
                cout << "Width = ";
                cin >> C.w;

                cout << "Height = ";
                cin >> C.h;
            }


            // ---------- D ----------

            cout << endl << "Figure D" << endl;
            cout << "1 - circle, 0 - rectangle: ";
            cin >> D.circle;

            cout << "x0 = ";
            cin >> D.x0;

            cout << "y0 = ";
            cin >> D.y0;

            if (D.circle == 1)
            {
                cout << "R = ";
                cin >> D.R;
            }
            else
            {
                cout << "Width = ";
                cin >> D.w;

                cout << "Height = ";
                cin >> D.h;
            }

            figuresEntered = 1;

            cout << endl << "Figures entered." << endl;
        }


        // =============================
        // ПРОВЕРКА ТОЧКИ
        // =============================

        if (menu == 2)
        {
            if (figuresEntered == 0)
            {
                cout << "First enter figures!" << endl;
            }
            else
            {
                cout << endl;
                cout << "Enter point X: ";
                cin >> x;

                cout << "Enter point Y: ";
                cin >> y;


                inA = checkPoint(A, x, y);
                inB = checkPoint(B, x, y);
                inC = checkPoint(C, x, y);
                inD = checkPoint(D, x, y);


                cout << endl;
                cout << "A = " << inA << endl;
                cout << "B = " << inB << endl;
                cout << "C = " << inC << endl;
                cout << "D = " << inD << endl;


                // Вариант 10:
                // ((NOT(A AND B)) AND D) OR C

                result = (!(inA && inB) && inD) || inC;


                if (result == 1)
                {
                    cout << "Point belongs to the set." << endl;
                }
                else
                {
                    cout << "Point does NOT belong to the set." << endl;
                }
            }
        }

    } while (menu != 0);


    return 0;
}