Question: For this exercise, you'll use the Rectangle class below (you can assume that the length and width are measured in feet). Write a class named

For this exercise, you'll use the Rectangle class below (you can assume that the length and width are measured in feet). Write a class named Carpet that has two data members: size and costPerSqFoot. It should have a constructor that takes a Rectangle object and a float as parameters and uses them to initialize its data members. It should also have a method named cost that asks the size data member for its area and uses that to calculate and return the cost of the Carpet. This is an example of class composition because the Carpet class contains 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

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!