Created
October 8, 2024 15:57
-
-
Save Darklega228/c4b8da94277d61d2e43e5b39aa325f6a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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