Skip to content

Instantly share code, notes, and snippets.

@Darklega228
Created October 8, 2024 15:57
Show Gist options
  • Save Darklega228/c4b8da94277d61d2e43e5b39aa325f6a to your computer and use it in GitHub Desktop.
Save Darklega228/c4b8da94277d61d2e43e5b39aa325f6a to your computer and use it in GitHub Desktop.
#include <iostream>
using namespace std;
struct Point
{
double x, y;
};
struct Rectangle
{
Point bottomLeft;
Point topRight;
};
bool isPointInRectangle(const Point& p, const Rectangle& r)
{
return (p.x >= r.bottomLeft.x && p.x <= r.topRight.x &&
p.y >= r.bottomLeft.y && p.y <= r.topRight.y);
}
int main()
{
setlocale(0, "");
Rectangle rect;
cout << "Введите координаты левой нижней точки прямоугольника (x y): "; // 1 1
cin >> rect.bottomLeft.x >> rect.bottomLeft.y;
cout << "Введите координаты правой верхней точки прямоугольника (x y): "; // 5 5
cin >> rect.topRight.x >> rect.topRight.y;
Point pt;
cout << "Введите координаты точки для проверки (x y): "; // 3 3
cin >> pt.x >> pt.y;
if (isPointInRectangle(pt, rect))
{
cout << "Точка находится внутри прямоугольника." << "\n";
}
else
{
cout << "Точка находится вне прямоугольника." << "\n";
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment