public static void make_figure(int type) { Random rd = new Random(); if (type == 1) { double x = rd.Next(1000) + 1; square s = new square(x); if (s.Is_leagal()) { All_area += s.Get_Area(); } else { Wrong++; } } else if (type == 2) { double x = rd.Next(1000) + 1; double y = rd.Next(1000) + 1; rectangle s = new rectangle(x, y); if (s.Is_leagal()) { All_area += s.Get_Area(); } else { Wrong++; } } else { double x = rd.Next(1000) + 1; double y = rd.Next(1000) + 1; double z = rd.Next(1000) + 1; triangle s = new triangle(x, y, z); if (s.Is_leagal()) { All_area += s.Get_Area(); } else { Wrong++; } } }
static void Main(string[] args) { Console.WriteLine("please input the form:"); string form = Console.ReadLine(); if (form == "triangle") { triangle triangle = new triangle(); Console.WriteLine("please input the length "); int length = Console.Read(); Console.WriteLine("please input the width "); int width = Console.Read(); int s1 = triangle.TriangleArea(length, width); Console.WriteLine("the triangle's area is " + s1); } if (form == "rectangle") { rectangle rectangle = new rectangle(); Console.WriteLine("please input the bottomlength "); int bottomlength = Console.Read(); Console.WriteLine("please input the height "); int height = Console.Read(); int s2 = rectangle.RectangleArea(bottomlength, height); Console.WriteLine("the rectangle's area is " + s2); } if (form == "square") { square square = new square(); Console.WriteLine("please input the sidelength "); int sidelength = Console.Read(); int s3 = square.SquareArea(sidelength); Console.WriteLine("the square's area is " + s3); } if (form == "circle") { circle circle = new circle(); Console.WriteLine("please input the radius "); int radius = Console.Read(); double s4 = circle.CircleArea(radius); Console.WriteLine("the circle's area is " + s4); } }