private void MakeAddition(IOneDArray obj) { Console.WriteLine("First, multiply the array by 8, then divide the result by 2"); obj.Multiply(8); Console.WriteLine(obj); obj.Division(2); Console.WriteLine(obj); }
private void FillArrayRandomValue(IOneDArray obj) { var rnd = new Random(); for (var i = obj.StartIndex; i < obj.Length + obj.StartIndex; i++) { obj[i] = rnd.Next(); } }
private void DivisionAndMultiplication(IOneDArray obj) { Console.WriteLine(); Console.WriteLine("Get the sum of the current array with itself"); var Sum = obj.Add(obj); Console.WriteLine(Sum); Console.WriteLine("Now subtract the starting array from the result"); Console.WriteLine(Sum.Sub(obj)); }
private void GetElem(IOneDArray obj) { var index = 0; Console.Write("Get item with index - "); if (int.TryParse(Console.ReadLine(), out index)) { Console.WriteLine(obj[index]); } else { Console.WriteLine("Invalid value. Please enter INT type value."); GetElem(obj); } }
public void Main(SolutionFactory Factory) { IOneDArray obj = CreateObj(Factory); Console.WriteLine(); FillArrayRandomValue(obj); Console.WriteLine(obj.ToString()); Console.WriteLine(); GetElem(obj); Console.WriteLine(); MakeAddition(obj); DivisionAndMultiplication(obj); Console.WriteLine(); Console.WriteLine($"Max - {obj.Max()}"); Console.WriteLine($"Min - {obj.Min()}"); Console.WriteLine(); obj.Print(); }
public IOneDArray Adder(IOneDArray added, AdderArgument type) { try { if (StartIndex != added.StartIndex || Length != added.Length) { throw new IndexOutOfRangeException(); } } catch (IndexOutOfRangeException e) { Console.WriteLine("Выход за пределы массива"); return(new OneDArray()); } var result = new OneDArray(StartIndex, Length); for (var i = StartIndex; i < StartIndex + Length; i++) { result[i] = this[i] + added[i] * (int)type; } return(result); }
public IOneDArray Sub(IOneDArray subtrahend) { return(Adder(subtrahend, AdderArgument.Sub)); }
public IOneDArray Add(IOneDArray added) { return(Adder(added, AdderArgument.Add)); }