Advertisement
Guest User

Untitled

a guest
Jul 16th, 2013
192
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.17 KB | None | 0 0
  1. class Circle():
  2.  
  3.     #Constructor
  4.     def __init__ (self, radius):        
  5.         self.__radius = radius
  6.         self.calcArea()
  7.  
  8.        
  9.     def calcArea(self, PI = 3.14):        
  10.         self.__area = (self.__radius**2) * PI
  11.  
  12.  
  13.     #Get Functions
  14.     def GetArea(self):        
  15.         return self.__area
  16.  
  17.        
  18.     def GetRadius(self):        
  19.         return self.__radius
  20.  
  21.  
  22.     #Set Functions
  23.     def SetRadius(self, radius):
  24.         self.__radius = radius
  25.         self.calcArea()
  26.  
  27.        
  28. class Cylinder():
  29.  
  30.     #Constructor    
  31.     def __init__(self, radius, height):        
  32.         self.__height = height
  33.         self.__base = Circle(radius)
  34.         self.calcVolume()
  35.  
  36.        
  37.     def calcVolume(self):        
  38.         self.__volume = self.__base.GetArea() * self.__height
  39.  
  40.  
  41.     #Get Functions
  42.     def GetVolume(self):        
  43.         return self.__volume
  44.  
  45.     def GetBase(self):
  46.         return self.__base
  47.  
  48.     def GetRadius(self):
  49.         return self.__base.GetRadius()
  50.  
  51.     def GetHeight(self):
  52.         return self.__height
  53.  
  54.     #Set Functions
  55.     def SetRadius(self, radius):
  56.         self.__base.SetRadius(radius)
  57.         self.calcVolume()
  58.  
  59.     def SetHeight(self, height):
  60.         self.__height = height
  61.         self.calcVolume()
  62.  
  63.  
  64. class Cone(Cylinder):
  65.  
  66.     #Constructor
  67.     def __init__ (self, radius, height):        
  68.         Cylinder.__init__(self, radius, height)
  69.         self.calcVolume()
  70.  
  71.        
  72.     def calcVolume(self):
  73.         Cylinder.calcVolume(self)
  74.         self.__volume = Cylinder.GetVolume(self) * (1.0/3.0)
  75.  
  76.  
  77.     #Get Functions
  78.     def GetVolume(self):
  79.         return self.__volume
  80.    
  81.  
  82.     #Set Functions
  83.     def SetRadius(self, radius):
  84.         Cylinder.SetRadius(self, radius)
  85.         self.calcVolume()
  86.  
  87.     def SetHeight(self, height):
  88.         Cylinder.SetHeight(self, height)
  89.         self.calcVolume()
  90.  
  91.  
  92.  
  93. def main():
  94.         cylinder = Cylinder(5, 6)
  95.         cone = Cone(5, 6)
  96.         circle = Circle(5)
  97.        
  98.         print cylinder.GetVolume()
  99.         print cone.GetVolume()
  100.         print circle.GetArea()
  101.         cone.SetHeight(7)
  102.         print cone.GetVolume()
  103.  
  104. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement