static void Main()
        {
            Console.WriteLine("First to test the paths:");
            Point3D a = new Point3D(2, -5, 3.5);
            Point3D b = new Point3D(-2, 25, 4.8);

            Console.WriteLine("Creating 2 point and print them:");
            Console.WriteLine(a);
            Console.WriteLine(b);
            Console.WriteLine("Here is the static start: " + Point3D.PrintZero());
            Console.WriteLine("The distance between these two points is: " + StatisClass.Distance(a, b));
            Console.WriteLine("Read 4 points from txt and displaying them:");
            Path myPath = new Path(PathStorage.LoadPath());

            Console.WriteLine(myPath[0].ToString());
            Console.WriteLine(myPath[1].ToString());
            Console.WriteLine(myPath[2].ToString());
            Console.WriteLine(myPath[3].ToString());
            Console.WriteLine("And now save them to output.txt");
            PathStorage.SavePath(myPath);
            Console.WriteLine();
            Console.WriteLine("Now to test the Generic list. Create new list with size 2 and add two itens");
            GenericList <int> list = new GenericList <int>(2);

            list.Add(85);
            list.Add(12);
            Console.WriteLine(list);
            Console.WriteLine("Add one more item and let the list expand:");
            list.Add(-5);
            Console.WriteLine(list);
            Console.WriteLine("Print element at index 2: " + list[2]);
            list.RemoveAt(1);
            Console.WriteLine("Remove elemect at index 1: " + list);
            list.InsertAt(1, 99);
            Console.WriteLine("Insert elemect at index 1: " + list);
            Console.WriteLine("99 is which what index in the list: " + list.IndexOf(99));
            Console.WriteLine("Smallest element in the list is: " + list.Min());
            Console.WriteLine("Biggest element in the list is: " + list.Max());

            list.Clear();
            Console.WriteLine("Clearing the list." + list);

            Console.WriteLine("Now to test the matrixes: creating two matrixes: { 4, 3 }, { 2, 1 } and { 2, 1 }, { 4, 3 }, and them executing the 3 operations:");
            Matrix <int> firstMatrix  = new Matrix <int>(2, 2);
            Matrix <int> secondMatrix = new Matrix <int>(2, 2);

            int[,] sMatrix = new int[, ] {
                { 4, 3 }, { 2, 1 }
            };
            int[,] cMatrix = new int[, ] {
                { 2, 1 }, { 4, 3 }
            };
            for (int row = 0; row < 2; row++)
            {
                for (int col = 0; col < 2; col++)
                {
                    firstMatrix[row, col]  = sMatrix[row, col];
                    secondMatrix[row, col] = cMatrix[row, col];
                }
            }
            Console.WriteLine("Addition:");
            Matrix <int> newOne = firstMatrix + secondMatrix;

            for (int row = 0; row < 2; row++)
            {
                for (int col = 0; col < 2; col++)
                {
                    Console.Write(newOne[row, col] + " ");
                }
                Console.WriteLine();
            }
            Console.WriteLine("Subtraction:");
            newOne = firstMatrix - secondMatrix;
            for (int row = 0; row < 2; row++)
            {
                for (int col = 0; col < 2; col++)
                {
                    Console.Write(newOne[row, col] + " ");
                }
                Console.WriteLine();
            }
            Console.WriteLine("Multiplication:");
            newOne = firstMatrix * secondMatrix;
            for (int row = 0; row < 2; row++)
            {
                for (int col = 0; col < 2; col++)
                {
                    Console.Write(newOne[row, col] + " ");
                }
                Console.WriteLine();
            }
            Console.WriteLine("Atributes:");
            Type type = typeof(Test);

            object[] attr = type.GetCustomAttributes(false);
            foreach (VersionAttribute item in attr)
            {
                Console.WriteLine(item.Version);
            }
        }
Example #2
0
        static void Main()
        {
            // TEST PATH STORAGE
            Stack <Point3D> seq = new Stack <Point3D>();

            seq.Push(new Point3D(23, 11, 2));
            seq.Push(new Point3D(-23, 2, 11));
            seq.Push(new Point3D(23, 43, 89));

            Path.PathStorage.SavePath(seq, "path.txt");

            // TEST GENERIC LIST
            GenericList <int> myList = new GenericList <int>(8);

            myList.Add(23);
            myList.Add(12);
            myList.Add(55);
            myList.Add(78);
            myList.Add(-1);

            Console.WriteLine(myList.ToString());
            int currentCount = myList.Count;

            Console.WriteLine("Count: " + currentCount);
            Console.WriteLine("Index of 23: " + myList.IndexOf(23));
            Console.WriteLine("Index of 12: " + myList.IndexOf(12));
            myList.Insert(108, 2);
            Console.WriteLine("After insertion: " + myList);
            myList.RemoveAt(2);
            Console.WriteLine("Removed: " + myList);
            myList.Clear();
            Console.WriteLine("Cleared: " + myList);

            try
            {
                GenericList <string> newList = new GenericList <string>(4);
                newList.Add(null);
                // myList.Insert(23, 105);
                // myList.RemoveAt(-12);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }

            myList.Add(23);
            myList.Add(12);
            myList.Add(55);
            myList.Add(78);
            myList.Add(-1);

            // should resize
            myList.Add(44);
            myList.Add(5);
            myList.Add(7);
            myList.Add(886);
            myList.Add(-12);
            Console.WriteLine("Resize: ");
            Console.WriteLine(myList.ToString());
            Console.WriteLine(myList.Capacity);

            // min/max
            Console.WriteLine("Max: " + myList.Max <int>());
            Console.WriteLine("Min: " + myList.Min <int>());

            // Matrix operators
            Matrix <decimal> m1 = new Matrix <decimal>(2, 2);

            m1[0, 0] = 34;
            m1[0, 1] = 16;
            m1[1, 0] = -2;
            m1[1, 1] = -3;

            Matrix <decimal> m2 = new Matrix <decimal>(2, 2);

            m2[0, 0] = 16;
            m2[0, 1] = 34;
            m2[1, 0] = 2;
            m2[1, 1] = 0;

            Console.WriteLine("Operator overloading: ");
            Console.WriteLine(new string('-', 23) + "Add");
            Console.WriteLine(m1 + m2);
            Console.WriteLine(new string('-', 23) + "Subtract");
            Console.WriteLine(m1 - m2);
            Console.WriteLine(new string('-', 23) + "Multiply");
            Console.WriteLine(m1 * m2);

            Console.WriteLine((bool)m1);
            Console.WriteLine((bool)m2);

            // Show version at runtime
            Console.Write("Version: ");
            var atr = typeof(SimpleValidator).GetCustomAttributes(typeof(MyVersion), true).FirstOrDefault() as MyVersion;

            Console.WriteLine(atr != null ? atr.Version : "no version attribute");
        }
        public static void Main()
        {
            //Initializing 3D points
            var firstPoint  = new Point3D(1, 2, 3);
            var secondPoint = new Point3D(2, 2, 3);

            Console.WriteLine(firstPoint);
            Console.WriteLine(secondPoint);

            //Printing distance between two points
            Console.WriteLine("Distance between points: {0}", Distance.CalculateDistance(firstPoint, secondPoint));
            //Console.WriteLine("Distance between points: {0}", Distance.CalculateDistance(firstPoint, Point3D.Point0));

            //Initializing points
            var path = new Path();

            for (int i = 0; i < 5; i++)
            {
                path.AddPoints(new Point3D(i + 2, i + 2, i + 2));
            }

            //Saving points in file
            PathStorage.SavePath(path, "pathstorage.txt");
            //Loading point from file
            var print = PathStorage.LoadPath("pathstorage.txt");

            //And printing it on the console
            foreach (var item in print)
            {
                Console.WriteLine(item);
            }

            var list = new GenericList <int>(3);

            //Adding elements
            list.AddElement(5);
            list.AddElement(18);
            list.AddElement(100);

            //Removing element by index
            list.RemoveElement(1);

            list.AddElement(90);

            //Inserting element at given index
            list.InsertElement(1, 10000);

            list.AddElement(123);

            Console.WriteLine(list);

            //Get element at index
            Console.WriteLine(list.GetElement(1));

            //Get min element
            Console.WriteLine(list.GetMinEl());

            //Get max element
            Console.WriteLine(list.GetMaxEl());

            //Clear the list
            list.ClearElements();

            Console.WriteLine(list);
        }