예제 #1
0
        static void Main(string[] args)
        {
            Console.WriteLine("Hello World!");
            Console.WriteLine("Adding new Cirlce.");
            Circle cirlce = new Circle(2.0);

            Console.WriteLine("Cirlce's radius is 2.0! Calculating it's area.");
            cirlce.GetArea();
            Console.WriteLine("Circle's area is " + cirlce.Area);
            Console.WriteLine("Adding new Triangle.");
            double[] i    = { 2, 1, 1 };
            Triangle tri1 = new Triangle(i);

            Console.WriteLine("Triangle's sides are 2, 1 and 1! Calculating it's area.");
            tri1.GetArea("sides");
            Console.WriteLine("Triangle's area is " + tri1.Area);
            Console.WriteLine("Adding new Triangle.");
            double[] о    = { 3.5, 3, 1 };
            Triangle tri3 = new Triangle(о);

            Console.WriteLine("Triangle's sides are 3.5, 3 and 1! Calculating it's area.");
            tri3.GetArea("sides");
            Console.WriteLine("Triangle's area is " + tri3.Area);
            Console.WriteLine("Adding new Triangle.");
            double[] k    = { 2, 3, 1 };
            Triangle tri2 = new Triangle(k);

            Console.WriteLine("Triangle's sides are 3, 2 and 1! Checking wheter it right-angled.");
            if (tri2.IsRightAngled())
            {
                Console.WriteLine("Sure it is!");
            }
            else
            {
                Console.WriteLine("I guess it's not.");
            }

            Console.WriteLine("Adding new Triangle.");
            double[] t    = { 2, 2.236, 1 };
            Triangle tri4 = new Triangle(t);

            Console.WriteLine("Triangle's sides are 2.24, 2 and 1! Checking wheter it right-angled.");
            if (tri4.IsRightAngled())
            {
                Console.WriteLine("Sure it is!");
            }
            else
            {
                Console.WriteLine("I guess it's not.");
            }
            Console.WriteLine("Press any key...");
            Console.ReadKey();
        }
예제 #2
0
        public static void Main(string[] args)
        {
            Triangle triangle = new Triangle();

            Console.WriteLine("请输入三角形的三边长:");
            String str1 = Console.ReadLine();
            String str2 = Console.ReadLine();
            String str3 = Console.ReadLine();
            double a    = Convert.ToDouble(str1);
            double b    = Convert.ToDouble(str2);
            double c    = Convert.ToDouble(str3);

            triangle.GetArea(a, b, c);
            Circle circle = new Circle();

            Console.WriteLine("请输入圆的半径:");
            String str4   = Console.ReadLine();
            double radius = Convert.ToDouble(str4);

            circle.GetArea(radius);
            Square square = new Square();

            Console.WriteLine("请输入正方形的边长:");
            String str5   = Console.ReadLine();
            double length = Convert.ToDouble(str5);

            square.GetArea(length);
            Rectangle rectangle = new Rectangle();

            Console.WriteLine("请输入长方形的长和宽:");
            String str6   = Console.ReadLine();
            String str7   = Console.ReadLine();
            double width  = Convert.ToDouble(str6);
            double height = Convert.ToDouble(str7);

            rectangle.GetArea(width, height);
            Console.ReadKey();
        }