예제 #1
0
        static void Main()
        {
            Point3D p1   = new Point3D(5.4, 6.2, 3);
            Point3D p2   = new Point3D(7.9, 2.1, 5.9);
            Point3D p3   = new Point3D(23.4, 3, 5);
            Point3D p4   = new Point3D(7, 15.5, 57.7);
            Point3D p5   = new Point3D(-5, 20.5, 43.4);
            Path    path = new Path();

            path.AddPoint(p1);
            path.AddPoint(p2);
            path.AddPoint(p3);
            path.AddPoint(p4);
            for (int i = 0; i < 4; i++)
            {
                Console.WriteLine(path[i]);
            }
            var distance = CalculateDistance.calculateDistance(p1, p2);

            Console.WriteLine(distance);
            PathStorage.SavePaths(path, "PointsFromPath.txt");

            /*Path pathFromFile = PathStorage.LoadPath("PointsFromPath.txt");
             * for (int i = 0; i < 4 ; i++)
             * {
             *  Console.WriteLine(pathFromFile[i]);
             * }*/
            GenericList <Point3D> listOfPoints = new GenericList <Point3D>(5);

            listOfPoints.AddElement(p1);
            listOfPoints.AddElement(p2);
            listOfPoints.AddElement(p3);
            listOfPoints.AddElement(p4);
            listOfPoints.AddElement(p5);
            listOfPoints.RemoveElement(3);
            listOfPoints.InsertAtPosition(3, p3);
            Console.WriteLine(listOfPoints[3]);
            Console.WriteLine(listOfPoints.IndexOf(p3));
        }
        static void Main()
        {
            var point1 = new Point3D(1, 2, 3);
            var point2 = new Point3D(5, 2, 7);

            //Problem 1. Structure
            Console.WriteLine("Problem 1. Structure:");
            Console.WriteLine(point1);
            Console.WriteLine(point2);
            Console.WriteLine();

            //Problem 2. Static read-only field
            Console.WriteLine("Problem 2. Static read-only field:");
            Console.WriteLine(Point3D.O);
            Console.WriteLine();

            //Problem 3. Static class
            Console.WriteLine(CalcDistanceIn3D.CalcDistance(point1, point2));

            //Problem 4. Path
            var newPath = new Path();

            newPath.AddPointToList(point1);
            newPath.AddPointToList(point2);
            newPath.AddPointToList(point1);
            newPath.AddPointToList(point1);

            //Problem 5. Generic class
            PathStorage.LoadFile();
            PathStorage.SaveFile(newPath);

            // Declare a list of type int
            GenericList <int> intList = new GenericList <int>(4);
            // Declare a list of type string
            GenericList <string> stringList = new GenericList <string>(7);

            intList.Add(-28);
            intList.Add(7);
            intList.Add(11);

            Console.Write("Problem 5: List count: ");
            Console.WriteLine(intList.Count);

            Console.Write("Problem 5: Element at index 1: ");
            Console.WriteLine(intList.ElementAtIndex(1));

            Console.Write("Problem 5: Remove the element at index 1: ");
            intList.Remove(1);
            Console.WriteLine(intList.ElementAtIndex(1));

            Console.Write("Problem 5: Insert element 12 at index 1: ");
            intList.InsertAt(12, 1);
            Console.WriteLine(intList.ElementAtIndex(1));

            Console.Write("Problem 5: The position of element 12 is with index: ");
            Console.WriteLine(intList.IndexOf(12));

            Console.Write("Problem 5: Printing the entire list: ");
            Console.WriteLine(intList.ToString());


            //Problem 6. Auto-grow
            for (int i = 0; i < 40; i += 2)
            {
                intList.Add(i);
            }
            Console.WriteLine("Problem 6: Adding new elements to the list and expanding its size: ");
            Console.WriteLine(intList.ToString());

            //Problem 7. Min and Max
            Console.WriteLine("Problem 7: ");

            Console.Write("Thi minimal value in the entire list is: ");
            Console.WriteLine(intList.Min());

            Console.Write("Thi maximal value in the entire list is: ");
            Console.WriteLine(intList.Max());
            Console.WriteLine();

            //Problem 8. Matrix
            Console.WriteLine("Problem 8. Matrix:");
            Matrix <int> testMatrix = new Matrix <int>(7, 9);

            testMatrix[3, 5] = 17;
            testMatrix[4, 5] = 60;
            var indexAtPoint = testMatrix[3, 5];

            Console.WriteLine(@"Value at index [3, 5] is: {0}", indexAtPoint);

            //this class is for testing
            Matrix <int> testMatrixFirst  = new Matrix <int>(4, 4);
            Matrix <int> testMatrixSecond = new Matrix <int>(4, 4);

            //fill the first matrix
            for (int i = 0; i < testMatrixFirst.Rows; i++)
            {
                for (int j = 0; j < testMatrixFirst.Cols; j++)
                {
                    testMatrixFirst[i, j] = i + j + 1;
                }
            }

            //fill the second matrix
            for (int i = 0; i < testMatrixSecond.Rows; i++)
            {
                for (int j = 0; j < testMatrixSecond.Cols; j++)
                {
                    testMatrixSecond[i, j] = i * j;
                }
            }

            //Operations with matrix
            Matrix <int> addingMatrix    = testMatrixFirst + testMatrixSecond;
            Matrix <int> substractMatrix = testMatrixFirst - testMatrixSecond;
            Matrix <int> multiMatrix     = testMatrixFirst * testMatrixSecond;

            //Printing the result of adding:
            Console.WriteLine("The result from adding two matrix: ");
            addingMatrix.PrintMatrix();
            Console.WriteLine();

            //Printing the result of substracting:
            Console.WriteLine("The result from substracting two matrix: ");
            substractMatrix.PrintMatrix();
            Console.WriteLine();

            //Printing the result of multiplication:
            Console.WriteLine("The result from multiplication of two matrix: ");
            multiMatrix.PrintMatrix();
            Console.WriteLine();

            //Implement the true operator
            Console.WriteLine("Implement the true operator: ");
            if (testMatrixFirst)
            {
                Console.WriteLine("Does not have zero element");
            }
            else
            {
                Console.WriteLine("Has zero element");
            }
        }
예제 #3
0
        static void Main(string[] args)
        {
            GenericList <int> newList = new GenericList <int>(3);

            Console.WriteLine("Capacity before adding an elements: ");
            Console.WriteLine(newList.Capacity);

            newList.Add(1);
            newList.Add(2);
            newList.Add(3);
            newList.Add(4);
            newList.Add(5);
            newList.Add(6);
            newList.Add(7);
            Console.WriteLine("The list after Adding elements from 1 to 7:");
            Console.WriteLine(newList);
            Console.WriteLine("Capacity after adding an elements: ");
            Console.WriteLine(newList.Capacity);

            newList.Insert(7, 8);
            newList.Insert(8, 9);
            newList.Insert(9, 10);
            newList.Insert(10, 11);
            newList.Insert(11, 12);
            Console.WriteLine("The list after Insert elements from 8 to 12 at positions from 7 to 11:");
            Console.WriteLine(newList);
            newList.RemoveAt(2);
            newList.RemoveAt(4);
            Console.WriteLine("The list after Remove elements in positions 2 and 4:");
            Console.WriteLine(newList);
            Console.WriteLine("The min element of the list is:");
            Console.WriteLine(newList.Min());
            Console.WriteLine("The max element of the list is:");
            Console.WriteLine(newList.Max());
            Console.WriteLine("The list after clear method:");
            newList.Clear();
            Console.WriteLine(newList);
            Console.WriteLine();

            Matrix <int> matrix1 = new Matrix <int>(3, 3);

            matrix1[0, 0] = 1;
            matrix1[0, 1] = 2;
            matrix1[0, 2] = 3;
            matrix1[1, 0] = 4;
            matrix1[1, 1] = 5;
            matrix1[1, 2] = 0;
            matrix1[2, 0] = 7;
            matrix1[2, 1] = 8;
            matrix1[2, 2] = 9;

            Matrix <int> matrix2 = new Matrix <int>(3, 3);

            matrix2[0, 0] = 1;
            matrix2[0, 1] = 2;
            matrix2[0, 2] = 3;
            matrix2[1, 0] = 4;
            matrix2[1, 1] = 5;
            matrix2[1, 2] = 6;
            matrix2[2, 0] = 7;
            matrix2[2, 1] = 8;
            matrix2[2, 2] = 9;
            Console.WriteLine("The sum of the matrix \n{0} \nand matrix \n{1} \nis:", matrix1, matrix2);
            Console.WriteLine(matrix1 + matrix2);
            Console.WriteLine("The division of the matrix \n{0} \nand matrix \n{1} \nis:", matrix1, matrix2);
            Console.WriteLine(matrix1 - matrix2);
            Console.WriteLine("The Product of the matrix \n{0} \nand matrix \n{1} \nis:", matrix1, matrix2);
            Console.WriteLine(matrix1 * matrix2);
            Console.WriteLine("Operator True for the matrix:");
            if (matrix1)
            {
                Console.WriteLine("The matrix: \n{0} \n has NO ZERO elements!", matrix1);
            }
            else
            {
                Console.WriteLine("The matrix:\n{0} \n HAS ZERO elements!", matrix1);
            }
            if (matrix2)
            {
                Console.WriteLine("The matrix:\n{0} \n has NO ZERO elements!", matrix2);
            }
            else
            {
                Console.WriteLine("The matrix: \n{0} \n HAS ZERO elements!", matrix2);
            }
        }