Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Circle():
- #Constructor
- def __init__ (self, radius):
- self.__radius = radius
- self.calcArea()
- def calcArea(self, PI = 3.14):
- self.__area = (self.__radius**2) * PI
- #Get Functions
- def GetArea(self):
- return self.__area
- def GetRadius(self):
- return self.__radius
- #Set Functions
- def SetRadius(self, radius):
- self.__radius = radius
- self.calcArea()
- class Cylinder():
- #Constructor
- def __init__(self, radius, height):
- self.__height = height
- self.__base = Circle(radius)
- self.calcVolume()
- def calcVolume(self):
- self.__volume = self.__base.GetArea() * self.__height
- #Get Functions
- def GetVolume(self):
- return self.__volume
- def GetBase(self):
- return self.__base
- def GetRadius(self):
- return self.__base.GetRadius()
- def GetHeight(self):
- return self.__height
- #Set Functions
- def SetRadius(self, radius):
- self.__base.SetRadius(radius)
- self.calcVolume()
- def SetHeight(self, height):
- self.__height = height
- self.calcVolume()
- class Cone(Cylinder):
- #Constructor
- def __init__ (self, radius, height):
- Cylinder.__init__(self, radius, height)
- self.calcVolume()
- def calcVolume(self):
- Cylinder.calcVolume(self)
- self.__volume = Cylinder.GetVolume(self) * (1.0/3.0)
- #Get Functions
- def GetVolume(self):
- return self.__volume
- #Set Functions
- def SetRadius(self, radius):
- Cylinder.SetRadius(self, radius)
- self.calcVolume()
- def SetHeight(self, height):
- Cylinder.SetHeight(self, height)
- self.calcVolume()
- def main():
- cylinder = Cylinder(5, 6)
- cone = Cone(5, 6)
- circle = Circle(5)
- print cylinder.GetVolume()
- print cone.GetVolume()
- print circle.GetArea()
- cone.SetHeight(7)
- print cone.GetVolume()
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement