static void Main()
        {
            Point3D instance1 = new Point3D(2, 5, 8);
            Point3D instance2 = new Point3D(2.5, 3.8, 8.5);

            var path = new Path();

            path.AddPoint(instance1);
            path.AddPoint(instance2);

            PathStorage.SavePath(@"../../text.txt", path);
            PathStorage.LoadPath(@"../../text.txt");
        }
예제 #2
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));
        }
예제 #3
0
        public static void Main()
        {
            // Create instances of 2 points
            Point3D point1 = new Point3D(1, 2, 3);
            Point3D point2 = new Point3D(1, 3, 2);

            // Testing ToString() override
            Console.WriteLine("{0}  -->  ToString() test", Point3D.PointO.ToString());
            Console.WriteLine("{0}  -->  ToString() test", point1.ToString());
            AddSeparator();

            // Calculate Distance Test
            Console.WriteLine("{0:F2}  -->  Calculate Distance test", Point3D.CalculateDistance(point1, point2));
            AddSeparator();

            // Load points test
            Console.WriteLine("PathStorage Load Method Test");
            Console.WriteLine();
            StreamReader reader = new StreamReader("../../PointsLoad.txt");

            var points = PathStorage.Load(reader);

            for (int i = 0; i < points.Count; i++)
            {
                Console.WriteLine(points[i].ToString());
            }

            AddSeparator();

            // Save points test
            Console.WriteLine("PathStorage Save Method Test");
            Console.WriteLine();
            var writer = new StreamWriter("../../PointsSave.txt");

            PathStorage.Save(writer, points);
            Console.WriteLine("Save done!");
            AddSeparator();
        }
        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");
            }
        }