Exemple #1
0
 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);
 }
Exemple #2
0
        private void FillArrayRandomValue(IOneDArray obj)
        {
            var rnd = new Random();

            for (var i = obj.StartIndex; i < obj.Length + obj.StartIndex; i++)
            {
                obj[i] = rnd.Next();
            }
        }
Exemple #3
0
        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));
        }
Exemple #4
0
        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);
            }
        }
Exemple #5
0
        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();
        }
Exemple #6
0
        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);
        }
Exemple #7
0
 public IOneDArray Sub(IOneDArray subtrahend)
 {
     return(Adder(subtrahend, AdderArgument.Sub));
 }
Exemple #8
0
 public IOneDArray Add(IOneDArray added)
 {
     return(Adder(added, AdderArgument.Add));
 }