Esempio n. 1
0
        static void SwapRef(ref ArrEl first, ref ArrEl second)
        {
            int temp = 0;

            temp       = first.Val;
            first.Val  = second.Val;
            second.Val = temp;
        }
Esempio n. 2
0
 //индексатор2
 public ArrEl this[string info]
 {
     get
     {
         ArrEl element = null;
         foreach (var el in Data)
         {
             if (el.Name == info)
             {
                 element = el;
                 break;
             }
         }
         return(element);
     }
 }
Esempio n. 3
0
 public Arr()
 {
     Data = new ArrEl[Constants.ArraySize];
 }
Esempio n. 4
0
        static void Main(string[] args)
        {
            Arr MyArray = new Arr();

            ArrEl first = new ArrEl {
                Name = "first_param", Val = 678
            };

            MyArray[0] = first;

            ArrEl second = new ArrEl {
                Name = "second_param", Val = 78
            };

            MyArray[1] = second;

            ArrEl third = new ArrEl {
                Name = "third_param", Val = 89
            };

            MyArray[2] = third;

            ArrEl forth = new ArrEl {
                Name = "fourth_param", Val = 333
            };

            MyArray[3] = forth;

            ArrEl fifth = new ArrEl {
                Name = "fifth_param", Val = 689
            };

            MyArray[4] = fifth;



            //task1
            Console.WriteLine(MyArray[3]); // output: forth_param, 333
            // Console.WriteLine(MyArray[78]); //exception
            Console.WriteLine(MyArray["first_param"]);
            Console.WriteLine(MyArray["hj"]); //null

            //task2
            Console.WriteLine("- - - - - - - - - - - -");
            Console.WriteLine(Addition(first.Val, MyArray[1].Val, MyArray[2].Val, MyArray[3].Val, MyArray[4].Val));
            int[] IntArray = { 2, 5, 7, 8 };
            Console.WriteLine(Addition(IntArray));

            //task 3
            Console.WriteLine("- - - - - - - - - - - -");
            Console.WriteLine("Before swap:\n");


            for (int i = 0; i < Constants.ArraySize; i++)
            {
                Console.WriteLine(MyArray[i]);
            }
            SwapRef(ref first, ref second);
            Console.WriteLine("");
            Console.WriteLine("After swap:\n");
            for (int i = 0; i < Constants.ArraySize; i++)
            {
                Console.WriteLine(MyArray[i]);
            }

            //task 4
            Console.WriteLine("- - - - - - - - - - - -");
            //ввод координат
            Console.WriteLine("Пожалуйста, вводите координаты только по/против часовой стрелки, иначе все поломается(( ");

            Console.Write("x1: ");
            double x1 = Convert.ToInt32(Console.ReadLine());

            Console.Write("y1: ");
            double y1 = Convert.ToInt32(Console.ReadLine());

            Console.Write("x2: ");
            double x2 = Convert.ToInt32(Console.ReadLine());

            Console.Write("y2: ");
            double y2 = Convert.ToInt32(Console.ReadLine());

            Console.Write("x3: ");
            double x3 = Convert.ToInt32(Console.ReadLine());

            Console.Write("y3: ");
            double y3 = Convert.ToInt32(Console.ReadLine());

            Console.Write("x4: ");
            double x4 = Convert.ToInt32(Console.ReadLine());

            Console.Write("y4: ");
            double y4 = Convert.ToInt32(Console.ReadLine());

            Console.Write("Perimeter \n");

            Figure.Find_perim(x1, y1, x2, y2, x3, y3, x4, y4, out double perim, out bool perim_flag);

            if (perim_flag)
            {
                Console.WriteLine(perim);
            }
            else
            {
                Console.WriteLine("there's something wrong... check whether it is a quadrangle at all");
            }

            Console.Write("Area ");

            Figure.Find_area(x1, y1, x2, y2, x3, y3, x4, y4, out double area, out bool area_flag);

            if (area_flag)
            {
                Console.WriteLine(area);
            }
            else
            {
                Console.WriteLine("there's something wrong... check whether it is a quadrangle at all");
            }
        }