Exemplo n.º 1
0
        public void AreaPerimetrParalllelogram()
        {
            Parallelogram parallelogram = new Parallelogram(8, 10);

            Assert.AreEqual(79.148659729870545, parallelogram.Area());
            Assert.AreEqual(36, parallelogram.Perimetr());
        }
Exemplo n.º 2
0
        static void Main(string[] args)
        {
            Triangle tr = new Triangle(new double[3] {
                -1, 1, 0
            }, new double[3] {
                0, 0, 2
            });
            Parallelogram par = new Parallelogram(new double[4] {
                -4, -1, -5, -2
            }, new double[4] {
                4, 5, 1, 2
            });
            Square sq = new Square(new double[4] {
                -1, -1, 1, 1
            }, new double[4] {
                -1, 1, 1, -1
            });

            Console.WriteLine("Area of Triange is {0}, Perimeter is {1}", tr.Area(), tr.Perimeter());

            Console.WriteLine("Area of Parallelogram is {0}, Perimeter is {1}", par.Area(), par.Perimeter());

            Console.WriteLine("Area of Square is {0}, Perimeter is {1}", sq.Area(), sq.Perimeter());

            Console.ReadKey();
        }
Exemplo n.º 3
0
        public static Parallelogram SetParallelogram(out string name, out string type, out double a, out double b,
                                                     out double h, out double area, out double perim, out int tops, out int edges)
        {
            Console.Write("Set Name of Parallelogram: ");
            name = Console.ReadLine();

            Console.Write("Set Type of Parallelogram: ");
            type = Console.ReadLine();

            Console.Write("Enter a side of Parallelogram:\n");
            Console.Write("a: ");
            a = double.Parse(Console.ReadLine(), CultureInfo.InvariantCulture);

            Console.Write("Enter b side of Parallelogram:\n");
            Console.Write("b: ");
            b = double.Parse(Console.ReadLine(), CultureInfo.InvariantCulture);

            Console.Write("Enter h:\n");
            Console.Write("h: ");
            h = double.Parse(Console.ReadLine(), CultureInfo.InvariantCulture);

            Parallelogram parallelogram = new Parallelogram(a, b, h);

            parallelogram.Name = name;
            parallelogram.Type = type;
            area  = parallelogram.Area();
            perim = parallelogram.Perimeter();
            tops  = parallelogram.QuantityOfTops();
            edges = parallelogram.QuantityOfEdges();

            return(parallelogram);
        }
Exemplo n.º 4
0
        public void TestForArea3()
        {
            var para     = new Parallelogram(3, 8, 5);
            var result   = para.Area();
            var expected = 15;

            Assert.AreEqual(expected, result);
        }
Exemplo n.º 5
0
    public static void Main(string[] args)
    {
        //注意所有几何体的点按照逆时针输入
        Circle circle = new Circle(0, 0, 1);

        Console.WriteLine("半径为1的圆的面积为:" + circle.Area().ToString());
        Console.WriteLine("半径为1的圆的周长为:" + circle.CircumFerence().ToString());

        Cylinder cylinder = new Cylinder();

        cylinder.R = 1;
        cylinder.h = 1;
        Console.WriteLine("半径为1,高为1的圆柱体的表面积为:" + cylinder.Area().ToString());
        Console.WriteLine("半径为1,高为1的圆柱体的体积为:" + cylinder.GetV().ToString());

        Quadrilateral quadrilateral = new Quadrilateral(1, 2, 2, 3, 3, 4, 1, 4);

        Console.WriteLine("普通四边形的周长:" + quadrilateral.Perimeter().ToString());
        Console.WriteLine("普通四边形的面积:" + quadrilateral.Area().ToString());

        Trapaezoid trapaezoid = new Trapaezoid(0, 0, 2, 0, 2, 1, 1, 1);

        Console.WriteLine("梯形的周长:" + trapaezoid.Perimeter().ToString());
        Console.WriteLine("梯形的面积:" + trapaezoid.Area().ToString());

        Parallelogram parallelogram = new Parallelogram(0, 0, 2, 0, 3, 1, 1, 1);

        Console.WriteLine("平行四边形的周长:" + parallelogram.Perimeter().ToString());
        Console.WriteLine("平行四边形的面积:" + parallelogram.Area().ToString());

        Rectangle rectangle = new Rectangle(0, 0, 2, 0, 2, 1, 0, 1);

        Console.WriteLine("长为2,宽为1的矩形面积为:" + rectangle.Area().ToString());
        Console.WriteLine("长为2,宽为1的矩形周长为:" + rectangle.Perimeter().ToString());

        Rhombus rhombus = new Rhombus(0, 0, 2, 1, 3, 3, 1, 2);

        Console.WriteLine("菱形的周长:" + rhombus.Perimeter().ToString());
        Console.WriteLine("菱形的面积:" + rhombus.Area().ToString());

        Quadrate quadrate = new Quadrate(0, 0, 1, 0, 1, 1, 0, 1);

        Console.WriteLine("正方形的周长:" + quadrate.Perimeter().ToString());
        Console.WriteLine("正方形的面积:" + quadrate.Area().ToString());

        Triangle triangle = new Triangle(new Point(0, 0), new Point(1, 0), new Point(0, 1));

        Console.WriteLine("三角形的面积为: " + triangle.Area().ToString());
        Console.WriteLine("三角形的周长为: " + triangle.Perimeter().ToString());
    }
Exemplo n.º 6
0
        static void Main(string[] args)
        {
            Console.WriteLine("Write down 2 sides and angle for figures splitting them with spaces:");
            var line = Console.ReadLine();
            var vals = line.Split(' ');

            if (vals.Length != 3)
            {
                Console.WriteLine("Wrong count of arguments.");
                Console.ReadKey();
                return;
            }

            double side1   = double.Parse(vals[0]),
                   side2   = double.Parse(vals[1]),
                   angle   = double.Parse(vals[2]);
            double minSide = side1 <side2?side1 : side2,
                                    maxSide = side1> side2 ? side1 : side2;
            Figure fig;

            Console.WriteLine("Creating Parallelogram:");
            fig = new Parallelogram(minSide, maxSide, angle);
            Console.WriteLine($"Area = {fig.Area():F3}\tPerimeter = {fig.Perimeter():F3}\n");

            Console.WriteLine("Creating Rectangle:");
            fig = new Rectangle(minSide, maxSide);
            Console.WriteLine($"Area = {fig.Area():F3}\tPerimeter = {fig.Perimeter():F3}\n");

            Console.WriteLine("Creating Square:");
            fig = new Square(maxSide);
            Console.WriteLine($"Area = {fig.Area():F3}\tPerimeter = {fig.Perimeter():F3}\n");

            Console.WriteLine("Creating Rhomb:");
            fig = new Rhomb(maxSide, angle);
            Console.WriteLine($"Area = {fig.Area():F3}\tPerimeter = {fig.Perimeter():F3}\n");

            Console.ReadKey();
        }
Exemplo n.º 7
0
        void Run()
        {
            var quad1 = new Quadrilateral(2, 3, 4, 5);

            Console.WriteLine($"quad1: perimeter is {quad1.Perimeter()}");

            var pgram1 = new Parallelogram(6, 7);

            Console.WriteLine($"pgram1: perimeter is {pgram1.Perimeter()} and area is {pgram1.Area()}");

            var sqr1 = new Square(10);

            Console.WriteLine($"sqr1: perimeter is {sqr1.Perimeter()} and area is {sqr1.Area()}");

            var tri1 = new Triangle(2, 3, 4);

            Console.WriteLine($"tri1: perimeter is {tri1.Perimeter()}");
        }
Exemplo n.º 8
0
        public static void Area_Returns_Area_of_the_Shape()
        {
            Parallelogram parallelogram = new Parallelogram(height, width, skew);

            Assert.AreEqual(50, parallelogram.Area());
        }
Exemplo n.º 9
0
    public static void Main(string[] args)
    {
        double perimeter;  //周长
        double area;       //面积
        double volume;     //体积

        //圆类
        Circle circle = new Circle(37, 43, 2.5);

        Console.WriteLine(circle.ToString());
        perimeter = circle.CircumFerence();
        area      = circle.Area();
        Console.WriteLine("该圆的周长是:{0}", perimeter);
        Console.WriteLine("该圆的面积是:{0}", area);
        circle.X = 20;
        circle.Y = 20;

        Console.WriteLine("该圆的新圆心坐标是:{0},{1}", circle.X, circle.Y);
        Console.WriteLine();

        //圆柱体
        double   high     = 10;
        Cylinder cylinder = new Cylinder(circle, high);

        Console.WriteLine(cylinder.ToString());
        area   = cylinder.Area();
        volume = cylinder.Volume();
        Console.WriteLine("该圆柱体的面积是:{0}", area);
        Console.WriteLine("该圆柱体的体积是:{0}", volume);
        Console.WriteLine();

        //三角形
        Point    point1    = new Point(1, 1);
        Point    point2    = new Point(4, 5);
        Point    point3    = new Point(3, 8);
        Line     line1     = new Line(point1, point2);
        Line     line2     = new Line(point2, point3);
        Line     line3     = new Line(point1, point3);
        Triangle triangle1 = new Triangle(point1, point2, point3);

        Console.WriteLine(triangle1.ToString());
        Triangle triangle2 = new Triangle(line1, line2, line3);

        perimeter = triangle2.Perimeter();
        area      = triangle2.Area();
        Console.WriteLine("该三角形的周长是:{0}", perimeter);
        Console.WriteLine("该三角形的面积是:{0}", area);
        if (triangle2.IsEquicrural())
        {
            Console.WriteLine("该三角形是一个等腰三角形。");
            if (triangle2.IsEquilateral())
            {
                Console.WriteLine("该三角形是一个等边三角形。");
            }
        }
        else
        {
            Console.WriteLine("该三角形不是等腰三角形。");
        }
        Console.WriteLine();

        //四边形
        Point         point4         = new Point(7, 3);
        Line          line4          = new Line(point1, point4);
        Line          line5          = new Line(point3, point4);
        Quadrilateral quadrilateral1 = new Quadrilateral(point1, point2, point3, point4);

        Console.WriteLine(quadrilateral1.ToString());
        Quadrilateral quadrilateral2 = new Quadrilateral(line1, line2, line4, line5);

        perimeter = quadrilateral2.Perimeter();
        area      = quadrilateral2.Area();
        Console.WriteLine("该四边形的周长是:{0}", perimeter);
        Console.WriteLine("该四边形的面积是:{0}", area);
        Console.WriteLine();

        //梯形
        Point      point5      = new Point(2, 1);
        Point      point6      = new Point(9, 1);
        Point      point7      = new Point(7, 4);
        Point      point8      = new Point(4, 4);
        Line       line6       = new Line(point5, point6);
        Line       line7       = new Line(point6, point7);
        Line       line8       = new Line(point7, point8);
        Line       line9       = new Line(point8, point5);
        Trapaezoid trapaezoid1 = new Trapaezoid(point5, point6, point7, point8);
        Trapaezoid trapaezoid2 = new Trapaezoid(line6, line7, line8, line9);

        Console.WriteLine(trapaezoid2.ToString());
        perimeter = trapaezoid2.Perimeter();
        area      = trapaezoid2.Area();
        Console.WriteLine("该梯形的周长是:{0}", perimeter);
        Console.WriteLine("该梯形的面积是:{0}", area);
        if (trapaezoid2.IsIsosceles())
        {
            Console.WriteLine("这是一个等腰梯形。");
        }
        Console.WriteLine();

        //平行四边形
        Parallelogram parallelogram1 = new Parallelogram(point1, point2, point3, point4);

        Console.WriteLine(parallelogram1.ToString());
        Point         point9         = new Point(5, 2);
        Point         point10        = new Point(7, 5);
        Line          line10         = new Line(point5, point9);
        Line          line11         = new Line(point9, point10);
        Line          line12         = new Line(point10, point8);
        Parallelogram parallelogram2 = new Parallelogram(point5, point9, point10, point8);

        Console.WriteLine(parallelogram2.ToString());
        Parallelogram parallelogram3 = new Parallelogram(line10, line11, line12, line9);

        perimeter = parallelogram3.Perimeter();
        area      = parallelogram3.Area();
        Console.WriteLine("该平形四边形的周长是:{0}", perimeter);
        Console.WriteLine("该平行四边形的面积是:{0}", area);
        Console.WriteLine();

        //长方形
        Rectangle rectangle1 = new Rectangle(line10, line11, line12, line9);

        Console.WriteLine(rectangle1.ToString());
        Point     point13    = new Point(1, 5);
        Point     point14    = new Point(9, 5);
        Line      line13     = new Line(point1, point6);
        Line      line14     = new Line(point6, point14);
        Line      line15     = new Line(point14, point13);
        Line      line16     = new Line(point13, point1);
        Rectangle rectangle2 = new Rectangle(line13, line14, line15, line16);

        Console.WriteLine(rectangle2.ToString());
        perimeter = rectangle2.Perimeter();
        area      = rectangle2.Area();
        Console.WriteLine("该长方形的周长是:{0}", perimeter);
        Console.WriteLine("该长方形的面积是:{0}", area);
        Console.WriteLine();

        //菱形
        Point   point15 = new Point(7, 6);
        Point   point16 = new Point(4, 8);
        Point   point17 = new Point(1, 6);
        Line    line17  = new Line(point8, point15);
        Line    line18  = new Line(point15, point16);
        Line    line19  = new Line(point16, point17);
        Line    line20  = new Line(point17, point8);
        Rhombus rhombus = new Rhombus(line17, line18, line19, line20);

        Console.WriteLine(rhombus.ToString());
        perimeter = rhombus.Perimeter();
        area      = rhombus.Area();
        Console.WriteLine("该菱形的周长是:{0}", perimeter);
        Console.WriteLine("该菱形的面积是:{0}", area);
        Console.WriteLine();

        //正方形
        Point    point18  = new Point(2, 6);
        Point    point19  = new Point(6, 6);
        Line     line21   = new Line(point8, point19);
        Line     line22   = new Line(point19, point16);
        Line     line23   = new Line(point16, point18);
        Line     line24   = new Line(point18, point8);
        Quadrate quadrate = new Quadrate(line21, line22, line23, line24);

        Console.WriteLine(quadrate.ToString());
        perimeter = quadrate.Perimeter();
        area      = quadrate.Area();
        Console.WriteLine("该正方形的周长是:{0}", perimeter);
        Console.WriteLine("该正方形的面积是:{0}", area);
        Console.WriteLine();
    }
Exemplo n.º 10
0
    public static void Main(string[] args)
    {
        Circle circle = new Circle(37, 43, 2.5);

        Console.WriteLine("该圆的" + circle.ToString());
        circle.X = 20;
        circle.Y = 20;

        Console.WriteLine("该圆的" + circle.ToString());
        Console.WriteLine("-------------------------------------------------");

        Cylinder cylinder = new Cylinder(32, 34, 4.5, 8);

        Console.WriteLine(cylinder.ToString());
        Console.WriteLine("该圆柱体的底面积是:" + cylinder.Area());
        Console.WriteLine("该圆柱体的体积是:" + cylinder.Volume());
        Console.WriteLine("-------------------------------------------------");

        Point    p1       = new Point(3, 5);
        Point    p2       = new Point(7, 5);
        Point    p3       = new Point(5, 0);
        Triangle triangle = new Triangle(p1, p2, p3);

        Console.WriteLine(triangle.ToString());
        Console.WriteLine("该三角形的周长是:" + triangle.Perimeter());
        Console.WriteLine("该三角形的面积是:" + triangle.Area());
        Console.WriteLine("-------------------------------------------------");

        Point         p4            = new Point(1, 0);
        Quadrilateral quadrilateral = new Quadrilateral(p4, p1, p2, p3);

        Console.WriteLine("该四边形的" + quadrilateral.ToString());
        Console.WriteLine("该四边形的周长是:" + quadrilateral.Perimeter());
        Console.WriteLine("该四边形的面积是:" + quadrilateral.Area());
        Console.WriteLine("-------------------------------------------------");

        Point      p5         = new Point(9, 0);
        Trapaezoid trapaezoid = new Trapaezoid(p4, p1, p2, p5);

        Console.WriteLine("该梯形的" + trapaezoid.ToString());
        Console.WriteLine("该梯形的周长是:" + trapaezoid.Perimeter());
        Console.WriteLine("该梯形的高是:" + trapaezoid.GetHeight());
        Console.WriteLine("该梯形的面积是:" + trapaezoid.Area());
        Console.WriteLine("-------------------------------------------------");

        Parallelogram parallelogram = new Parallelogram(p3, p1, p2, p5);

        Console.WriteLine("该平行四边形的" + parallelogram.ToString());
        Console.WriteLine("该平行四边形的周长是:" + parallelogram.Perimeter());
        Console.WriteLine("该平行四边形的高是:" + parallelogram.GetHeight());
        Console.WriteLine("该平行四边形的面积是:" + parallelogram.Area());
        Console.WriteLine("-------------------------------------------------");

        Point   p6      = new Point(5, 10);
        Rhombus rhombus = new Rhombus(p1, p6, p2, p3);

        Console.WriteLine("该菱形的" + rhombus.ToString());
        Console.WriteLine("该菱形的周长是:" + rhombus.Perimeter());
        Console.WriteLine("该菱形的面积是:" + rhombus.Area());
        Console.WriteLine("-------------------------------------------------");

        Point    p7       = new Point(3, 10);
        Point    p8       = new Point(7, 10);
        Quadrate quadrate = new Quadrate(p1, p7, p8, p2);

        Console.WriteLine("该正方形的" + quadrate.ToString());
        Console.WriteLine("该正方形的周长是:" + quadrate.Perimeter());
        Console.WriteLine("该正方形的面积是:" + quadrate.Area());
        Console.WriteLine("-------------------------------------------------");

        Point     p9        = new Point(3, 0);
        Point     p10       = new Point(7, 0);
        Rectangle rectangle = new Rectangle(p9, p7, p8, p10);

        Console.WriteLine("该长方形的" + rectangle.ToString());
        Console.WriteLine("该长方形的周长是:" + rectangle.Perimeter());
        Console.WriteLine("该长方形的面积是:" + rectangle.Area());
        Console.WriteLine("-------------------------------------------------");

        Console.ReadLine();
    }
Exemplo n.º 11
0
        void Run()     //instance method, not static.  We want main method to call run
        {
            var quad1 = new Quadrilateral(2, 3, 4, 5);

            Console.WriteLine($"quad1: perimeter is {quad1.Perimeter()}");

            var pgram1 = new Parallelogram(6, 7);                                                        //create instance of parallelogram

            Console.WriteLine($"pgram1: perimeter is {pgram1.Perimeter()} and area is {pgram1.Area()}"); //calling perimeter, because it's inherited.

            var sqr1 = new Square(10);

            Console.WriteLine($"sqr1: perimeter is {sqr1.Perimeter()} and area is {sqr1.Area()}"); //calling perimeter, because it's inherited.


            var tri1 = new Triangle(2, 3, 4);

            Console.WriteLine($"tri1: perimeter is {tri1.Perimeter()}");
            // note tri-one   tri1   not "trill.    not el .  The number 1
        }
Exemplo n.º 12
0
        void Run()   //instance method. New mothods don't have to be static now.
        {
            var quad1 = new Quadrilateral(2, 3, 4, 5);

            Console.WriteLine($"The perimeter of quad1 is {quad1.Perimeter()}");

            var pgram1 = new Parallelogram(6, 7);

            Console.WriteLine($"The perimeter of pgram1 is {pgram1.Perimeter()}, the area is {pgram1.Area()}");

            var square1 = new Square(10);

            Console.WriteLine($"The perimeter of square1 is {square1.Perimeter()}, the area is {square1.Area()}");

            var tri1 = new Triangle(2, 3, 4);

            Console.WriteLine($"The perimeter of tri1 is {tri1.Perimeter()}");
        }
Exemplo n.º 13
0
    public static void Main(string[] args)
    {
        Point point = new Point(5, 7);

        Console.WriteLine("点的坐标为{0}", point.ToString());
        Circle circle = new Circle(point, 2.5);

        Console.WriteLine(circle.ToString());
        Console.WriteLine("圆周长为{0},面积为{1}", circle.Perimeter(), circle.Area());
        Cylinder cylinder = new Cylinder(point, 3, 6);

        Console.WriteLine(cylinder.ToString());
        Console.WriteLine("圆柱体面积为{0},体积为{1}", cylinder.Area(), cylinder.Volume());
        Point    point1   = new Point(0, 0);
        Point    point2   = new Point(0, 2);
        Point    point3   = new Point(3, 0);
        Triangle triangle = new Triangle(point1, point2, point3);

        Console.WriteLine(triangle.ToString());
        Console.WriteLine("三角形周长为{0},面积为{1}", triangle.Perimeter(), triangle.Area());
        string s1 = triangle.IsEquicrural() ? "是" : "不是";
        string s2 = triangle.IsEquilateral() ? "是" : "不是";

        Console.WriteLine("三角形" + s1 + "等腰三角形," + s2 + "等边三角形");
        Point      point4     = new Point(3, 4);
        Trapaezoid trapaezoid = new Trapaezoid(point1, point2, point4, point3);

        Console.WriteLine(trapaezoid.ToString());
        Console.WriteLine("梯形周长为{0},面积为{1},高为{2}", trapaezoid.Perimeter(), trapaezoid.Area(), trapaezoid.H);
        Console.WriteLine(trapaezoid.WhichParallel());
        Point         point5        = new Point(3, 2);
        Parallelogram parallelogram = new Parallelogram(point1, point2, point5, point3);

        Console.WriteLine(parallelogram.ToString());
        Console.WriteLine("平行四边形周长为{0},面积为{1},两个高为{2},{3}", parallelogram.Perimeter(), parallelogram.Area(), parallelogram.H1, parallelogram.H2);
        Point   point6  = new Point(1, 0);
        Point   point7  = new Point(0, 5);
        Point   point8  = new Point(1, 10);
        Point   point9  = new Point(2, 5);
        Rhombus rhombus = new Rhombus(point6, point7, point8, point9);

        Console.WriteLine(rhombus.ToString());
        Console.WriteLine("菱形周长为{0},面积为{1},两个高为{2},{3}", rhombus.Perimeter(), rhombus.Area(), rhombus.H1, rhombus.H2);
        Rectangle rectangle = new Rectangle(point1, point2, point5, point3);

        Console.WriteLine(rectangle.ToString());
        Console.WriteLine("长方形周长为{0},面积为{1}", rectangle.Perimeter(), rectangle.Area());
        Point    point10  = new Point(2, 2);
        Point    point11  = new Point(2, 0);
        Quadrate quadrate = new Quadrate(point1, point2, point10, point11);

        Console.WriteLine(quadrate.ToString());
        Console.WriteLine("正方形周长为{0},面积为{1}", quadrate.Perimeter(), quadrate.Area());
        Console.ReadLine();
    }