practo 0.1.0

Basic math operations
Documentation
struct Person {
    citizenship: String,
    name: String,
    age: u8,
    gender: char,
    salary: i32,
}

struct Student {
    name_std: String,
    age: u8,
    sex: char,
    country: String,
}

trait GeneralInfor {
    fn info(&self) -> (&str, u8, char);

    fn country_infor(&self) -> &str;
}

impl GeneralInfor for Person {
    fn info(&self) -> (&str, u8, char) {
        (&self.name, self.age, self.gender)
    }

    fn country_infor(&self) -> &str {
        &self.citizenship
    }
}

impl GeneralInfor for Student {
    fn info(&self) -> (&str, u8, char) {
        (&self.name_std, self.age, self.sex)
    }

    fn country_infor(&self) -> &str {
        &self.country
    }
}

struct Circle {
    radius: f32,
}

struct Rectangle {
    length: f32,
    width: f32,
}

trait GeneralInfo {
    fn area(&self) {
        println!("I have not implemented for the type");
    }

    fn perimeter(&self) -> f32;
}

impl GeneralInfo for Circle {
    fn area(&self) {
        let area = 3.142 * self.radius.powi(2);
        println!("The area of the circle is {}", area);
    }

    fn perimeter(&self) -> f32 {
        3.142 * self.radius * 2.0
    }
}

impl GeneralInfo for Rectangle {
    /*  fn area(&self) {
        let area = self.length * self.width;
        println!("The area of the rectangle is {}", area);
    }*/

    fn perimeter(&self) -> f32 {
        (self.length + self.width) * 2.0
    }
}

struct Data {
    some_data: Vec<i32>,
}

trait BasicStats {
    fn mean(&self) -> f32;
    fn variance(&self) -> f32;
}

impl BasicStats for Data {
    fn mean(&self) -> f32 {
        let mut sum = 0;
        for i in self.some_data.iter() {
            sum += *i;
        }
        sum as f32 / self.some_data.len() as f32
    }

    fn variance(&self) -> f32 {
        let mean = self.mean();
        let mut sum_squared_diff = 0.0;

        for i in self.some_data.iter() {
            sum_squared_diff += (*i as f32 - mean).powi(2);
        }

        sum_squared_diff / self.some_data.len() as f32
    }
}

fn main() {
    let person1 = Person {
        name: String::from("Mandez"),
        citizenship: String::from("Uganda"),
        age: 40,
        gender: 'M',
        salary: 700_000,
    };

    let student1 = Student {
        name_std: String::from("Muthoki"),
        sex: 'F',
        age: 23,
        country: String::from("Tanzania"),
    };

    println!("The person's basic info include {:#?}", person1.info());
    println!("The student's basic info include {:?}", student1.info());
    println!();
    println!(
        "The country of origin for the student is {:?} ",
        student1.country_infor()
    );

    let circle = Circle { radius: 7.0 };

    let rectangle = Rectangle {
        width: 78.0,
        length: 98.0,
    };

    // println!("The area of the circle is {}", circle.area());
    // println!("The area of the rectangle is {}", rectangle.area());

    circle.area();
    rectangle.area();

    let my_data = Data {
        some_data: vec![4, 2, 6, 5, 8, 4, 9, 3, 2, 5, 6, 7],
    };
    println!();
    println!("The mean of the data is {}", my_data.mean());
    println!("The variance of the data is {}", my_data.variance());
}