Advertisement
adriyanbulgary

OperatorsExpressionsAndStatements - Task 10

Jun 13th, 2014
302
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.70 KB | None | 0 0
  1. using System;
  2. /*
  3.  * Write an expression that checks for given point (x, y) if it is within the circle K({1, 1}, 1.5)
  4.  * and out of the rectangle R(top=1, left=-1, width=6, height=2)
  5.  */
  6. class PointInsideCircleAndRectangle
  7. {
  8.     static void Main()
  9.     {
  10.         double radious = 1.5 * 1.5;
  11.         byte centerX = 1;
  12.         byte centerY = 1;
  13.         Console.Write("Please enter X and Y\n x = ");
  14.         float coordinateX = float.Parse(Console.ReadLine());
  15.         Console.Write(" y = ");
  16.         float coordinateY = float.Parse(Console.ReadLine());
  17.         float pointsCoordinates = (float)((coordinateX - centerX) * (coordinateX - centerX) + (coordinateY - centerY) *  (coordinateY - centerY));
  18.         bool inCircle = radious - pointsCoordinates >= 0;
  19.         bool inRectangle = coordinateX >= -1 && coordinateX <= 5 && coordinateY >= -1 && coordinateY <= 1; // check if the point are in the rectangle
  20.         if (inCircle && inRectangle)
  21.         {
  22.             Console.WriteLine("\nThe point wirh coordinates ( {0} : {1} ) is in the both figures!\n", coordinateX, coordinateY);
  23.         }
  24.         if (inCircle && !inRectangle)
  25.         {
  26.             Console.WriteLine("\nThe point wirh coordinates ( {0} : {1} ) is in the circle and out of the rectangle!\n", coordinateX, coordinateY);
  27.         }
  28.         if (!inCircle && inRectangle)
  29.         {
  30.             Console.WriteLine("\nThe point wirh coordinates ( {0} : {1} ) is in the rectangle and out of the cirlce!\n", coordinateX, coordinateY);
  31.         }
  32.         if (!inCircle && !inRectangle)
  33.         {
  34.             Console.WriteLine("\nThe point wirh coordinates ( {0} : {1} ) is outside both figures!\n", coordinateX, coordinateY);
  35.         }
  36.     }
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement