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

Each of you have written code that contains different functions including…. - Su

ID: 3697755 • Letter: E

Question

Each of you have written code that contains different functions including….

- Sum up numbers in an array

- Calculate the mean/average of numbers in an array

- Calculate the standard deviation of random #’s in an array

- Find the min and the max of numbers in an array

For this assignment, please create two files, a c++ program and a header .h file

The .h file should be called, stats.h and contain 5 different statistical functions.

The statistical functions are:

Find Sum

Find Mean

Find Std Deviation

Find Min

Find Max

In your main c++ program…

Read in the data from “Num of Units.txt” into an array of 30 elements

Run the different statistical functions on the data

Output to the console, the five statistical data results

Explanation / Answer

#include<iostream.h>
#include<conio.h>
#include<stdlib.h>
#include<math.h>

int findsum(int a[])
{
   int s=0;
   for(int i=0;i<30;i++)
   {
  
       s=s+a[i];

   }
   return s;
}

float findmean(int s)
{
   float av = s/30;
   return av;
}

int findmax(int a[])
{
   int mx=a[0];
   for(int i=0;i<30;i++)
   {
       if(a[i]>mx)
           mx=a[i];
   }
   return mx;
}

int findmin(int a[])
{
   int mi=a[0];
   for(int i=0;i<30;i++)
   {
  
       if(a[i]<mi)
           mi=a[i];
   }
   return mi;
}

double findsd(int a[], float av)
{
   double sd1=0;
   for(int i=0;i<30;i++)
   {

       sd1 = sd1+sqrt((pow(a[i]-av,2)));

   }
   return sd1;
}

void main()
{
   int a[30];
   int i,j,s=0,nn;
   float av;
   int m,mi,min=1, max=1000,sd1=0,sd;

   clrscr();
   for(i=0;i<30;i++)
   {
       a[i]=rand()%(max-min+1)+min;
   }
   s=findsum(a);
   cout<<"Sum is "<<s<<endl;

   av=findmean(s);
  
   cout<<"Average is :"<<av;

   m=findmax(a);
   cout<<"Maximum is "<<m<<endl;

   mi=findmin(a);
   cout<<"Minimum is "<<mi<<endl;

   sd=findsd(a,av);
   cout<<"Standard Deviation = "<<sd<<endl;


   getch();
}

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