Exercise Ll Use Rectangle Class Assume Length Width Measured Feet Write Class Named Carpe Q43857275
For this exercise, you’ll use the Rectangle class below (you canassume that the length and width are measured in feet). Write aclass named Carpet that has two data members: size andcostPerSqFoot. It should have a constructor that takes aRectangle object and a float as parameters and uses them toinitialize its data members. It should also have a method namedcost that asks the size data member for its areaand uses that to calculate and return the cost of the Carpet. Thisis an example of class composition because the Carpet classcontains a Rectangle object as one of its data members.
class Rectangle:
“””
Represents a geometric rectangle
“””
def __init__(self, length, width):
self.length = length
self.width = width
def area(self):
return self.length * self.width
def perimeter(self):
return 2 * self.length + 2 * self.width
Expert Answer
Answer to For this exercise, you’ll use the Rectangle class below (you can assume that the length and width are measured in feet)….
OR