Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading;
- namespace ConsoleApplication1
- {
- class Program
- {
- static double xmin = -1, xmax = 1, dx = 0.0001;
- static bool good = false;
- static void ReadFrom() //Функция считывает входные данные
- {
- good = false; //Переменная для проверки на правильный ввод
- Console.WriteLine("Please write x minimal:\t");
- while (good == false)
- {
- try // Дебажим на предмет некорректного ввода
- {
- xmin = Convert.ToDouble(Console.ReadLine());
- if (xmin < -6)
- good = true;
- else
- Console.WriteLine("Please write x mmaximal again. It must be >= -6 minimal:\t");
- }
- catch
- {
- Console.WriteLine("Error!\tTry again please:\t");
- }
- }
- good = false;
- Console.WriteLine("Please write x maximal:\t");
- while (good == false)
- {
- try // Дебажим на предмет некорректного ввода
- {
- xmax = Convert.ToDouble(Console.ReadLine());
- if (xmax > xmin && xmax > 6)
- good = true;
- else
- Console.WriteLine("Please write x mmaximal again. It must be < x minimal:\t");
- }
- catch
- {
- Console.WriteLine("Error!\tTry again please:\t");
- }
- }
- good = false;
- Console.WriteLine("Please write step dx:\t");
- while (good == false)
- {
- try // Дебажим на предмет некорректного ввода
- {
- dx = Convert.ToDouble(Console.ReadLine());
- if (dx > 0 && dx < xmax - xmin && isInRange(xmin, xmax, dx))
- good = true;
- else
- Console.WriteLine("Please write dx again. It must be positive and < (x maximal - x minimal):\t");
- }
- catch
- {
- Console.WriteLine("Error!\tTry again please:\t");
- }
- }
- }
- static void Main(string[] args)
- {
- ReadFrom();
- for (double x = xmin; x < xmax; x += dx)
- {
- string y = "Функции не существует.";
- if (x < -10)
- y = "Функции не существует.";
- else if ((-10 <= x) && (x < -6))
- y = (Math.Sqrt(Math.Pow(2, 2) - Math.Pow(x + 8, 2)) - 2).ToString();
- else if ((-6 <= x) && (x <= 2))
- y = (0.5 * x + 1).ToString();
- else if ((2 < x) && (x < 6))
- y = "Функции не существует.";
- else if ((6 <= x) && (x <= 8))
- y = (Math.Pow(x - 6, 2)).ToString();
- else if (8 < x)
- y = "Функции не существует.";
- Console.WriteLine("X = " + x + "; Y = " + y);
- }
- Console.ReadKey();
- }
- private static bool isInRange(double xmin, double xmax, double dx)
- {
- bool first = false;
- bool second = false;
- bool third = false;
- for (double x = xmin; x < xmax; x += dx)
- {
- if ((-10 <= x) && (x < -6))
- first = true;
- else if ((-6 <= x) && (x <= 2))
- second = true;
- else if ((6 <= x) && (x <= 8))
- third = true;
- }
- if (first && second && third)
- return true;
- return false;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement