use std::io::stdin;
use std::io::BufRead;
use std::io::BufReader;
mod figures {
pub trait Figure {
fn area(&self) -> f64;
fn printName(&self) {
print!("Figure = {} ", self.name());
}
fn name(&self) -> &'static str;
}
pub struct Rectangle {
w: f64,
h: f64,
}
impl Rectangle {
pub fn new(width: f64, height: f64) -> Rectangle {
Rectangle { w: width, h: height }
}
}
impl Figure for Rectangle {
fn name(&self) -> &'static str {
"Rectangle"
}
fn area(&self) -> f64 {
self.h * self.w
}
}
pub struct Square {
rectangle: Rectangle,
}
impl Square {
pub fn new(size: f64) -> Square {
Square { rectangle: Rectangle { w: size, h: size } }
}
}
impl Figure for Square {
fn name(&self) -> &'static str {
"Square"
}
fn area(&self) -> f64 {
self.rectangle.area()
}
}
pub struct Ellipse {
rectangle: Rectangle,
}
impl Ellipse {
pub fn new(a: f64, b: f64) -> Ellipse {
Ellipse { rectangle: Rectangle { w: a, h: b } }
}
}
impl Figure for Ellipse {
fn name(&self) -> &'static str {
"Ellipse"
}
fn area(&self) -> f64 {
self.rectangle.area() * 3.1415
}
}
}
fn main() {
use figures::{Figure, Rectangle, Square, Ellipse};
let v: [&Figure; 3] = [
&Rectangle::new(2.0, 3.0),
&Square::new(4.0),
&Ellipse::new(2.0, 3.0)
];
for i in v.iter() {
i.printName();
println!(", area: {}", i.area());
}
}
dXNlIHN0ZDo6aW86OnN0ZGluOwp1c2Ugc3RkOjppbzo6QnVmUmVhZDsKdXNlIHN0ZDo6aW86OkJ1ZlJlYWRlcjsKCm1vZCBmaWd1cmVzIHsKCQoJcHViIHRyYWl0IEZpZ3VyZSB7CgkJZm4gYXJlYSgmc2VsZikgLT4gZjY0OwoJCWZuIHByaW50TmFtZSgmc2VsZikgewoJCQlwcmludCEoIkZpZ3VyZSA9IHt9ICIsIHNlbGYubmFtZSgpKTsKCQl9CgkJZm4gbmFtZSgmc2VsZikgLT4gJidzdGF0aWMgc3RyOwoJfQoJCglwdWIgc3RydWN0IFJlY3RhbmdsZSB7CgkJdzogZjY0LAo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