Question: You are tasked with designing a Python program to model a simple shape hierarchy. A: Define an abstract base class called Shape. This class should:
You are tasked with designing a Python program to model a simple shape hierarchy.
A: Define an abstract base class called Shape. This class should:
Declare an abstract method called area to calculate and return the area of the shape.
Declare an abstract method called perimeter to calculate and return the perimeter of the shape.
Define a common method called displayinfo that prints the name of the shape.
B: Define three subclasses of Shape for different types of shapes: Circle, Rectangle, and Triangle. Each subclass should:
Inherit from the Shape class.
Implement the area and perimeter methods specific to that type of shape.
Override the displayinfo method to print the name of the shape eg "Circle", "Rectangle", or "Triangle"
C: Define a class called ShapeManager. This class should:
Have a list called shapes to store instances of different shapes both Circle, Rectangle, and Triangle
Implement a method called addshape that takes a Shape object as a parameter and adds it to the shapes list.
Implement a method called listshapes that displays the names, areas, and perimeters of all shapes in the shapes list.
Implement a method called totalarea that calculates and returns the total area of all shapes in the shapes list.
Implement a method called totalperimeter that calculates and returns the total perimeter of all shapes in the shapes list.
D: Write a sample program that demonstrates the use of your shape hierarchy. Create instances of different shapes, add them to the ShapeManager, list the shapes with their names, areas, and perimeters, and calculate the total area and total perimeter using polymorphism.
Python
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
