Advertisement
Guest User

Untitled

a guest
Dec 15th, 2019
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.80 KB | None | 0 0
  1. from math import pi as PI
  2.  
  3. class Point:
  4.     """Klasa opisująca punkt na płaszczyźnie"""
  5.     def __init__ (self,x1,y1):
  6.       self.__x = x1
  7.       self.__y = y1
  8.  
  9.     def __str__(self):
  10.       return "Lokalizacja punktu: x={}, y={}".format(self.__x,self.__y)
  11.  
  12.  
  13. class Figure(Point):
  14.     """Klasa opisująca figurę na płaszczyźnie o środku w punkcie Point"""
  15.     __listOfFigures = []
  16.    
  17.     def __init__ (self,x,y,
  18.                 colour = "czerwony",
  19.                 name="figura",
  20.                 lineWidth=2,
  21.                 lineStyle='-'):
  22.         super().__init__(x,y)
  23.         self.__colour = colour
  24.         self.__name = name
  25.         self.__lineWidth = lineWidth
  26.         self.__lineStyle = lineStyle
  27.        
  28.  
  29.     def __str__(self):
  30.         return '{}\nKolor figury = "{}"\nTyp figury = {}\nGrubość linii = {} \nStyl linii = "{}"'.format(
  31.                                                                    super().__str__(), self.__colour,
  32.                                                                    self.__name,self.__lineWidth,
  33.                                                                    self.__lineStyle)
  34.        
  35.     def addFigure(self,newFigure):
  36.         self.__listOfFigures.append(newFigure)
  37.        
  38.     def printFigureList(self):
  39.         for figure in self.__listOfFigures:
  40.             print(figure)
  41.             print(30*'-')
  42.            
  43.     def numberOfElements(self):
  44.         return len(self.__listOfFigures)
  45.        
  46.     def area(self):
  47.         """Metoda licząca pole figury"""
  48.         pass
  49.  
  50.     def perimeter(self):
  51.         """Metoda licząca obwód figury"""
  52.         pass
  53.  
  54.  
  55. class Triangle(Figure):
  56.     def __init__ (self,x,y,
  57.             base,
  58.             sideA,
  59.             sideB,
  60.             height,
  61.             colour = "czerwony",
  62.             name = "trójkąt",
  63.             lineWidth=2,
  64.             lineStyle='-'):
  65.             super().__init__(x,y,colour,name,lineWidth,lineStyle)
  66.             self.__base = base
  67.             self.__sideA = sideA
  68.             self.__sideB = sideB
  69.             self.__height = height
  70.  
  71.     def __str__(self):
  72.         return "{} \nPole = {}, obwód = {}".format(super().__str__(),self.area(),self.perimeter())
  73.  
  74.     def perimeter(self):
  75.         return self.__base + self.__sideA + self.__sideB
  76.  
  77.     def area(self):
  78.         return 0.5*self.__base*self.__height
  79.  
  80.  
  81. class Rectangle(Figure):
  82.     def __init__ (self,x,y,
  83.         sideA,
  84.         sideB,
  85.         colour = "czerwony",
  86.         name = "prostokąt",
  87.         lineWidth=2,
  88.         lineStyle='-'):
  89.             super().__init__(x,y,colour,name,lineWidth,lineStyle)
  90.             self.__sideA = sideA
  91.             self.__sideB = sideB
  92.  
  93.     def __str__(self):
  94.         return "{} \nPole = {}, obwód = {}".format(super().__str__(),self.area(),self.perimeter())
  95.    
  96.     def perimeter(self):
  97.         return 2*self.__sideA + 2*self.__sideB
  98.  
  99.     def area(self):
  100.         return self.__sideA*self.__sideB
  101.  
  102.    
  103. class Circle(Figure):
  104.     def __init__ (self,x,y,
  105.         radius,
  106.         colour = "czerwony",
  107.         name = "koło",
  108.         lineWidth=2,
  109.         lineStyle='-'):
  110.         super().__init__(x,y,colour,name,lineWidth,lineStyle)
  111.         self.__radius = radius
  112.  
  113.     def __str__(self):
  114.         return "{} \nPole = {}, obwód = {}".format(super().__str__(),self.area(),self.perimeter())
  115.  
  116.     def perimeter(self):
  117.         return 2*PI*self.__radius
  118.  
  119.     def area(self):
  120.         return self.__radius**2*PI
  121.  
  122.  
  123. def main():
  124.     figure = Figure(3,4)      
  125.     figure.addFigure(Triangle(2,2,4,5,6,7))
  126.     figure.addFigure(Rectangle(3,3,2,2))
  127.     figure.addFigure(Circle(4,4,12))
  128.  
  129.     figure.printFigureList()
  130.  
  131.     print("Liczba figur w licie: {}".format(figure.numberOfElements()))
  132.      
  133.  
  134. if __name__ == '__main__':
  135.     main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement