Beispiel #1
0
        static void Main(string[] args)
        {
            Hexagon hex = new Hexagon("Beth");
            hex.Draw();

            Circle cir = new Circle("Cindy");
            // Calls base class implementation
            cir.Draw();

            // Make an array of Shape-compatible objects
            Shape[] myShapes = {new Hexagon(), new Circle(), new Hexagon("Mick")
                              , new Circle("Beth"), new Hexagon("Linda")};
            // Loop over each item and interact with the polymorphic interface
            foreach (Shape s in myShapes) {
                s.Draw();
            }

            Console.ReadLine();
        }
Beispiel #2
0
        static void Main(string[] args)
        {
            Shape rectangle = new Rectangle(5, 6);

            Console.WriteLine("Rectangle:");
            Console.WriteLine(rectangle.CalculateArea());
            Console.WriteLine(rectangle.CalculatePerimeter());
            Console.WriteLine();
            rectangle.Draw();

            Console.WriteLine();

            Shape circle = new Circle(7);

            Console.WriteLine("Circle:");
            Console.WriteLine(circle.CalculateArea());
            Console.WriteLine(circle.CalculatePerimeter());
            Console.WriteLine();
            circle.Draw();
        }
Beispiel #3
0
        public static void Main(string[] args)
        {
            try
            {
                var       radius = int.Parse(Console.ReadLine());
                IDrawable circle = new Circle(radius);

                var       width  = int.Parse(Console.ReadLine());
                var       height = int.Parse(Console.ReadLine());
                IDrawable rect   = new Rectangle(width, height);

                Console.WriteLine(circle.Draw());
                Console.WriteLine(rect.Draw());
            }
            catch (ArgumentException exception)
            {
                Console.WriteLine(exception.Message);
                return;
            }
        }
Beispiel #4
0
        public static void Main(string[] args)
        {
            try
            {
                Shape circle    = new Circle(2.5);
                Shape rectangle = new Rectangle(6, 3);

                Console.WriteLine(circle.CalculateArea());
                Console.WriteLine(circle.CalculatePerimeter());
                Console.WriteLine(circle.Draw());

                Console.WriteLine(rectangle.CalculateArea());
                Console.WriteLine(rectangle.CalculatePerimeter());
                Console.WriteLine(rectangle.Draw());
            }
            catch (ArgumentException exception)
            {
                Console.WriteLine(exception.Message);
            }
        }
Beispiel #5
0
        static void Main(string[] args)
        {
            var radius = int.Parse(Console.ReadLine());

            IDrawable circle = new Circle(radius);



            var width = int.Parse(Console.ReadLine());

            var height = int.Parse(Console.ReadLine());

            IDrawable rect = new Rectangle(width, height);



            circle.Draw();

            rect.Draw();
        }
        static void Main(string[] args)
        {
            Rectangle r = new Rectangle(3f, 4f);

            //Rectangle r = new Rectangle();
            //r.get();
            Console.WriteLine("Perimeter of rectangle is:" + r.CalculatePerimeter());

            Console.WriteLine("Area of rectangle :" + r.CalculateArea());
            Console.WriteLine(r.Draw());
            Console.WriteLine();
            Circle c = new Circle(5f);

            //Circle c = new Circle();
            //c.get();
            Console.WriteLine("Perimeter of circle is:" + c.CalculatePerimeter());

            Console.WriteLine("Area of circle :" + c.CalculateArea());
            Console.WriteLine(c.Draw());
            Console.ReadLine();
        }
        static void Main(string[] args)
        {
            Console.WriteLine("***** Fun with Polymorphism *****\n");

            Hexagon hex = new Hexagon("Beth");
            hex.Draw();

            Circle cir = new Circle("Cindy");
            // Calls base class implementation!
            cir.Draw();
            Console.WriteLine();

            // Make an array of Shap-compatible objects.
            Shape[] myShapes = {new Hexagon(), new Circle(), new Hexagon("Mick"), new Circle("Beth"), new Hexagon("Linda")};

            // Loop over each item and interact with
            // Polymorphic interface.
            foreach (Shape s in myShapes)
            {
                s.Draw();
            }

            Console.WriteLine();

            // This calls the Draw() method of the ThreeDCircle.
            ThreeDCircle o = new ThreeDCircle();
            o.Draw();

            DrawCircle(o);
            Console.WriteLine();

            // This calls the Draw() method of the parent!
            ((Circle)o).Draw();

            Circle oCopy = o as Circle;
            oCopy.Draw();
            Console.WriteLine();

            Console.ReadKey();
        }
Beispiel #8
0
        static void Main(string[] args)
        {
            Hexagon hex = new Hexagon("Beth");
            hex.Draw();

            Circle cir = new Circle("Cindy");
            cir.Draw();

            Shape[] myShapes = { new Hexagon(), new Circle(), new Hexagon("Mick"), new Circle("Beth"), new Hexagon("Linda") };

            foreach (Shape s in myShapes)
            {
                s.Draw();
            }

            ThreeDCircle o = new ThreeDCircle();
            o.Draw();

            ((Circle)o).Draw();

            Console.ReadLine();
        }
        static void Main(string[] args)
        {
            double[] data = Console.ReadLine().Split(' ', StringSplitOptions.RemoveEmptyEntries).Select(double.Parse).ToArray();

            try
            {
                Shape curentShape = null;

                switch (data.Length)
                {
                case 2:
                    curentShape = new Rectangle(data[0], data[1]);     // data[0] -> height, data[1] -> width
                    break;

                case 1:
                    curentShape = new Circle(data[0]);     // data[0] -> radius
                    break;

                default:
                    Console.WriteLine("Too many data!");
                    break;
                }

                if (curentShape != null)
                {
                    Console.WriteLine($"Area: {curentShape.CalculateArea()}");
                    Console.WriteLine($"Perimeter: {curentShape.CalculatePerimeter()}");
                    curentShape.Draw();
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }


            //Console.WriteLine("Hello World!");
        }
Beispiel #10
0
        static void Main(string[] args)
        {
            Hexagon hex = new Hexagon("Beth");
            hex.Draw();

            Circle cir = new Circle("Cindy");
            cir.Draw();
            Console.WriteLine();

            Shape[] myShapes = { new Hexagon(), new Circle(), new Hexagon("Mick"), new Circle("Beth"), new Hexagon("Linda") };
            foreach (Shape s in myShapes)
            {
                s.Draw();
            }

            Console.WriteLine();
            ThreDCircle c = new ThreDCircle();
            c.Draw();                                 //calls method form 3d circle

            Circle c1 = new ThreDCircle();
            c1.Draw();                                //calls method form  circle
            Console.ReadLine();
        }
Beispiel #11
0
        static void Main(string[] args)
        {
            while (true)
            {
                string input = Console.ReadLine();

                if (input == "c")
                {
                    Shape circle = new Circle(5);
                    Console.WriteLine(circle.CalculateArea());
                    Console.WriteLine(circle.CalculatePerimeter());
                    Console.WriteLine(circle.Draw());
                }

                else if (input == "r")
                {
                    Shape rec = new Rectangle(4, 60);
                    Console.WriteLine(rec.CalculateArea());
                    Console.WriteLine(rec.CalculatePerimeter());
                    Console.WriteLine(rec.Draw());
                }
            }
        }
Beispiel #12
0
        static void Main(string[] args)
        {
            // Note: Cannot create an instance of the abstract class or interface "shape":
            //     Shape abstShape = new Shape() { };

            Console.WriteLine("***** Fun with Polymorphism *****\n");
            // make an array of Shape-compatible objects
            Shape[] myShapes = { new Hexagon(), new Circle(), new Hexagon("Mick"), new Circle("Beth"), new Hexagon("Linda") };
            // Loop over each item (above) and interact with the polymorphic interface
            foreach (Shape s in myShapes)
            {
                s.Draw();
            }
            Console.WriteLine();
            Console.ReadLine();
            Console.WriteLine();

            Hexagon hex = new Hexagon("Beth");

            hex.Draw(); // calls Hexagon.Draw() method()
            Circle cir = new Circle("Cindy");

            cir.Draw(); // calls base class implementation

            // it is still possible to trigger the base class implementation of a shadowed member
            //   using an explicit cast:
            // Example: This calls the Draw() method of the ThreeDCircle:
            _3dCircle o = new _3dCircle();

            o.Draw();
            // Example: This calls the Draw() method of the parent, Circle
            ((Circle)o).Draw();

            // Pause program execution before exit
            Console.WriteLine();
            Console.ReadLine();
        }
Beispiel #13
0
        static void Main(string[] args)
        {
            Shape shape  = new Rectangle(3.5, 12);
            Shape shape1 = new Circle(1);

            Console.WriteLine($"Perimeter = {shape.CalculatePerimeter():f2}; \nArea = {shape.CalculateArea():f2}; \n{shape.Draw()}");
            Console.WriteLine($"Perimeter = {shape1.CalculatePerimeter():f2}; \nArea = {shape1.CalculateArea():f2}; \n{shape1.Draw()}");
        }
        static void Main()
        {
            var myPoint = new Point(1, 2);
            //Console.WriteLine(myPoint);
            //myPoint.PrintInfo();

            var myCircle = new Circle() { Radius = 2, Center = myPoint };
            //myCircle.PrintInfo();

            var myTriangle = new Triangle()
            {
                Name = "ABC",
                A = new Point(0, 0),
                B = new Point(1, 0),
                C = new Point(0, 1)
            };

            //myTriangle.PrintInfo();
            //Console.WriteLine("Число вершин {0}",
            //    myTriangle.NumberOfPoints());
            //PrintNumberOfPoints(myTriangle);

            var myRectangle = new Rectangle()
                { A = new Point(1, 1), C = new Point(-1, -1),
                Name = "ABCD"};
            //myRectangle.PrintInfo();
            //Console.WriteLine("Число вершин {0}",
            //    myRectangle.NumberOfPoints());
            //PrintNumberOfPoints(myRectangle);

            var myLine = new Line() { A = new Point(), B = new Point(1, 1) };

            IPrintable[] ifacePr = new IPrintable[]
                {   (IPrintable)myCircle,
                    myTriangle,
                    myLine,
                    myRectangle,
                    myPoint
                };
            foreach (var figure in ifacePr)
            {
                figure.PrintInfo();
                if (figure is IPointy)
                    PrintNumberOfPoints((IPointy)figure);
                if (figure is IMeasurable)
                    Console.WriteLine("Площадь равна {0:F3} кв. ед.",
                        ((IMeasurable)figure).GetArea());
                if (figure is IPolygone)
                    Console.WriteLine("Число диагоналей равно " +
                        ((IPolygone)figure).NumberOfDiagonals);
            }

            Console.WriteLine("Фигура наибольшей площади имеет площадь {0:F3}",
                GetTheLargest(myPoint, myTriangle, myCircle, myLine).GetArea());

            myCircle.Draw();
            var ifaceScreen = (IScreenable)myCircle;
            var IfacePlotter = (IPlottarable)myCircle;
            ifaceScreen.Draw();
            IfacePlotter.Draw();

            foreach (Point vertex in myTriangle)
                vertex.PrintInfo();

            myTriangle.A = new Point(-1, -1);
            myTriangle.PrintInfo();
            foreach (Point vertex in myTriangle)
                vertex.PrintInfo();

            myRectangle.PrintInfo();
            foreach (Point vert in myRectangle)
                vert.PrintInfo();

            //var iEnum = myRectangle.GetEnumerator();

            //while (true)
            //{
            //    if (iEnum.MoveNext())
            //    {
            //        var p = iEnum.Current as Point;
            //        p.PrintInfo();
            //    }
            //    else
            //        iEnum.Reset();

            //    if (Console.KeyAvailable)
            //        break;
            //}

            var myQuadrangle = new Quadrangle()
            {
                A = new Point(),
                B = new Point(5, 0),
                C = new Point(5, 5),
                D = new Point(-5, 0)
            };
            myQuadrangle.PrintInfo();

            foreach (Point vert in myQuadrangle)
                vert.PrintInfo();

            Console.ReadKey();
        }
 public static void DrawCircle(Circle shape)
 {
     Console.WriteLine("Using DrawCircle()");
     shape.Draw();
 }
Beispiel #16
0
        static void Main(string[] args)
        {
            //Set Points
            var A = new Point(0, 0);
            var B = new Point(3, 4);
            var C = new Point(1.5, 5);
            var D = new Point(1, 2);

            //Distance between points
            var ab = new Distance(A, B);
            var bc = new Distance(B, C);
            var cd = new Distance(C, D);
            var da = new Distance(D, A);

            //Unit explanation
            UnitExplanation.Units();

            //Triangle test
            //var iso = TriangleType.Isosceles;
            //var rect = TriangleType.Rectangular;
            //var obt = TriangleType.Obtuse;
            //var equi = TriangleType.Echilateral;
            var t1 = new TriangleWithSides(A, B, C);
            var t2 = new TriangleWithSides(3, 4, 5);
            var t3 = new TriangleWithSides(1.5, 3.7, 5);
            var t4 = new TriangleWithAngle(3, 3, 45);
            var t5 = new TriangleWithAngle(A, B, C);
            var t6 = new TriangleWithAngle(3, 4, 90);

            t1.Draw();
            t1.DisplayShape();
            t2.DisplayShape();
            t3.DisplayShape();
            t4.DisplayShape();
            t5.DisplayShape();
            t6.DisplayShape();

            //Circle Test
            var circle1 = new Circle(A, B);
            var circle2 = new Circle(3);

            circle1.Draw();
            circle1.DisplayShape();
            circle2.DisplayShape();

            //Rectangle test
            var rect1 = new Rectangle(A, B, D);
            var rect2 = new Rectangle(3, 4);

            rect1.Draw();
            rect1.DisplayShape();
            rect2.DisplayShape();

            //Square test
            var sq1 = new Square(4);
            var sq2 = new Square(A, B);

            sq1.Draw();
            sq1.DisplayShape();
            sq2.DisplayShape();

            //Cylinder test
            var cyl1 = new Cylinder(A, B, C);
            var cyl2 = new Cylinder(3, 5);

            cyl1.Draw();
            cyl1.DisplayShape();
            cyl2.DisplayShape();

            //Sphere test
            var sphere1 = new Sphere(A, B);
            var sphere2 = new Sphere(7.5);

            sphere1.Draw();
            sphere1.DisplayShape();
            sphere2.DisplayShape();

            //Hemisphere test
            var hs1 = new Hemisphere(B, D);
            var hs2 = new Hemisphere(3.7);

            hs1.Draw();
            hs1.DisplayShape();
            hs2.DisplayShape();

            //Cone test
            var cone1 = new Cones(A, B, C);
            var cone2 = new Cones(2.5, 4, 5);

            cone1.Draw();
            cone1.DisplayShape();
            cone2.DisplayShape();

            //Cuboid test
            var cub1 = new Cuboid(5.0, 6.0, 7.0);
            var cub2 = new Cuboid(A, B, C, D);

            cub1.Draw();
            cub1.DisplayShape();
            cub2.DisplayShape();

            //Testing Cube
            var cube1 = new Cube(5);
            var cube2 = new Cube(A, B);

            cube1.Draw();
            cube1.DisplayShape();
            cube2.DisplayShape();
            Display();
            var shapes = new List <Shape>();

            shapes.Add(cub1);
            shapes.Add(cone1);
            shapes.Add(t1);
            shapes.Add(rect1);
            foreach (var item in shapes)
            {
                item.Draw();
            }
        }
        static void Main()
        {
            var myPoint = new Point(1, 2);
            //Console.WriteLine(myPoint);
            //myPoint.PrintInfo();

            var myCircle = new Circle()
            {
                Radius = 2, Center = myPoint
            };
            //myCircle.PrintInfo();

            var myTriangle = new Triangle()
            {
                Name = "ABC",
                A    = new Point(0, 0),
                B    = new Point(1, 0),
                C    = new Point(0, 1)
            };

            //myTriangle.PrintInfo();
            //Console.WriteLine("Число вершин {0}",
            //    myTriangle.NumberOfPoints());
            //PrintNumberOfPoints(myTriangle);

            var myRectangle = new Rectangle()
            {
                A    = new Point(1, 1), C = new Point(-1, -1),
                Name = "ABCD"
            };
            //myRectangle.PrintInfo();
            //Console.WriteLine("Число вершин {0}",
            //    myRectangle.NumberOfPoints());
            //PrintNumberOfPoints(myRectangle);

            var myLine = new Line()
            {
                A = new Point(), B = new Point(1, 1)
            };

            IPrintable[] ifacePr = new IPrintable[]
            { (IPrintable)myCircle,
              myTriangle,
              myLine,
              myRectangle,
              myPoint };
            foreach (var figure in ifacePr)
            {
                figure.PrintInfo();
                if (figure is IPointy)
                {
                    PrintNumberOfPoints((IPointy)figure);
                }
                if (figure is IMeasurable)
                {
                    Console.WriteLine("Площадь равна {0:F3} кв. ед.",
                                      ((IMeasurable)figure).GetArea());
                }
                if (figure is IPolygone)
                {
                    Console.WriteLine("Число диагоналей равно " +
                                      ((IPolygone)figure).NumberOfDiagonals);
                }
            }


            Console.WriteLine("Фигура наибольшей площади имеет площадь {0:F3}",
                              GetTheLargest(myPoint, myTriangle, myCircle, myLine).GetArea());

            myCircle.Draw();
            var ifaceScreen  = (IScreenable)myCircle;
            var IfacePlotter = (IPlottarable)myCircle;

            ifaceScreen.Draw();
            IfacePlotter.Draw();

            foreach (Point vertex in myTriangle)
            {
                vertex.PrintInfo();
            }

            myTriangle.A = new Point(-1, -1);
            myTriangle.PrintInfo();
            foreach (Point vertex in myTriangle)
            {
                vertex.PrintInfo();
            }

            myRectangle.PrintInfo();
            foreach (Point vert in myRectangle)
            {
                vert.PrintInfo();
            }

            //var iEnum = myRectangle.GetEnumerator();

            //while (true)
            //{
            //    if (iEnum.MoveNext())
            //    {
            //        var p = iEnum.Current as Point;
            //        p.PrintInfo();
            //    }
            //    else
            //        iEnum.Reset();

            //    if (Console.KeyAvailable)
            //        break;
            //}


            var myQuadrangle = new Quadrangle()
            {
                A = new Point(),
                B = new Point(5, 0),
                C = new Point(5, 5),
                D = new Point(-5, 0)
            };

            myQuadrangle.PrintInfo();

            foreach (Point vert in myQuadrangle)
            {
                vert.PrintInfo();
            }

            Console.ReadKey();
        }