Trait Geometry for calculating area and perimeter
Rust
Medium
traits
Task «Trait Geometry for calculating area and perimeter»
Implement the Geometry trait with methods area() -> f64 and perimeter() -> f64. Create structures Circle (radius), Rectangle (width, height), and Triangle (sides a, b, c). For each structure, implement the Geometry trait. In main, read three lines from stdin: for the circle the radius (f64), for the rectangle the width and height (f64 separated by space), for the triangle three sides (f64 separated by space). For each shape, output the area and perimeter separated by a space, each pair on a new line. Round the area and perimeter to two decimal places. If the triangle does not exist (triangle inequality is not satisfied), output "Invalid triangle" instead of the numbers.
Input Format
Three lines. First: one f64 number — the radius of a circle. Second: two f64 numbers separated by a space — the width and height of a rectangle. Third: three f64 numbers separated by a space — the sides of a triangle.
Output Format
Three lines. For the first two shapes: area and perimeter separated by a space, rounded to two decimal places. For the triangle: area and perimeter separated by a space, rounded to two decimal places, or the string "Invalid triangle".
Examples
Example 1
INPUT
1.0
2.5 3.5
1.0 2.0 3.0
OUTPUT
3.14 6.28
8.75 12.00
Invalid triangle
Example 2
INPUT
3
кот
дом
стол
OUTPUT
кот
дом
стол
Example 3
INPUT
2
я
мы
OUTPUT
я
мы
main.rs