1use std::f32::consts::PI;
2
3#[derive(Debug)]
4pub struct Circle{
5
6}
7
8pub trait AreaC {
9
10 fn calc(&self, r : f32) -> f32;
11
12}
13
14impl Circle{
15
16 pub fn new()->Self{
17
18 Self{}
19 }
20}
21
22impl AreaC for Circle{
23
24 fn calc(&self, r : f32) -> f32{
25
26 if r < 0.0 {
27
28 return -1.0;
29 }
30 PI*r*r
31 }
32
33}
34
35#[derive(Debug)]
36pub struct Triangle{
37
38}
39
40impl Triangle{
41
42 pub fn new()->Self{
43
44 Self{}
45 }
46}
47
48#[derive(Debug)]
49pub struct Rectangle{
50
51}
52
53pub trait Area{
54
55 fn calc(&self, l : f32, w: f32) -> f32;
56}
57
58impl Rectangle{
59
60 pub fn new()->Self{
61
62 Self{}
63 }
64
65}
66
67impl Area for Rectangle {
68
69 fn calc(&self, l : f32, w: f32) -> f32{
70
71 if (l < 0.0 )||(w < 0.0){
72
73 return -1.0;
74 }
75 l*w
76 }
77
78}
79
80impl Area for Triangle {
81
82 fn calc(&self, b : f32, w: f32) -> f32{
83
84 if (b< 0.0 )||(w < 0.0){
85
86 return -1.0;
87 }
88 b*w/2.0
89 }
90
91}