Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

2) Write the function definition of a function) named stats5 that calculates and

ID: 3698497 • Letter: 2

Question

2) Write the function definition of a function) named stats5 that calculates and returns the total, average, highest, lowest, standard deviation (sd), root mean square (RMS), and harmonic mean (H) of the elements of the array a. Use the variables tota, avg_a, max a, min a, sd a, RMS a, and H a for the total, average, highest value, lowest value, standard deviation, root mean square, and harmonic mean. The standard deviation, root mean square, and harmonic mean are given by: ' length laD) n(n- Sale s 2 https://www.courseher Aqm/file/23647993/CSC1240-exam-2/

Explanation / Answer

As no language is specified so I did in java

public class Statistics {

public static void stats5(int a[])

{

int tot_a=0;

int min_a=a[0];

int max_a=a[0];

double avg_a=0.0;

double sd_a=0;

double rms_a=0;

double h_a=0;

double sumOfInverse=0;

int sumOfSquares=0;

int squareOfSum=0;

for(int i=0;i<a.length;i++)

{

tot_a=tot_a+a[i];

}

System.out.println("total of the given array is : "+tot_a);

avg_a=(double)(tot_a/a.length);

System.out.println("average of the given array is : "+avg_a);

for(int i=1;i<a.length;i++)

{

if(min_a>a[i])

min_a=a[i];

if(max_a<a[i])

max_a=a[i];

sumOfSquares=sumOfSquares+a[i]*a[i];

sumOfInverse=sumOfInverse+(double)1/a[i];

}

System.out.println("Maximum of the given array is : "+max_a);

System.out.println("Minimum of the given array is : "+min_a);

squareOfSum=tot_a*tot_a;

sd_a=Math.sqrt((a.length*sumOfSquares-squareOfSum)/(a.length*a.length-1));

System.out.println("standard deviation of the given array is : "+sd_a);

rms_a=Math.sqrt(sumOfSquares/a.length);

System.out.println("RMS value of the given array is : "+rms_a);

h_a=a.length/sumOfInverse;

System.out.println("Harmonic mean of the given array is : "+h_a);

}

public static void main(String[] args) {

// TODO Auto-generated method stub

int a[]={24,36,83,52,77,89,64,24,72,55,32};

stats5(a);

}

}

output:

total of the given array is : 608
average of the given array is : 55.0
Maximum of the given array is : 89
Minimum of the given array is : 24
standard deviation of the given array is : 21.470910553583888
RMS value of the given array is : 59.270566050949775
Harmonic mean of the given array is : 53.95010888028194

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote