$30
Write five classes conforming the relation shown in UML class diagram below, i.e. a Square is a Rectangle, SquarePyramid inherit from multiple classes (Square and Triangle) and TrianglePrism inherit from multiple classes (Rectangle and Triangle). Write all the class implementations to Prism.py. Test your code with the sample main function provided to you (Main.py). It must print the sample output provided to you (output.txt). You can also create and test your own main functions.
Details:
In the diagram, class notations consist of three parts; (1) class name, (2) class attributes, (3) class methods. The name of the class appears in the first partition, e.g., Square, Rectangle etc. Attributes are shown in the second partition, e.g., edge, width etc. Methods are shown in the third partition, e.g., get_volume(), get_area() etc.
Member functions:
- get area methods: calculates the area of the related shape and returns it.
- get perimeter methods: calculates the perimeter of the related shape and returns it.
- get_volume(self): calculates the volume of the TrianglePrism and returns it.
- __str__(self): returns a string representation of the class. For the output format, please check provided output file (output.txt). Note that, print the area, perimeter and volume with 2 digit after decimal point. Hint: '{0:.2f}'.format(x)
Hints:
-You can use math library (import math).
- In this lab, we use equilateral triangle which all three sides have the same length.
Area of triangle =𝑒𝑑𝑔𝑒
Perimeter of triangle = 3∗ 𝑒𝑑𝑔𝑒
Area of rectangle = 𝑤𝑖𝑑𝑡ℎ ∗ ℎ𝑒𝑖𝑔ℎ𝑡
Perimeter of rectangle = 2∗ (𝑤𝑖𝑑𝑡ℎ +ℎ𝑒𝑖𝑔ℎ𝑡)
Area of square = 𝑒𝑑𝑔𝑒2
Perimeter of square = 4∗ 𝑒𝑑𝑔𝑒
Area of SquarePyramid = area of square + 3* (area of triangle)
Area of TrianglePrism = 2*(area of triangle) + 3* (area of rectangle)
Volume of TrianglePrism = (area of triangle) * height
Testing: You are provided with an output file. You can test your program from the command line using the following commands. (>: stands for command prompt)
> python Main.py > my_output.txt
The outputs, which you generate using the print() function in the source codes, are redirected to my_output.txt file. You can then check if my_output.txt file is exactly the same with the provided output.txt file, using diff command from the command prompt: > diff output.txt m
2