Deserboy

Rectangle

Dec 7th, 2019
205
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.45 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace WorkingWithAbstactions
  6. {
  7. class Rectangle
  8.     {
  9.         public Rectangle (Point TopLeft,Point BottomRight)
  10.         {
  11.             this.TopLeftPoint = TopLeft;
  12.             this.BottomRightPoint = BottomRight;
  13.         }
  14.         public Rectangle(int leftX,int leftY,int rightX,int rightY)
  15.         {
  16.             this.TopLeftPoint = new Point(leftX, leftY);
  17.             this.BottomRightPoint = new Point(rightX, rightY);
  18.         }
  19.         public Rectangle()
  20.         {
  21.  
  22.         }
  23.         public Point TopLeftPoint { get; set; }
  24.         public Point BottomRightPoint{ get; set; }
  25.  
  26.         public bool Contains(Point point)
  27.         {
  28.             if ( point.X >= TopLeftPoint.X &&
  29.                 point.X <= BottomRightPoint.X &&
  30.                 point.Y <= TopLeftPoint.Y &&
  31.                 point.Y >= BottomRightPoint.Y)
  32.             {
  33.                 return true;
  34.             }
  35.             else
  36.             {
  37.                 return false;
  38.             }
  39.            
  40.         }
  41.     }
  42. class Point
  43.     {
  44.         public Point(int x,int y)
  45.         {
  46.             this.X = x;
  47.             this.Y = y;
  48.         }
  49.         public Point()
  50.         {
  51.  
  52.         }
  53.         public int X { get; set; }
  54.         public int Y { get; set; }
  55.     }
  56.     class Program
  57.     {
  58.         static void Main(string[] args)
  59.         {
  60.             Rectangle rectangle = new Rectangle();
  61.             Point topLeft = new Point();
  62.             Point bottomRight = new Point();
  63.             int[] coordinates = Console.ReadLine().Split().Select(int.Parse).ToArray();
  64.             int n = int.Parse(Console.ReadLine());
  65.             int topLeftX = coordinates[0];
  66.             int topLeftY = coordinates[1];
  67.             int bottomRightX = coordinates[2];
  68.             int bottomRightY = coordinates[3];
  69.             topLeft.X = topLeftX;
  70.             topLeft.Y = topLeftY;
  71.             bottomRight.X = bottomRightX;
  72.             bottomRight.Y = bottomRightY;
  73.             rectangle.TopLeftPoint = topLeft;
  74.             rectangle.BottomRightPoint = bottomRight;
  75.             Point point = new Point();
  76.             for (int i = 0;i < n; i++)
  77.             {
  78.                 int[] points = Console.ReadLine().Split().Select(int.Parse).ToArray();
  79.                 point.X = points[0];
  80.                 point.Y = points[1];
  81.                 Console.WriteLine(rectangle.Contains(point));
  82.             }
  83.         }
  84.     }
  85. }
Advertisement
Add Comment
Please, Sign In to add comment