Question: Your goal is to fix all the errors in the code below. Note that you do not need to change the logic in any way.

Your goal is to fix all the errors in the code below. Note that you do not need to change the logic in any way. You do not need to understand what the code is doing in order to do this assignment. The errors are largely focused on Rust Lecture 2 material and ownership concepts. Once you have fixed all the errors and your code compiles, you are done (assuming you don't change the program logic). [HIGHLY RECOMMENDED]: Zip file for running on your own machine: Rust2.zip main.rs 12 23 1 use std::vec :: Vec; 2 3 // You may not modify the function signatures. If you do so, the tests will not pass. 4 // Feel free to modify anything inside the function. 5 6 // Helper function to calculate the mean of a sample. 7 - fn mean(sample: &Vec) -> f32 { 8 let mut sum: usize = 0; 9 for *i in sample { 10 sum += i; 11 } sum / sample.len() as f32 13 } 14 15 // Helper function to calculate the standard deviation of a sample. 16 - fn sd(sample: &Vec) -> f32 { 17 let mut sum: f32 = 0.6; 18 let mean = mean (sample); 19 for i in sample { 20 sum += (i - mean). powf (2.0); 21 } 22 (sum as f32 / sample.len().sqrt() } 24 25 // Helper function to calculate the z-score of a value in a sample. 26 fn z(value: usize, mean: f32, sd: f32) -> f32 { 27 (value - mean) / sd 28 } 29 30 // Function to normalize a sample. 31 - fn normalize(sample: &Vec) -> Vec { 32 let mut n : Vec = vec![]; 33 let mean : f32 = mean(sample); 34 let sd: f32 = sd(sample); 35 for &num in sample { 36 n.push(z(*num, *mean, *sd)); 37 } 38 39 } 40 41 // Main function. 42 - fn main() { 43 let s : Vec = vec![3, 7, 5, 4, 5, 5, 6, 7, 7, 7]; let n: Vec = normalize(&s); 45 printin!(\"{}\", mean(&s)); 46 println(\"{}\", sd(&s)); println(\"{:?}\", s); 48 println(\"{:}\", n); 49 n 44 47

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!