u may only use print(), input(), len(), typecasting functions. a. Write a Python class definition for a geometric shape - the quadrilateral. A quadrilateral is characterized by four points in the Cartesian coordinate system. Each point is a pair of numbers (x, y) which are the Cartesian coordinates. In your class definition, provide the following methods - getters/setters to return/set each point as a tuple, print all four points of the quadrilateral, distance between any two points of the quadrilateral. Test your class by creating objects and calling each of the methods. b. Modify your class in Problem a. to create two more classes, one for a Pentagon (5 Cartesian points, one for each corner) and one for a Hexagon (6 Cartesian points, one for each corner). Add a new method to determine the sum of lengths of all the sides in addition to the methods in Problem a
a)
Python code for the required scenario:
class quadrilateral:
def __init__(self, a1, a2, b1, b2, c1, c2, d1, d2):
self.a1 = a1
self.a2 = a2
self.b1 = b1
self.b2 = b2
self.c1 = c1
self.c2 = c2
self.d1 = d1
self.d2 = d2
def get_points(self):
return self.a1, self.a2, self.b1, self.b2, self.c1, self.c2, self.d1, self.d2
def set_points(self, A1, A2, B1, B2, C1, C2, D1, D2):
self.a1, self.a2 = A1, A2
self.b1, self.b2 = B1, B2
self.c1, self.c2 = C1, C2
self.d1, self.d2 = D1, D2
def distance(x1, x2, y1, y2):
return ((x2-x1)^2 + (y2-y1)^2)^0.5
m= quadrilateral()
m.set_points(2,3,5,4,0,3,1,2)
print( m.get_poits())
print(m.distance(2,0,3,1))
Trending now
This is a popular solution!
Step by step
Solved in 4 steps