ReDestroyDeR

Продвинутый калькуль фени

May 27th, 2020
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 10.11 KB | None | 0 0
  1. using Microsoft.VisualBasic.CompilerServices;
  2. using System;
  3. using System.Linq;
  4.  
  5. namespace Phoenix_Calculator
  6. {
  7.     class Program
  8.     {
  9.         public static void Main(string[] args)
  10.         {
  11.             /*
  12.              *             Console.WriteLine("Одно число");
  13.              *             Console.WriteLine("Два числа");
  14.              *             Console.WriteLine("Теорема пифагора");
  15.              *             Console.WriteLine("Дискриминант");
  16.              */
  17.             bool exit = false;
  18.             do
  19.             {
  20.                 Console.WriteLine("Операции с:" + Environment.NewLine +
  21.                                   "1. Одним числом" + Environment.NewLine +
  22.                                   "2. Двумя числами" + Environment.NewLine +
  23.                                   "3. Теорема пифагора" + Environment.NewLine +
  24.                                   "4. Решение квадратных уравнений" + Environment.NewLine +
  25.                                   "5. Выйти из приложения");
  26.  
  27.  
  28.                 string operationIndex = Console.ReadLine();
  29.  
  30.                 switch (operationIndex)
  31.                 {
  32.                     case "1":
  33.                         Console.Write("Введите число: ");
  34.                         try
  35.                         {
  36.                             int x = int.Parse(Console.ReadLine());
  37.                             for (int i = 1; i < 10; i++)
  38.                             {
  39.                                 Console.WriteLine(string.Format("Степень {0} числа {1} - {2}", i, x, RaiseToPower(x, i)));
  40.                             }
  41.  
  42.                             Console.WriteLine(Environment.NewLine + string.Format("Корень числа {0} - {1}", x, Math.Sqrt(x)));
  43.  
  44.                         } catch (FormatException e)
  45.                         {
  46.                             ErrorMessage(e.Message);
  47.                         }
  48.                         break;
  49.  
  50.                     case "2":
  51.                         bool secondPass = false;
  52.                         do
  53.                         {
  54.                             Console.WriteLine("Введите выражение в формате: x (операция) y" + Environment.NewLine +
  55.                                               "Выражения: +, -, *, /, >, <, =, >=, <=");
  56.                             Console.Write("Ввод: ");
  57.                             string sentence = Console.ReadLine();
  58.                             string[] subSentece = sentence.Split(' ');
  59.                             try
  60.                             {
  61.                                 if (subSentece.Length == 3)
  62.                                 {
  63.                                     double x = double.Parse(subSentece[0]);
  64.                                     double y = double.Parse(subSentece[2]);
  65.                                     switch (subSentece[1])
  66.                                     {
  67.                                         case "+":
  68.                                             Console.WriteLine(string.Format("{0} = {1}", sentence, x + y));
  69.                                             secondPass = true;
  70.                                             break;
  71.  
  72.                                         case "-":
  73.                                             Console.WriteLine(string.Format("{0} = {1}", sentence, x - y));
  74.                                             secondPass = true;
  75.                                             break;
  76.  
  77.                                         case "*":
  78.                                             Console.WriteLine(string.Format("{0} = {1}", sentence, x * y));
  79.                                             secondPass = true;
  80.                                             break;
  81.  
  82.                                         case "/":
  83.                                             Console.WriteLine(string.Format("{0} = {1}", sentence, x / y));
  84.                                             secondPass = true;
  85.                                             break;
  86.  
  87.                                         case ">":
  88.                                             Console.WriteLine(string.Format("{0}? {1}", sentence, x > y));
  89.                                             secondPass = true;
  90.                                             break;
  91.  
  92.                                         case "<":
  93.                                             Console.WriteLine(string.Format("{0}? {1}", sentence, x < y));
  94.                                             secondPass = true;
  95.                                             break;
  96.  
  97.                                         case "=":
  98.                                             Console.WriteLine(string.Format("{0}? {1}", sentence, x == y));
  99.                                             secondPass = true;
  100.                                             break;
  101.  
  102.                                         case ">=":
  103.                                             Console.WriteLine(string.Format("{0}? {1}", sentence, x >= y));
  104.                                             secondPass = true;
  105.                                             break;
  106.  
  107.                                         case "<=":
  108.                                             Console.WriteLine(string.Format("{0}? {1}", sentence, x <= y));
  109.                                             secondPass = true;
  110.                                             break;
  111.  
  112.                                         default:
  113.                                             ErrorMessage("не допустимая операция");
  114.                                             break;
  115.                                     }
  116.                                 }
  117.                                 else
  118.                                 {
  119.                                     ErrorMessage("не верный формат");
  120.                                 }
  121.                             } catch (FormatException e)
  122.                             {
  123.                                 ErrorMessage(e.Message);
  124.                             }
  125.                            
  126.                         } while (!secondPass);
  127.                         break;
  128.  
  129.                     case "3":
  130.                         bool thirdPass = false;
  131.                         do
  132.                         {
  133.                             try
  134.                             {
  135.                                 Console.Write("Введите два катета" + Environment.NewLine +
  136.                                               "AB: ");
  137.                                 double a = double.Parse(Console.ReadLine());
  138.                                 Console.Write("BC: ");
  139.                                 double b = double.Parse(Console.ReadLine());
  140.                                 Console.WriteLine(string.Format("Гипотенуза AC = {0}", Math.Sqrt(a*a + b*b)));
  141.                                 thirdPass = true;
  142.                             }
  143.                             catch (FormatException e)
  144.                             {
  145.                                 ErrorMessage(e.Message);
  146.                             }
  147.  
  148.                         } while (!thirdPass);
  149.                         break;
  150.  
  151.                     case "4":
  152.                         bool fourthPass = false;
  153.                         do
  154.                         {
  155.                             try
  156.                             {
  157.                                 Console.Write("Введите три аргумента" + Environment.NewLine +
  158.                                               "A: ");
  159.                                 double a = double.Parse(Console.ReadLine());
  160.                                 Console.Write("B: ");
  161.                                 double b = double.Parse(Console.ReadLine());
  162.                                 Console.Write("C: ");
  163.                                 double c = double.Parse(Console.ReadLine());
  164.  
  165.                                 if (a == 0 || b == 0 || c == 0)
  166.                                 {
  167.                                     FormatException formatException = new FormatException("у тебя один из операторов нулевой");
  168.                                     throw formatException;
  169.                                 }
  170.  
  171.                                 double D = b * b - 4 * a * c;
  172.                                 double x1 = (-b + Math.Sqrt(D)) / (2 * a);
  173.                                 double x2 = (-b - Math.Sqrt(D)) / (2 * a);
  174.                                 if (D < 0)
  175.                                 {
  176.                                     Console.WriteLine("Дискриминант = " + D);
  177.                                     Console.WriteLine("У уравнения нет корней");
  178.                                 }
  179.                                 else
  180.                                 {
  181.                                     Console.WriteLine(string.Format("Дискриминант: {0}{1}X1 = {2}; X2 = {3}", D, Environment.NewLine, x1, x2));
  182.                                 }
  183.                                 fourthPass = true;
  184.                             }
  185.                             catch (FormatException e)
  186.                             {
  187.                                 ErrorMessage(e.Message);
  188.                             }
  189.  
  190.                         } while (!fourthPass);
  191.                         break;
  192.  
  193.                     case "5":
  194.                         exit = true;
  195.                         break;
  196.  
  197.                     default:
  198.                         ErrorMessage("число не от одного до четырех");
  199.                         break;
  200.                 }
  201.  
  202.             } while (!exit);
  203.         }  
  204.  
  205.         private static void ErrorMessage(string message)
  206.         {
  207.             Console.WriteLine(string.Format("Ты ебаный мудак, {0}", message));
  208.         }
  209.  
  210.         private static double RaiseToPower(double x, double y)
  211.         {
  212.             double result = x;
  213.             for (int i = 1; i < y; i++)
  214.             {
  215.                 result *= x;
  216.             }
  217.  
  218.             return result;
  219.         }
  220.     }
  221. }
Add Comment
Please, Sign In to add comment