Welcome to Westonci.ca, your go-to destination for finding answers to all your questions. Join our expert community today! Join our Q&A platform and connect with professionals ready to provide precise answers to your questions in various areas. Get detailed and accurate answers to your questions from a dedicated community of experts on our Q&A platform.

Implement a program that manages shapes. Implement a class named Shape with a method area() which returns the double value 0.0. Implement three derived classes named Rectangle, Square, and Circle. Declare necessary properties in each including getter and setter function and a constructor that sets the values of these properties. Override the area() function in each by calculating the area using the defined properties in that class.

Sagot :

Answer:

Explanation:

The following code is written in Python. It creates the parent class Shape and the three subclasses Rectangle, Square, and Circle that extend Shape. Shape has the constructor which is empty and the area method which returns 0.0, while the three subclasses take in the necessary measurements for its constructor. Each subclass also has getter and setter methods for each variable and an overriden area() method which returns the shapes area.

class Shape:

   def __init__(self):

       pass

   def area(self):

       return 0.0

class Square(Shape):

   _length = 0

   _width = 0

   def __init__(self, length, width):

       self._width = width

       self._length = length

   def area(self):

       area = self._length * self._width

       return area

   def get_length(self):

       return self._length

   def get_width(self):

       return self._width

   def set_length(self, length):

       self._length = length

   def set_width(self, width):

       self._width = width

class Rectangle(Shape):

   _length = 0

   _width = 0

   def __init__(self, length, width):

       self._width = width

       self._length = length

   def area(self):

       area = self._length * self._width

       return area

   def get_length(self):

       return self._length

   def get_width(self):

       return self._width

   def set_length(self, length):

       self._length = length

   def set_width(self, width):

       self._width = width

class Circle(Shape):

   _radius = 0

   def __init__(self, radius):

       self._radius = radius

   def area(self):

       area = 2 * 3.14 * self._radius

       return area

   def get_radius(self):

       return self._radius

   def set_radius(self, radius):

       self._radius = radius

View image sandlee09