Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions

Question

What is the difference between an ER diagram and an ER schema

Answered: 1 week ago