Advertisement
filin

laba_1_z_1_mk2

Oct 1st, 2016
104
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_1
  8. {
  9.     class Program
  10.     {
  11.  
  12.         static void Main(string[] args)
  13.         {
  14.             Console.Title = "Дана точка на плоскости с координатами (х, у). Узнать где она лежит.";
  15.                         const int r = 15;
  16.             Console.WriteLine("Система уравнений: \n y>|x|, \n x^2+y^2=r^2;   , где r = {0}", r);
  17.            
  18.  
  19.             int exit = 1;
  20.             while (exit == 1)
  21.             {
  22.                 Console.Write("Введите x: ");
  23.                 string x1 = Console.ReadLine();
  24.                 x1 = x1.Trim();
  25.                 check(x1);
  26.                
  27.                 double x = double.Parse(x1);
  28.                 Console.Write("Введите y: ");
  29.                 string y1 = Console.ReadLine();
  30.                 x1 = x1.Trim();
  31.                 check(y1);
  32.                 double y = double.Parse(y1);
  33.                 if (y < Math.Abs(x) || Math.Pow(x, 2) + Math.Pow(y, 2) > Math.Pow(r, 2))
  34.                 {
  35.                     Console.WriteLine("точка ({0},{1}) находится вне фигуры",x,y);
  36.                 }
  37.                 else
  38.                 {
  39.                     if (y == Math.Abs(x) || Math.Pow(x, 2) + Math.Pow(y, 2) == Math.Pow(r, 2))
  40.                     {
  41.                         Console.WriteLine("точка ({0},{1}) лежит на границе фигуры", x,y);
  42.                     }
  43.                     else
  44.                     {
  45.                         Console.WriteLine("точка ({0},{1}) находится в фигуре",x,y);
  46.                     }
  47.                 }
  48.                 Console.WriteLine("Если хотите продолжить, то введите 1");
  49.                 exit = int.Parse(Console.ReadLine());
  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.             return true;
  67.         }
  68.         static void check(string x1)
  69.         {
  70.             while (IsDigit(x1) != true)
  71.             {
  72.                 Console.WriteLine("Некорректные данные, если хотите выйти введите 2, иначе введите другой символ");
  73.  
  74.                 string exit2 = Console.ReadLine();
  75.                 if (exit2.Equals("2"))
  76.                 {
  77.                     Environment.Exit(0);
  78.                 }
  79.                 else
  80.                 {
  81.                     Console.Write("Введите x: ");
  82.                     x1 = Console.ReadLine();
  83.                 }
  84.             }
  85.         }
  86.     }
  87. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement