Пример #1
0
        static void Main()
        {
            MassPoint[] elements;
            int         N; // количество точек на плоскости
            Random      gen = new Random(0);

            do
            {
                Console.Write("Введите количество точек на плоскости: ");
            }while (!int.TryParse(Console.ReadLine(), out N) || N < 1);
            elements = new MassPoint[N];
            for (int i = 0; i < elements.Length; i++)
            {
                PointS ps = new PointS(gen.Next(-10, 11), gen.Next(-10, 11));
                elements[i] = new MassPoint(ps, gen.Next(1, 6));
                Console.WriteLine(elements[i].ToString());
            }
            SetOfMassPoint real;

            do
            {
                double R = 0;
                do
                {
                    Console.Write("Введите радиус множества: ");
                }while (!double.TryParse(Console.ReadLine(), out R) || R <= 1);
                real = new SetOfMassPoint(elements, new PointS(0, 0), R);
                Console.WriteLine(real.ToString());
                Console.WriteLine(real.MassCenter.ToString());
                Console.WriteLine("Для завершения работы нажмите Escape ");
            } while (Console.ReadKey(true).Key != ConsoleKey.Escape);
        }
Пример #2
0
        private static void Main()
        {
            var sep  = Path.DirectorySeparatorChar;
            var path = $@"..{sep}..{sep}..{sep}MassPoints.bin";

            var elements = new List <MassPoint>();
            var radius   = GetNumber <double>("Enter radius of set: ",
                                              el => el > 1);

            try
            {
                // Read info from file.
                using (var sr = new StreamReader(new FileStream(path, FileMode.Open)))
                {
                    string line;

                    while ((line = sr.ReadLine()) != null)
                    {
                        MassPoint massPoint = GetMassPoint(line);

                        elements.Add(massPoint);
                    }
                }

                var real = new SetOfMassPoint(elements, new PointS(0, 0), radius);

                PrintMessage("\nSuitable points:\n\n", ConsoleColor.Green);
                PrintMessage(real.ToString(), ConsoleColor.Yellow);
            }
            catch (IOException)
            {
                PrintMessage("Problem with file!\n", ConsoleColor.Red);
            }
            catch (Exception)
            {
                PrintMessage("Unexpected error!\n", ConsoleColor.Red);
            }

            PrintMessage("\nPress ESC to exit...", ConsoleColor.Green);
            while (Console.ReadKey().Key != ConsoleKey.Escape)
            {
                ;
            }
        }