public DiapasonArray() { arr = new Diapason[10]; for (int i = 0; i < 10; i++) { arr[i] = new Diapason(i, 10 - i); } count++; }
public DiapasonArray(int n, double min, double max) { arr = new Diapason[n]; double mm = max - min; if (double.IsInfinity(mm)) { throw new Exception("Inappropriate min and max values"); } for (int i = 0; i < n; i++) { arr[i] = new Diapason(rnd.NextDouble() * mm + min, rnd.NextDouble() * mm + min); } count++; }
public static bool Intersection(Diapason dp1, Diapason dp2) { { double x1, x2, y1, y2; if (dp1.X > dp1.Y) { x2 = dp1.Y; y2 = dp1.X; } else { y2 = dp1.Y; x2 = dp1.X; } if (dp2.X > dp2.Y) { x1 = dp2.Y; y1 = dp2.X; } else { y1 = dp2.Y; x1 = dp2.X; } if (x1 >= x2 & x1 <= y2) { return(true); } if (y1 >= x2 & y1 <= y2) { return(true); } if (x2 >= x1 & x2 <= y1) { return(true); } if (y2 >= x1 & y2 <= y1) { return(true); } return(false); } }
public bool Intersection(Diapason dp) { double x1, x2, y1, y2; if (dp.X > dp.Y) { x2 = dp.Y; y2 = dp.X; } else { y2 = dp.Y; x2 = dp.X; } if (this.X > this.Y) { x1 = this.Y; y1 = this.X; } else { y1 = this.Y; x1 = this.X; } if (x1 >= x2 & x1 <= y2) { return(true); } if (y1 >= x2 & y1 <= y2) { return(true); } if (x2 >= x1 & x2 <= y1) { return(true); } if (y2 >= x1 & y2 <= y1) { return(true); } return(false); }
private static bool Menu() { try { Console.ForegroundColor = ConsoleColor.Blue; Console.WriteLine("\nМЕНЮ\n"); Console.ResetColor(); Console.Write(" 1. Задание 1\n" + " 2. Задание 3\n" + " 3. Показать каунтеры\n" + " 4. Выход из программы\n" + "\nВыберите задание: "); string str; switch (int.Parse(Console.ReadLine())) { case 1: str = "="; str = str.PadRight(Console.WindowWidth, '='); Console.WriteLine(str); Console.SetCursorPosition(0, Console.CursorTop + Console.WindowHeight + 2); Console.SetCursorPosition(0, Console.CursorTop - Console.WindowHeight); { Diapason dp1 = new Diapason(DoubleVvod("Введите первую границу первого диапазона: "), DoubleVvod("Введите вторую границу первого диапазона: ")); Diapason dp2 = new Diapason(DoubleVvod("Введите первую границу второго диапазона: "), DoubleVvod("Введите вторую границу второго диапазона: ")); Console.WriteLine($"Пересекается ли первый Diapason и второй Diapason: {dp1.Intersection(dp2)}\n" + $"Пересекается ли второй Diapason и первый Diapason: {dp2.Intersection(dp1)}\n" + $"Пересекается ли второй Diapason и второй Diapason: {dp2.Intersection(dp2)}\n" + $"Пересекается ли первый Diapason и второй Diapason (статическая внешняя функция): {Intersection(dp1, dp2)}\n" + $"Пересекается ли второй Diapason и первый Diapason (статическая внешняя функция): {Intersection(dp2, dp1)}\n"); } Console.WriteLine(); return(true); case 2: str = "="; str = str.PadRight(Console.WindowWidth, '='); Console.WriteLine(str); Console.SetCursorPosition(0, Console.CursorTop + Console.WindowHeight + 2); Console.SetCursorPosition(0, Console.CursorTop - Console.WindowHeight); { while (MenuZadacha3()) { } } Console.WriteLine(); return(true); case 3: str = "="; str = str.PadRight(Console.WindowWidth, '='); Console.WriteLine(str); Console.SetCursorPosition(0, Console.CursorTop + Console.WindowHeight + 2); Console.SetCursorPosition(0, Console.CursorTop - Console.WindowHeight); { Console.WriteLine($"Количество экземпляров Diapason: {Diapason.count}\n" + $"Количество экземпляров DiapasonArray: {DiapasonArray.count}"); } return(true); case 4: Console.Write("Нажмите любую клавишу для выхода..."); Console.ReadKey(); return(false); default: Console.Clear(); Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("Неверный формат числа\n"); Console.ResetColor(); Console.WriteLine(); return(true); } } catch { Console.Clear(); Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("Неверный формат числа\n"); Console.ResetColor(); return(true); } }