Beispiel #1
0
        public int CompareTo(object obj)
        {
            Geometric_figures p = (Geometric_figures)obj;

            if (this.Ploshjad() < p.Ploshjad())
            {
                return(-1);
            }
            else if (this.Ploshjad() == p.Ploshjad())
            {
                return(0);
            }
            else
            {
                return(1);
            }
        }
        public int CompareTo(Object rhs)
        {
            Geometric_figures objR = rhs as Geometric_figures;

            if (FindSurface() - objR.FindSurface() > 0.0001)
            {
                if (FindSurface() < objR.FindSurface())
                {
                    return(-1);
                }
                else
                {
                    return(1);
                }
            }
            else
            {
                return(0);
            }
        }
Beispiel #3
0
        static int Main(string[] args)
        {
            #region
            int       n    = 0;
            ArrayList arli = new ArrayList();
            List <Geometric_figures> li = new List <Geometric_figures>();

            double len;

            Rectangle rect = new Rectangle(0, 0);
            Console.WriteLine("Creating rectangle");
            Console.WriteLine("Please put in your value");
            Console.Write("Length 1 ");
            len          = Double.Parse(Console.ReadLine());
            rect.length1 = len;
            Console.Write("Length 2 ");
            len          = Double.Parse(Console.ReadLine());
            rect.length2 = len;

            Square scv = new Square(0);
            Console.WriteLine("Please put in your value");
            Console.Write("Length ");
            len         = Double.Parse(Console.ReadLine());
            scv.length1 = len;
            scv.length2 = len;

            Circle cir = new Circle(0);
            Console.WriteLine("Please put in your value");
            Console.Write("Radius ");
            len        = Double.Parse(Console.ReadLine());
            cir.radius = len;

            arli.Add(rect);
            li.Add(rect);
            arli.Add(scv);
            li.Add(scv);
            arli.Add(cir);
            li.Add(cir);

            #endregion

            while (n != 5)
            {
                Main_menu();
                n = int.Parse(Console.ReadLine());
                switch (n)
                {
                case 1:
                {
                    int yeah;

                    Console.WriteLine("How do you want to sort this collection?");
                    Console.WriteLine("  1. Ascending");
                    Console.WriteLine("  2. Descending");
                    yeah = int.Parse(Console.ReadLine());
                    if (yeah == 1)
                    {
                        for (int j = 0; j < arli.Count - 1; j++)
                        {
                            for (int i = 0; i < arli.Count - 1 - j; i++)
                            {
                                if (((Geometric_figures)arli[i]).CompareTo(arli[i + 1]) == 1)
                                {
                                    Object spec = arli[i];
                                    arli[i]     = arli[i + 1];
                                    arli[i + 1] = spec;
                                }
                            }
                        }
                    }
                    else
                    {
                        for (int j = 0; j < arli.Count - 1; j++)
                        {
                            for (int i = 0; i < arli.Count - 1 - j; i++)
                            {
                                if (((Geometric_figures)arli[i]).CompareTo(arli[i + 1]) == 0)
                                {
                                    Object spec = arli[i];
                                    arli[i]     = arli[i + 1];
                                    arli[i + 1] = spec;
                                }
                            }
                        }
                    }


                    Console.WriteLine();

                    foreach (object i in arli)
                    {
                        if (i.GetType().Name == "Rectangle")
                        {
                            Console.WriteLine(i.GetType().Name + ":");
                            ((Rectangle)i).Print();
                        }
                        else
                        if (i.GetType().Name == "Square")
                        {
                            Console.WriteLine(i.GetType().Name + ":");
                            ((Square)i).Print();
                        }
                        else
                        if (i.GetType().Name == "Circle")
                        {
                            Console.WriteLine(i.GetType().Name + ":");
                            ((Circle)i).Print();
                        }
                    }

                    break;
                }

                case 2:
                {
                    int yeah;

                    Console.WriteLine("How do you want to sort this collection?");
                    Console.WriteLine("  1. Ascending");
                    Console.WriteLine("  2. Descending");
                    yeah = int.Parse(Console.ReadLine());
                    if (yeah == 1)
                    {
                        for (int j = 0; j < li.Count - 1; j++)
                        {
                            for (int i = 0; i < li.Count - 1 - j; i++)
                            {
                                if (((Geometric_figures)li[i]).CompareTo(li[i + 1]) == 0)
                                {
                                    Object spec = li[i];
                                    li[i]     = li[i + 1];
                                    li[i + 1] = (Geometric_figures)spec;
                                }
                            }
                        }
                    }
                    else
                    {
                        for (int j = 0; j < li.Count - 1; j++)
                        {
                            for (int i = 0; i < li.Count - 1 - j; i++)
                            {
                                if (((Geometric_figures)li[i]).CompareTo(li[i + 1]) == 1)
                                {
                                    Object spec = li[i];
                                    li[i]     = li[i + 1];
                                    li[i + 1] = (Geometric_figures)spec;
                                }
                            }
                        }
                    }

                    foreach (object i in li)
                    {
                        if (i.GetType().Name == "Rectangle")
                        {
                            Console.WriteLine(i.GetType().Name + ":");
                            ((Rectangle)i).Print();
                        }
                        else
                        if (i.GetType().Name == "Square")
                        {
                            Console.WriteLine(i.GetType().Name + ":");
                            ((Square)i).Print();
                        }
                        else
                        if (i.GetType().Name == "Circle")
                        {
                            Console.WriteLine(i.GetType().Name + ":");
                            ((Circle)i).Print();
                        }
                    }

                    break;
                }

                case 3:
                {
                    Console.WriteLine("\nMatrix");
                    Matrix <Geometric_figures> matrix = new Matrix <Geometric_figures>(3, 3, 3, new FigureMatrixCheckEmpty());
                    matrix[0, 0, 0] = rect;
                    matrix[1, 1, 1] = scv;
                    matrix[2, 2, 2] = cir;
                    Console.WriteLine(matrix.ToString());

                    break;
                }

                case 4:
                {
                    SimpleStack <Geometric_figures> stack = new SimpleStack <Geometric_figures>();
                    stack.Push(rect);
                    stack.Push(scv);
                    stack.Push(cir);

                    while (stack.Count > 0)
                    {
                        Geometric_figures f = stack.Pop();
                        Console.WriteLine(f);
                    }
                    break;
                }

                case 5:
                {
                    Console.WriteLine("Exiting.");
                    Console.ReadKey();
                    break;
                }

                default:
                {
                    Console.WriteLine("ERROR");
                }
                break;
                }
            }
            return(0);
        }
Beispiel #4
0
        static int Main(string[] args)
        {
            #region
            int       n    = 0;
            ArrayList arli = new ArrayList();
            List <Geometric_figures> li = new List <Geometric_figures>();

            double len;

            Rectangle rect = new Rectangle(0, 0);
            Console.WriteLine("Создание прямоугольника");
            Console.WriteLine("Введите значения:");
            Console.Write("Сторона: ");
            len          = Double.Parse(Console.ReadLine());
            rect.length1 = len;
            Console.Write("Сторона: ");
            len          = Double.Parse(Console.ReadLine());
            rect.length2 = len;

            Square scv = new Square(0);
            Console.WriteLine("Создание квадрата");
            Console.WriteLine("Введите значение");
            Console.Write("Сторона: ");
            len         = Double.Parse(Console.ReadLine());
            scv.length1 = len;
            scv.length2 = len;

            Console.WriteLine("Создание круга");
            Circle cir = new Circle(0);
            Console.WriteLine("Введите значение: ");
            Console.Write("Радиус: ");
            len        = Double.Parse(Console.ReadLine());
            cir.radius = len;

            arli.Add(rect);
            li.Add(rect);
            arli.Add(scv);
            li.Add(scv);
            arli.Add(cir);
            li.Add(cir);

            #endregion

            while (n != 5)
            {
                Main_menu();
                n = int.Parse(Console.ReadLine());
                switch (n)
                {
                case 1:
                {
                    int yeah;

                    Console.WriteLine("Как вы хотите отсортировать эту коллекцию?");
                    Console.WriteLine("  1. По возрастанию");
                    Console.WriteLine("  2. По убыванию");
                    yeah = int.Parse(Console.ReadLine());
                    if (yeah == 1)
                    {
                        for (int j = 0; j < arli.Count - 1; j++)
                        {
                            for (int i = 0; i < arli.Count - 1 - j; i++)
                            {
                                if (((Geometric_figures)arli[i]).CompareTo(arli[i + 1]) == 1)
                                {
                                    Object spec = arli[i];
                                    arli[i]     = arli[i + 1];
                                    arli[i + 1] = spec;
                                }
                            }
                        }
                    }
                    else
                    {
                        for (int j = 0; j < arli.Count - 1; j++)
                        {
                            for (int i = 0; i < arli.Count - 1 - j; i++)
                            {
                                if (((Geometric_figures)arli[i]).CompareTo(arli[i + 1]) == 0)
                                {
                                    Object spec = arli[i];
                                    arli[i]     = arli[i + 1];
                                    arli[i + 1] = spec;
                                }
                            }
                        }
                    }


                    Console.WriteLine();

                    foreach (object i in arli)
                    {
                        if (i.GetType().Name == "Прямоугольник")
                        {
                            Console.WriteLine(i.GetType().Name + ":");
                            ((Rectangle)i).Print();
                        }
                        else
                        if (i.GetType().Name == "Квадрат")
                        {
                            Console.WriteLine(i.GetType().Name + ":");
                            ((Square)i).Print();
                        }
                        else
                        if (i.GetType().Name == "Круг")
                        {
                            Console.WriteLine(i.GetType().Name + ":");
                            ((Circle)i).Print();
                        }
                    }

                    break;
                }

                case 2:
                {
                    int yeah;

                    Console.WriteLine("Как вы хотите отсортировать эту коллекцию?");
                    Console.WriteLine("  1. По возрастанию");
                    Console.WriteLine("  2. По убыванию");
                    yeah = int.Parse(Console.ReadLine());
                    if (yeah == 1)
                    {
                        for (int j = 0; j < li.Count - 1; j++)
                        {
                            for (int i = 0; i < li.Count - 1 - j; i++)
                            {
                                if (((Geometric_figures)li[i]).CompareTo(li[i + 1]) == 0)
                                {
                                    Object spec = li[i];
                                    li[i]     = li[i + 1];
                                    li[i + 1] = (Geometric_figures)spec;
                                }
                            }
                        }
                    }
                    else
                    {
                        for (int j = 0; j < li.Count - 1; j++)
                        {
                            for (int i = 0; i < li.Count - 1 - j; i++)
                            {
                                if (((Geometric_figures)li[i]).CompareTo(li[i + 1]) == 1)
                                {
                                    Object spec = li[i];
                                    li[i]     = li[i + 1];
                                    li[i + 1] = (Geometric_figures)spec;
                                }
                            }
                        }
                    }

                    foreach (object i in li)
                    {
                        if (i.GetType().Name == "Прямоугольник")
                        {
                            Console.WriteLine(i.GetType().Name + ":");
                            ((Rectangle)i).Print();
                        }
                        else
                        if (i.GetType().Name == "Квадрат")
                        {
                            Console.WriteLine(i.GetType().Name + ":");
                            ((Square)i).Print();
                        }
                        else
                        if (i.GetType().Name == "Круг")
                        {
                            Console.WriteLine(i.GetType().Name + ":");
                            ((Circle)i).Print();
                        }
                    }

                    break;
                }

                case 3:
                {
                    Console.WriteLine("\nMatrix");
                    Matrix <Geometric_figures> matrix = new Matrix <Geometric_figures>(3, 3, 3, new FigureMatrixCheckEmpty());
                    matrix[0, 0, 0] = rect;
                    matrix[1, 1, 1] = scv;
                    matrix[2, 2, 2] = cir;
                    Console.WriteLine(matrix.ToString());
                    break;
                }

                case 4:
                {
                    SimpleStack <Geometric_figures> stack = new SimpleStack <Geometric_figures>();
                    stack.Push(rect);
                    stack.Push(scv);
                    stack.Push(cir);

                    while (stack.Count > 0)
                    {
                        Geometric_figures f = stack.Pop();
                        Console.WriteLine(f);
                    }
                    break;
                }

                case 5:
                {
                    Console.ReadKey();
                    break;
                }

                default:
                {
                    Console.WriteLine("Ошибка");
                }
                break;
                }
            }
            return(0);
        }
Beispiel #5
0
        static void Main(string[] args)
        {
            Console.Title = "Назаров Максим Михайлович Группа ИУ5-33Б";
            Rectangle rect = new Rectangle(8, 6);
            Square    sq   = new Square(8);
            Circle    cir  = new Circle(8);

            Console.ForegroundColor = ConsoleColor.DarkRed;
            Console.WriteLine("\nArrayList");
            Console.ResetColor();
            ArrayList list = new ArrayList();

            list.Add(rect);
            list.Add(sq);
            list.Add(cir);
            foreach (var i in list)
            {
                Console.WriteLine(i.ToString() + " ");
            }

            List <Geometric_figures> list2 = new List <Geometric_figures>();

            list2.Add(rect);
            list2.Add(cir);
            list2.Add(sq);
            Console.ForegroundColor = ConsoleColor.DarkYellow;
            Console.WriteLine("\nПеред сортировкой:");
            Console.ResetColor();
            foreach (var i in list2)
            {
                Console.Write(i.ToString() + " \n" + " ");
            }
            list2.Sort();
            Console.ForegroundColor = ConsoleColor.Green;
            Console.WriteLine("\nПосле сортировки:");
            Console.ResetColor();
            foreach (var i in list2)
            {
                Console.Write(i.ToString() + " \n" + " ");
            }

            Console.ForegroundColor = ConsoleColor.Blue;
            Console.WriteLine("\nМатрица");
            Console.ResetColor();
            Matrix <Geometric_figures> matrix = new Matrix <Geometric_figures>(3, 3, 3, new FigureMatrixCheckEmpty());

            matrix[0, 0, 0] = rect;
            matrix[1, 1, 1] = sq;
            matrix[2, 2, 2] = cir;
            Console.WriteLine(matrix.ToString());

            Console.ForegroundColor = ConsoleColor.Magenta;
            Console.WriteLine("\nСтек");
            Console.ResetColor();
            SimpleStack <Geometric_figures> stack = new SimpleStack <Geometric_figures>();

            stack.Push(rect);
            stack.Push(sq);
            stack.Push(cir);
            while (stack.Count > 0)
            {
                Geometric_figures f = stack.Pop();
                Console.WriteLine(f);
            }

            Console.ReadKey();
        }