svetlozar_kirkov

Inside Circle & Outside Rectangle (Homework)

Oct 25th, 2014
258
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.20 KB | None | 0 0
  1. using System;
  2.  
  3. namespace InsideCircleOutsideRectangle
  4. {
  5.     class InsideCircleOutsideRectangle
  6.     {
  7.         public const double radius = 1.5;
  8.         public const double position = 1;
  9.         public struct Point
  10.         {
  11.             public double X, Y;
  12.         }
  13.         public static bool InsideCircle(Point point)
  14.         {
  15.             bool isInCircle = (point.X-position) * (point.X-position) +
  16.                 (point.Y-position) * (point.Y-position) <= (radius * radius);
  17.             return isInCircle;
  18.         }
  19.         public static bool InsideRectangle(Point point)
  20.         {
  21.             bool isInsideRectangle = (point.X >= -1 && point.X <= 5) && (point.Y >= -1 && point.Y <= 1);
  22.             return isInsideRectangle;
  23.         }
  24.         static void Main()
  25.         {
  26.             Point test = new Point();
  27.             Console.Write("x = ");
  28.             test.X = double.Parse(Console.ReadLine());
  29.             Console.Write("y = ");
  30.             test.Y = double.Parse(Console.ReadLine());
  31.             bool valid = InsideCircle(test) == true && InsideRectangle(test) == false;
  32.             Console.WriteLine("Inside circle and outside rectangle: {0}",valid ? "Yes" : "No");
  33.         }
  34.     }
  35. }
Advertisement
Add Comment
Please, Sign In to add comment