public Drobi Delenie(Drobi x) { Drobi res = new Drobi(); res.a = a * x.b; res.b = b * x.b; return(res); }
public Drobi Umnojenie(Drobi x) { Drobi res = new Drobi(); res.a = a * x.a; res.b = b * x.b; return(res); }
public Drobi Minus(Drobi x) { Drobi res = new Drobi(); if (b == x.b) { res.a = a - x.a; res.b = x.b; } return(res); }
static void Task03() { Drobi drob1 = new Drobi(); Drobi drob2 = new Drobi(); Drobi res = new Drobi(); Console.WriteLine("Задайте первую дробь!"); Console.Write("Введите числитель первой дроби: "); if (!int.TryParse(Console.ReadLine(), out int x1)) { throw new Exception("Неверный формат числителя дроби!"); } Console.Write("Введите знаменатель первой дроби: "); if (!int.TryParse(Console.ReadLine(), out int x2)) { throw new Exception("Неверный формат знаменателя дроби!"); } Console.WriteLine("Задайте вторую дробь!"); Console.Write("Введите числитель второй дроби: "); if (!int.TryParse(Console.ReadLine(), out int y1)) { throw new Exception("Неверный формат числителя дроби!"); } Console.Write("Введите знаменатель второй дроби: "); if (!int.TryParse(Console.ReadLine(), out int y2)) { throw new Exception("Неверный формат знаменателя дроби!"); } drob1.a = x1; drob1.b = x2; drob2.a = y1; drob2.b = y2; Console.WriteLine("Результаты!!!"); res = drob1.Umnojenie(drob2); Console.WriteLine($"Результат умножения: {res}"); res = drob1.Delenie(drob2); Console.WriteLine($"Результат деления: {res}"); Console.Write("Введите числитель первой дроби: "); if (!int.TryParse(Console.ReadLine(), out int a1)) { throw new Exception("Неверный формат числителя дроби!"); } Console.Write("Введите числитель второй дроби: "); if (!int.TryParse(Console.ReadLine(), out int b1)) { throw new Exception("Неверный формат числителя дроби!"); } Console.Write("Введите общий числитель для обеих дробей: "); if (!int.TryParse(Console.ReadLine(), out int c1)) { throw new Exception("Неверный формат числителя дроби!"); } drob1.a = a1; drob1.b = c1; drob2.a = b1; drob2.b = c1; res = drob1.Plus(drob2); Console.WriteLine($"Результат сложения: {res}"); res = drob1.Minus(drob2); Console.WriteLine($"Результат вычитания: {res}"); Console.ReadKey(); }