Exemple #1
0
        static void Main()
        {
            /*### Problem 1. Structure
             * Create a structure `Point3D` to hold a 3D-coordinate {X, Y, Z} in the Euclidian 3D space.
             * Implement the `ToString()` to enable printing a 3D point.*/

            Console.WriteLine("Problem 1. Structure - new 3D point created");
            Point3D point1 = new Point3D(1, 2, 3);

            Console.WriteLine(point1);

            /*### Problem 2. Static read-only field
             * Add a `private static read-only` field to hold the start of the coordinate system – the point O{0, 0, 0}.
             * Add a static property to return the point O.*/
            Console.WriteLine("\r\n\r\n\r\nProblem 2. Static read-only field - Point O");
            Console.WriteLine(Point3D.PointO);
            Console.WriteLine();

            /*### Problem 3. Static class
             * Write a `static class` with a `static method` to calculate the distance between two points in the 3D space.*/
            Point3D point11 = new Point3D(-7, -4, 3);
            Point3D point22 = new Point3D(17, 6, 2.5);

            Console.WriteLine("\r\n\r\n\r\nProblem 3. Distance between points");
            Console.WriteLine(point11);
            Console.WriteLine(point22);
            Console.WriteLine();
            Console.WriteLine(CalculateDistance.Distance(point11, point22));
            Console.WriteLine("26.004807247892 <== hardcoded to check the calculation");

            /*### Problem 4. Path
             * Create a class `Path` to hold a sequence of points in the 3D space.
             * Create a static class `PathStorage` with static methods to save and load paths from a text file.
             * Use a file format of your choice.*/
            Console.WriteLine("\r\n\r\n\r\nProblem 4. Path Class");
            Path newPath = new Path();

            newPath.Add3DPoint(point11);
            newPath.Add3DPoint(point22);
            newPath.Add3DPoint(Point3D.PointO);

            Console.WriteLine("\r\nPoints stored in newPath:\r\n");
            Console.WriteLine(newPath);

            //Test point deletion
            newPath.Delete3DPoint(Point3D.PointO);

            Console.WriteLine("\r\nPoints stored in newPath after removal of Point O:\r\n");
            Console.WriteLine(newPath);

            //Test saving Path to file
            PathStorage.SavePath(newPath);

            //Test loading Path from file
            Console.WriteLine("\r\nTest loading Path from file\r\n");
            Path testInputFile = new Path();

            PathStorage.LoadPath(testInputFile);
            Console.WriteLine(testInputFile);
        }
Exemple #2
0
        static void Main()
        {
            Point3D point = new Point3D(1, 2, 3);
            Path    path  = new Path();

            //Add two points to the path
            path.AddPoint(point);
            path.AddPoint(Point3D.Point0);

            //Save the path
            PathStorage.SavePath(path);

            Path someOtherPath = new Path();

            //Add two points to the other path
            someOtherPath.AddPoint(Point3D.Point0);
            someOtherPath.AddPoint(point);

            //Save the other path
            PathStorage.SavePath(someOtherPath);

            //Print all paths
            List <Path> paths = PathStorage.LoadPath();

            PathStorage.PrintPaths(paths);
        }
Exemple #3
0
        static void Main()
        {
            // first create 3 points
            Point3D p1 = new Point3D(1.3, 2.3, 3.1);
            Point3D p2 = new Point3D(4.2, 2.8, -5);
            Point3D p3 = new Point3D(1.1, 2.5, 11.7);

            // calculate distance between first two points
            Console.WriteLine("Distance between p1 and p2: {0}", CalcDistance.TwoPoints(p1, p2));

            // create two test paths and save them to two files
            Path testPath1 = new Path();

            testPath1.AddPoint(p1);
            testPath1.AddPoint(p2);
            testPath1.AddPoint(p3);
            PathStorage.SavePath(testPath1, "SavedTestPath1");

            Path testPath2 = new Path();

            testPath2.AddPoint(p3);
            testPath2.AddPoint(p2);
            testPath2.AddPoint(p1);
            PathStorage.SavePath(testPath2, "SavedTestPath2");

            // create third path and load its points from file of first path
            Path testPath3 = new Path();

            testPath3 = PathStorage.LoadPath("SavedTestPath1");

            // save third path to SavedTestPath3.txt
            PathStorage.SavePath(testPath3, "SavedTestPath3");

            // SavedTestPath3.txt should be the same as SavedTestPath1.txt

            try
            {
                testPath3 = PathStorage.LoadPath("NonExistentFile");
            }
            catch (Exception ex)
            {
                Console.WriteLine("An expected error occurred. Error message:\n{0}", ex.Message);
            }
        }