```python import math class Circle: def __init__(self, radius): self.__radius = radius def setradius(self, radius): self.__radius = radius def getradius(self): return self.__radius def cir(self): return 2 * math.pi * self.__radius def area(self): return math.pi * self.__radius 2 def print(self): print("圆的半径为:", self.__radius) class Ball: def __init__(self, radius): self.circle = Circle(radius) def barea(self): return 4 * math.pi * self.circle.getradius() 2 def vol(self): return 4 / 3 * math.pi * self.circle.getradius() 3 class Cylinder: def __init__(self, radius, height): self.__radius = radius self.__height = height def setheight(self, height): self.__height = height def getheight(self): return self.__height def barea(self): return 2 * math.pi * self.__radius * (self.__radius + self.__height) def vol(self): return math.pi * self.__radius 2 * self.__height def print(self): print("圆柱体的半径为:", self.__radius, "高为:", self.__height) def test(n, m): ball_sum_barea = 0 ball_sum_vol = 0 cylinder_sum_barea = 0 cylinder_sum_vol = 0 for i in range(n): ball = Ball(i + 1) ball_sum_barea += ball.barea() ball_sum_vol += ball.vol() for i in range(m): cylinder = Cylinder(i + 1, i + 2) cylinder_sum_barea += cylinder.barea() cylinder_sum_vol += cylinder.vol() print("n个球体的表面积之和为:", ball_sum_barea) print("n个球体的体积之和为:", ball_sum_vol) print("m个圆柱体的表面积之和为:", cylinder_sum_barea) print("m个圆柱体的体积之和为:", cylinder_sum_vol) test(3, 4) ``` [2024-06-13 19:29:36 | AI写代码神器 | 614点数解答]