|
import math class Shape: PI = 3.14 class Cylinder(Shape): def __init__(self, radius, height): self.radius = radius self.height = height def surface_area(self): return 2 * self.PI * self.radius * (self.radius + self.height) def volume(self): return self.PI * self.radius ** 2 * self.height class Sphere(Shape): def __init__(self, radius): self.radius = radius def surface_area(self): return 4 * self.PI * self.radius ** 2 def volume(self): return 4 / 3 * self.PI * self.radius ** 3 class Cube: def __init__(self, edge_length): self.edge_length = edge_length def surface_area(self): return 6 * self.edge_length ** 2 def volume(self): return self.edge_length ** 3 class Cuboid: def __init__(self, length, width, height): self.length = length self.width = width self.height = height def surface_area(self): return 2 * (self.length * self.width + self.width * self.height + self.height * self.length) def volume(self): return self.length * self.width * self.height N = int(input()) for _ in range(N): r_cylinder, h_cylinder = map(float, input().split()) r_sphere = float(input()) edge_cube = float(input()) l_cuboid, w_cuboid, h_cuboid = map(float, input().split()) cylinder = Cylinder(r_cylinder, h_cylinder) sphere = Sphere(r_sphere) cube = Cube(edge_cube) cuboid = Cuboid(l_cuboid, w_cuboid, h_cuboid) shapes = [cylinder, sphere, cube, cuboid] for shape in shapes: print(f"{shape.surface_area():.2f} {shape.volume():.2f}")
|
|