You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
lee e70d46f49a quest 8: adding tests and subjects 3 years ago
..
README.md quest 8: adding tests and subjects 3 years ago

README.md

project_motion

Instructions

For this exercise you will have to create a projectile motion.

You will be provided with a structure called Object that will have all variables that are essential for the projectile physics. (distance, velocity, height, time)

You must implement :

  • A function throw_object that will initialize the Object with a given velocity and height.
  • The trait Iterator with the .next() in which it must calculate the next position of the object after 1 second. It will return an Option with the Object, It will return None if the object already reached the floor.

Expected Function


#[derive(Debug, Clone, PartialEq)]
pub struct Object {
    pub distance: f32,
    pub velocity: f32,
    pub height: f32,
    pub time: f32,
}

impl Object {
    pub fn throw_object(velocity: f32, height: f32) -> Object {}
}

impl Iterator for Object {
  // next
}

Usage

Here is a program to test your function

fn main() {
    let mut obj = Object::throw_object(50.0, 150.0);
    println!("{:?}", obj.next());
    println!("{:?}", obj.next());
    println!("{:?}", obj.next());
    println!("{:?}", obj.next());
    println!("{:?}", obj.next());
    println!("{:?}", obj.next());
}

And its output:

student@ubuntu:~/[[ROOT]]/test$ cargo run
Some(Object { distance: 50.0, velocity: 50.0, height: 145.1, time: 1.0 })
Some(Object { distance: 100.0, velocity: 50.0, height: 125.5, time: 2.0 })
Some(Object { distance: 150.0, velocity: 50.0, height: 81.4, time: 3.0 })
Some(Object { distance: 200.0, velocity: 50.0, height: 3.0, time: 4.0 })
None
None
student@ubuntu:~/[[ROOT]]/test$

Notions