filin

laba_1_z_2_mk3

Oct 1st, 2016
46
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.02 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace Z_2
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             Console.Title = "Дана точка на плоскости с координатами (х, у).Узнать где она лежит.";
  14.             Console.WriteLine("плоскость ограничена фигурой: \n x > -15, \n y > -15, \n x < 0, \n y < 0;");
  15.  
  16.             int exit = 1;
  17.             while (exit == 1)
  18.             {
  19.                 Console.Write("Введите x: ");
  20.                 string x1 = Console.ReadLine();
  21.                 x1 = x1.Trim();
  22.                 check(x1);
  23.  
  24.                 double x = double.Parse(x1);
  25.  
  26.                 Console.Write("Введите y: ");
  27.                 string y1 = Console.ReadLine();
  28.                 while (IsDigit(y1) != true)
  29.                     check(y1);
  30.                 double y = double.Parse(y1);
  31.                 if (x > -15 && y > -15 && x < 0 && y < 0)
  32.                 {
  33.                     Console.WriteLine("точка({0},{1}) находится вне фигуры", x, y);
  34.                 }
  35.                 else
  36.                 {
  37.                     if (x == -15 && y <= 0 && y >= -15 || x == 0 && y <= 0 && y >= -15 || y == -15 && y <= 0 && y >= -15 || y == 0 && x <= 0 && x >= -15)
  38.                     {
  39.                         Console.WriteLine("точка ({0},{1}) лежит на границе фигуры", x, y);
  40.                     }
  41.                     else
  42.                     {
  43.                         Console.WriteLine("точка ({0},{1}) находится в фигуре", x, y);
  44.                     }
  45.                 }
  46.  
  47.                 Console.WriteLine("Если хотите продолжить введите 1");
  48.                 exit = int.Parse(Console.ReadLine());
  49.             }
  50.         }
  51.  
  52.  
  53.         static bool IsDigit(string number)
  54.         {
  55.             if (!((number[0] >= '0' && number[0] <= '9') || number[0] == '-'))
  56.             {
  57.                 return false;
  58.             }
  59.             for (int i = 1; i < number.Length; i++)
  60.             {
  61.                 if (!(number[i] >= '0' && number[i] <= '9'))
  62.                 {
  63.                     return false;
  64.                 }
  65.  
  66.             }
  67.             return true;
  68.         }
  69.         static void check(string x1)
  70.         {
  71.             while (IsDigit(x1) != true)
  72.             {
  73.                 Console.WriteLine("Некорректные данные, если хотите выйти введите 2, иначе введите другой символ");
  74.  
  75.                 string exit2 = Console.ReadLine();
  76.                 if (exit2.Equals("2"))
  77.                 {
  78.                     Environment.Exit(0);
  79.                 }
  80.                 else
  81.                 {
  82.                     Console.Write("Введите x: ");
  83.                     x1 = Console.ReadLine();
  84.                 }
  85.             }
  86.         }
  87.     }
  88. }
Add Comment
Please, Sign In to add comment