class Point():
def __init__(self, x, y): # x , y of type INTEGER
self.__x = x
self.__y = y
def getX(self):
return self.__x
def getY(self):
return self.__y
def setX(self, setX):
self.__x = setX
def setY(self, setY):
self.__y = setY
class Square():
def __init__(self, top, bottom): # top and bottom of type INTEGER
self.__top = top
self.__bottom = bottom
def getTop(self):
return self.__top
def getBottom(self):
return self.__bottom
def getArea(self):
Area = (self.__top.x - self.__bottom) * (self.__top.y - self.__bottom.y)
if Area < 0:
Area = Area * (-1)
return Area
class Circle():
def __init__(self, center, radius): # center, radius of type INTEGER
self.__center = center
self.__radius = radius
def getCenter(self):
return self.__center
def getRadius(self):
return self.__radius
def getArea(self):
return 3.14 * (self.__radius ** 2)
class Triangle():
def __init__(self, x, y, z):
self.__x = x
self.__y = y
self.__z = z
def getX(self):
return self.__x
def getY(self):
return self.__y
def getZ(self):
return self.__z
def getArea(self):
return 1
# b
circles = []
squares = []
triangles = []
areas = []
def readData():
try:
file = open("Shapes.txt", "r")
line = file.readline().strip()
while line != "":
if line == "circles":
line1 = file.readline().strip()
line2 = file.readline().strip()
line1List = line1.split()
center = Point(int(line1List[0]), int(line1List[1]))
radius = int(line2)
myCircle = Circle(center, radius)
circles.append(myCircle)
areas.append(("Circle", myCircle.getArea()))
elif line == "square":
line1 = file.readline().strip()
line2 = file.readline().strip()
line1List = line1.split()
top = Point(int(line1List[0]), int(line1List[1]))
line2List = line2.split()
bottom = Point(int(line2List[0]), int(line2List[1]))
mySquare = Square(top, bottom)
squares.append(mySquare)
areas.append((mySquare.getArea(), "square"))
elif line == "triangle":
line1 = file.readline().strip()
line2 = file.readline().strip()
line3 = file.readline().strip()
line1List = line1.split()
x = Point(int(line1List[0]), int(line1List[1]))
line2List = line2.split()
y = Point(int(line2List[0]), int(line2List[1]))
line3List = line3.split()
z = Point(int(line3List[0]), int(line3List[1]))
myTriangle = Triangle(x, y, z)
triangles.append(myTriangle)
areas.append((myTriangle.getArea(), "triangle"))
except IOError:
print("File not found")
def sortCircles():
n = len(circles)
for i in range(n - 1):
for j in range(0, n - i - 1):
if circles[j].getCenter().getX() > circles[j + 1].getCenter().getX() and circles[j].getCenter().getY() > \
circles[j + 1].getCenter().getY():
temp = circles[j]
circles[j] = circles[j + 1]
circles[j + 1] = temp
def sortSquares(): # using insertion sort
for i in range(1, len(squares)):
current_square = squares[i]
j = i - 1 # prev element
while j >= 0 and current_square.getArea() < squares[j].getArea():
temp = squares[j]
squares[j] = squares[j + 1]
squares[j + 1] = temp
def smallestTriangle():
minArea = triangles[0].getArea()
for i in range(1, len(triangles)):
if triangles[i].getArea() < minArea:
minArea = triangles[i].getArea()
return minArea
readData()
sortCircles()
sortSquares()