Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Introduction to Wireless and Mobile Systems

Authors: Dharma P. Agrawal, Qing An Zeng

4th edition

1305087135, 978-1305087132, 9781305259621, 1305259629, 9781305537910 , 978-130508713

More Books

Students also viewed these Programming questions

Question

=+7. For the cost matrix of Exercise 3,

Answered: 1 week ago

Question

List and briefly define the ATM service categories.

Answered: 1 week ago

Question

List and briefly explain the fields in an ATM cell.

Answered: 1 week ago