public LongLong addPlusMinus(LongLong A) //если добавляем числа разных знаков { LongLong Result = new LongLong(); Result.hight = this.hight + A.hight; if (Result.hight > 0) { if (this.small > A.small) { Result.small = this.small - A.small; } else { Result.hight -= 1; Result.small = this.small - A.small + miliard; } } else { if (A.small > this.small) { Result.small = A.small - this.small; } else { Result.small = A.small - this.small + miliard; Result.hight += 1; } } return(Result); }
public void Change(int index) { Console.WriteLine("Хотите ввести дробь(1-да/0-нет)"); int d = Convert.ToInt32(Console.ReadLine()); Console.WriteLine("На какое значение поменять введите большую часть"); int h = Convert.ToInt32(Console.ReadLine()); Console.WriteLine("На какое значение поменять введите меньшую часть"); int s = Convert.ToInt32(Console.ReadLine()); { if (index < Arr.Length) { Changed("Элемент под номером " + (index + 1) + " заменен на элемент со значениями " + h + " " + s); if (d == 1) { Arr[index] = new Fractional(h, s); } else { Arr[index] = new LongLong(h, s); } } else { throw new MyIndexOutOfRangeException("Нет элемента с таким индексом"); } } }
public LongLong addPlusPlus(LongLong A) { LongLong Result = new LongLong(); int plusToHightPart = 0; int s = this.small + A.small; //сума меньших частей int h = this.hight + A.hight; //сума больших частей if (s < miliard) { Result.small = s; } else { plusToHightPart = (int)(s / miliard); //количествомилиардов добавить к большей части чтобы не было переполнения Result.small = s % miliard; } if (h + plusToHightPart < thebigerNumberOfInt) { Result.hight = h + plusToHightPart; } else { throw new MyOutOfMemoryException(); } return(Result); }
public LongLong addHightIsNULL(LongLong A) //если добавляем числа разных знаков { LongLong Result = new LongLong(); if (this.hight != 0) { Result.hight = this.hight; if (this.hight > 0 && A.small > 0 || this.hight > 0 && A.small < 0) { Result.small = this.small + A.small; } else { Result.small = this.small - A.small; } } else if (A.hight != 0) { Result.hight = A.hight; if (A.hight > 0 && this.small > 0 || A.hight > 0 && this.small < 0) { Result.small = this.small + A.small; } else { Result.small = A.small - this.small; } } else { Result.small = this.small + A.small; } if (Result.small < 0 && Result.hight > 0) { Result.hight = -1; Result.small += miliard; } else if (Result.small < -miliard && Result.hight < 0) { Result.hight = -1; Result.small += miliard; } else if (Result.hight == 0) { if (Result.small > miliard) { Result.hight = 1; Result.small -= miliard; } else if (Result.small < -miliard) { Result.hight = -1; Result.small += miliard; } } return(Result); }
public static LongLong operator /(LongLong A, LongLong B) { LongLong Result = new LongLong(); bool plusA = A.isPlus(); bool plusB = B.isPlus(); Console.WriteLine(B.toString()); A.hight = Math.Abs(A.hight); A.small = Math.Abs(A.small); B.hight = Math.Abs(B.hight); B.small = Math.Abs(B.small); if (Math.Abs(A.hight) < Math.Abs(B.hight)) { return(Result); } else { if (B.hight != 0) { Result.small = (int)A.hight / B.hight; int FloatPart = A.hight % B.hight; if (FloatPart > A.hight / 2 && FloatPart > 0) { Result.small++; } else if (Math.Abs(FloatPart) > Math.Abs(A.hight / 2)) { Result.small--; } } else if (B.hight == 0 && B.small != 0) { Result.hight = A.hight / B.small; Result.small = A.small / B.small; } else { throw new MyDivideByZeroException(); } if (plusA != plusB) { if (Result.hight != 0) { Result.hight = -Result.hight; } else { Result.small = -Result.small; } } return(Result); } }
static void Main(string[] args) { Console.Title = "Лабораторна робота 2 "; LongLong Test = new LongLong(-44, 34223); LongLong Test2 = new LongLong(0, 4); Console.WriteLine(Test.toString()); Console.WriteLine(Test2.toString()); Console.WriteLine((Test * Test2).toString()); Fractional A = new Fractional(-3, 8); Fractional B = new Fractional(-2, 5); Fractional C = new Fractional(-3, 5); Console.WriteLine(C.toString()); Series Testing = new Series(Test); Console.WriteLine(Testing.toString()); Testing.Add(Test2); Testing.Add(B); Testing.Add(C); Console.WriteLine(Testing.toString()); Console.WriteLine("Поменяем 1 элемент"); Testing.Change(1); Console.WriteLine(Testing.toString()); Testing.Remove(Test); Console.WriteLine(Testing.toString()); Console.WriteLine("Найдем индекс " + B.toString()); Console.WriteLine(Testing.GetId(B)); Console.WriteLine("Добавим к массиву сумму,разницу,результат деления и умножения чисел " + A.toString() + " " + B.toString()); Testing.Add(A + B); Testing.Add(A - B); Testing.Add(A / B); Testing.Add(A * B); LongLong A2 = new LongLong(2, 644569924); LongLong B2 = new LongLong(0, 84399477); Console.WriteLine("Добавим к массиву сумму,разницу,результат деления и умножения чисел " + A2.toString() + " " + B2.toString()); // Testing.Add(A2 + B2); // Testing.Add(A2 - B2); Testing.Add(A2 + B2); Testing.Add(A2 - B2); Testing.Add(A2 / B2); Testing.Add(A2 * B2); Console.ReadKey(); }
public bool EqualstoPair(LongLong A) { if (A.small == small && A.hight == hight) { return(true); } else { return(false); } }
public bool EqualstoPair(LongLong A) { return(false); }
public override Pair DeepCopy() { LongLong k = new LongLong(hight, small); return(k); }
public static LongLong operator *(LongLong A, LongLong B) { bool isPlusA, isplusB; isPlusA = A.isPlus(); isplusB = B.isPlus(); A.hight = Math.Abs(A.hight); A.small = Math.Abs(A.small); B.hight = Math.Abs(B.hight); B.small = Math.Abs(B.small); LongLong Result = new LongLong(); Result.hight = (int)(A.small * B.small) / miliard; Result.small = (A.small * B.small) % miliard; if (A.hight != 0 && B.hight != 0) { throw new MyOutOfMemoryException(); } else if (A.hight != 0) { if ((A.hight * B.small) + Result.hight < A.thebigerNumberOfInt) { Result.hight += A.hight * B.small; } else { throw new MyOutOfMemoryException(); } } else if (B.hight != 0) { if ((B.hight * A.small) + Result.hight < A.thebigerNumberOfInt) { Result.hight += A.hight * B.small; } else { throw new MyOutOfMemoryException(); } } if (isPlusA != isplusB) { if (Result.hight != 0) { Result.hight = -Result.hight; } else { Result.small = -Result.small; } } return(Result); }
public static LongLong operator -(LongLong A, LongLong B) { LongLong C = new LongLong((-B.hight), (-B.small)); return(A + C); }