Ejemplo n.º 1
0
        public void Test_Trapeciya_Perimetr()
        {
            string[]  param    = { "-1", "10", "1", "10", "16", "2", "-7", "2" };
            double    expected = 52;
            Trapeciya trap     = new Trapeciya(param);
            double    per      = trap.perimetr;

            Assert.AreEqual(expected, per);
        }
Ejemplo n.º 2
0
        public void Test_Trapeciya_Ploshad()
        {
            string[]  param    = { "-2", "2", "2", "2", "6", "0", "-6", "0" };
            double    expected = 22.6274169979695;
            Trapeciya trap     = new Trapeciya(param);
            double    per      = trap.ploshad;

            Assert.AreEqual(expected, per, 0.001, "Account not debited correctly");
        }
Ejemplo n.º 3
0
        static void Main(string[] args)
        {
            try
            {
                int          countKv  = 0;                                                 //количество квадратов
                double       perKv    = 0;                                                 // средний периметр квадратов
                int          countOkr = 0;                                                 //количество Окружностей
                double       perOkr   = 0;                                                 // средний периметр окружностей
                int          countTr  = 0;                                                 //количество трапеций
                double       perTr    = 0;                                                 // средний периметр трапеций
                double       pr       = 0;                                                 // периметр
                double       sq       = 0;                                                 //площадь
                int          j        = 0;
                string[]     stroki;                                                       //массив строк из файла
                string[]     paramFig;                                                     //строка с параметрами фигуры
                IGeomFig[]   figures = null;                                               //массив объектов
                StreamReader reader  = new StreamReader(@"1.txt");
                Dictionary <double, string> perimDict = new Dictionary <double, string>(); // словарь для средних периметров
                string s = reader.ReadToEnd();                                             // читаем строку до конца
                reader.Close();

                //проверяем файл на наличие строк
                if (s.Length == 0)
                {
                    Console.WriteLine("Файл не содержит строк!");
                }
                else
                {
                    Console.Clear();
                    Console.WriteLine("Строка:\n" + s);

                    stroki  = s.Split('\n');
                    figures = new IGeomFig[stroki.Length];

                    //заполняем массив объектов
                    for (int i = 0; i < stroki.Length; i++)
                    {
                        paramFig = stroki[i].Split(' ');
                        if (paramFig.Length == 3)
                        {
                            if (Convert.ToDouble(paramFig[2]) > 0)
                            {
                                figures[j] = new Okruzhnost(paramFig);
                                pr         = pr + figures[j].perimetr;
                                sq         = sq + figures[j].ploshad;
                                countOkr++;
                                perOkr = perOkr + figures[j].perimetr;
                                perimDict.Add(perOkr, figures[j].GetType().Name);
                                j++;
                            }
                            else
                            {
                                Console.WriteLine("В строке " + (i + 1) + " круг имеет отрицательный радиус, объект не может быть создан!");
                            }
                        }
                        else
                        if (paramFig.Length == 8)
                        {
                            if (Kvadrat.proverka(paramFig))
                            {
                                figures[j] = new Kvadrat(paramFig);
                                pr         = pr + figures[j].perimetr;
                                sq         = sq + figures[j].ploshad;
                                countKv++;
                                perKv = perKv + figures[j].perimetr;
                                perimDict.Add(perKv, figures[j].GetType().Name);
                                j++;
                            }
                            else if (Trapeciya.proverka(paramFig))
                            {
                                figures[j] = new Trapeciya(paramFig);
                                pr         = pr + figures[j].perimetr;
                                sq         = sq + figures[j].ploshad;
                                countTr++;
                                perTr = perTr + figures[j].perimetr;
                                perimDict.Add(perTr, figures[j].GetType().Name);
                                j++;
                            }
                            else
                            {
                                Console.WriteLine("В строке " + (i + 1) + " возможно неправильно введены параметры!");
                            }
                        }
                        else
                        {
                            Console.WriteLine("В строке " + (i + 1) + " возможно неправильно введены параметры!");
                        }
                    }
                }

                Array.Resize(ref figures, j);
                if (j > 0)
                {
                    //вывод исходного массива
                    Console.WriteLine("\n\n Полученный массив\n");
                    for (int i = 0; i < j; i++)
                    {
                        figures[i].Vyvod(i + 1);
                    }
                    // средний периметр всех фигур
                    Console.WriteLine("\n\n Средний периметр всех фигур = " + pr / j);

                    // средняя площадь всех фигур
                    Console.WriteLine("\n\n Средняя площадь всех фигур = " + sq / j);

                    //сортировка массива по площади и поиск фигуры с наибольшей площадью
                    Array.Sort(figures, new SravPoPloshadi());
                    int maxValue = figures.Length - 1;
                    Console.WriteLine("\n\n Фигура, с наибольшей площадью \n");
                    figures[maxValue].Vyvod(maxValue + 1);

                    // тип фигуры с наибольшим значением среднего периметра среди всех других типов фигур
                    string result = perimDict.Values.Max();
                    Console.WriteLine("\n\n Тип фигуры, с наибольшим значением среднего периметра: " + result);
                }
                else
                {
                    Console.WriteLine("Элементы отсутствуют");
                }

                Console.ReadKey();
            }
            catch (FileNotFoundException) { Console.WriteLine("Ошибка открытия файла "); }
            catch (IndexOutOfRangeException) { Console.WriteLine("В массиве отсутствуют элементы "); }
            catch (OverflowException) { Console.WriteLine("Данные введены неверно "); }
            catch (FormatException) { Console.WriteLine("Данные введены неверно "); }
            catch
            {
                { Console.WriteLine("Непредвиденная ошибка "); }
            }
        }
Ejemplo n.º 4
0
        static void Main()
        {
            List <Figura> figuri = new List <Figura>();

            do
            {
                Console.WriteLine("Chose task 1 - figures; 2 - circle; 3- info o figurah");
                switch (int.Parse(Console.ReadLine()))
                {
                case 1:
                    Console.WriteLine("Vvedite chislo figur");
                    int kolichestvo = int.Parse(Console.ReadLine());

                    for (int i = 0; i < kolichestvo; i++)
                    {
                        Console.WriteLine("Viberite figuru:");
                        Console.WriteLine("1 - triugolnik");
                        Console.WriteLine("2 - trapeciya");
                        int figura = int.Parse(Console.ReadLine());

                        switch (figura)
                        {
                        case 1:
                            Point[] pointsTriug = new Point[3];
                            for (int tr = 0; tr < 3; tr++)
                            {
                                Console.WriteLine($"Koordinati {tr + 1} tochki:");
                                Console.Write("X = ");
                                pointsTriug[tr].X = int.Parse(Console.ReadLine());
                                Console.Write("Y = ");
                                pointsTriug[tr].Y = int.Parse(Console.ReadLine());
                            }
                            Triugulnik triugulnik = new Triugulnik(pointsTriug);
                            figuri.Add(triugulnik);
                            break;

                        case 2:
                            Point[] pointsTrapec = new Point[4];
                            for (int trap = 0; trap < 4; trap++)
                            {
                                Console.WriteLine($"Koordinat {trap + 1} tochki:");
                                Console.Write("X = ");
                                pointsTrapec[trap].X = int.Parse(Console.ReadLine());
                                Console.Write("Y = ");
                                pointsTrapec[trap].Y = int.Parse(Console.ReadLine());
                            }
                            Trapeciya trapecia = new Trapeciya(pointsTrapec);
                            figuri.Add(trapecia);
                            break;
                        }
                    }

                    double[] ploshyadi = new double[kolichestvo];

                    int numberOfTrap = 0;
                    foreach (var figura in figuri)
                    {
                        Console.WriteLine($"{numberOfTrap + 1} {nameof(figura)} ravnobedrennaya = {figura.CheckRavnobedr}, ploshyad = {figura.Area}, perimetr = {figura.Perimetr}");
                        ploshyadi[numberOfTrap] = figura.Area;
                        numberOfTrap++;
                    }

                    double srednPloshyad = ploshyadi.Sum() / ploshyadi.Length;

                    int kolichestvoVisheSredn = 0;

                    for (int i = 0; i < ploshyadi.Length; i++)
                    {
                        if (ploshyadi[i] > srednPloshyad)
                        {
                            kolichestvoVisheSredn++;
                        }
                    }
                    Console.WriteLine($"Kolichestvo figur s bolshei ploshyadu po bolnitse = {kolichestvoVisheSredn}");
                    Console.WriteLine();
                    break;

                case 2:

                    for (int i = 0; i < 2; i++)
                    {
                        int figure = 0;
                        Console.WriteLine("Chose what u want to create  circle or elipse");
                        do
                        {
                            Console.Write("1 - circle, 2 - elipse");
                        } while (!int.TryParse(Console.ReadLine(), out figure) || figure == 0);
                        switch (figure)
                        {
                        case 1:
                            Console.WriteLine($"Points of {i + 1}st circle");
                            Console.Write("X = ");
                            double pointX = double.Parse(Console.ReadLine());
                            Console.Write("Y = ");
                            double pointY         = double.Parse(Console.ReadLine());
                            Point  centerofCircle = new Point(pointX, pointY);
                            Console.Write("radius = ");
                            double radius = double.Parse(Console.ReadLine());

                            figuri.Add(new Circle(centerofCircle, radius, radius));
                            break;

                        case 2:
                            Console.WriteLine($"Points of {i + 1}st elipse");
                            Console.Write("X = ");
                            double pointXel = double.Parse(Console.ReadLine());
                            Console.Write("Y = ");
                            double pointYel       = double.Parse(Console.ReadLine());
                            Point  centerOfElipse = new Point(pointXel, pointYel);
                            Console.Write("1s radius = ");
                            double radius1 = double.Parse(Console.ReadLine());
                            Console.Write("2nd radius = ");
                            double radius2 = double.Parse(Console.ReadLine());

                            figuri.Add(new Circle(centerOfElipse, radius1, radius2));
                            break;
                        }
                    }
                    break;

                case 3:
                    int numberOfFig = 0;
                    foreach (var figura in figuri)
                    {
                        Console.WriteLine(figura.ToString());
                        numberOfFig++;
                    }
                    break;
                }
            } while (Console.ReadKey().Key != ConsoleKey.Escape);
        }