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

I am needing help writing a program that declares a 50 element integer array and

ID: 3549433 • Letter: I

Question

I am needing help writing a program that declares a 50 element integer array and fill the array with random numbers between 0 and 25 inclusive. After the array outputs the following statistics: sum, mean, 'mode', largest value, and smallest value. The program should use functions to fill the array and compute each of the statistics. Remember, a function does 'one' thing really well, so you'll need need at least 6 programmer defined functions in this program..


I will appreciate any help!! Also I need to mention that I am not in a very advanced class so please if you can make it as simple as possible that would be great!

Explanation / Answer

#include <iostream>
#include <cstdlib>
using namespace std;

//function proto types
int Number_Generat();
int sum(int temp_Array[50]);
int mean(int temp_Array[50]);
int largest(int temp_Array[50]);
int smallest(int temp_Array[50]);


int main(void) {


/* initialize random seed: */
srand (time(NULL));

int my_Array[50];    //Array declaration   
int i;

for(i=0;i<50;i++)
{
     my_Array[i]= Number_Generat();    //Just initializing array with random #'s
}

// function call(s)
int total = sum(my_Array);
int nmean = mean(my_Array);
int large = largest(my_Array);
int small = smallest(my_Array);

//printing result out
cout<<"Sum is: "<<total<<endl;
cout<<"Mean is: "<<nmean<<endl;
cout<<"Largest is: "<<large<<endl;
cout<<"Smallest is: "<<small<<endl;    



return 0;
}

//function generate random numbers between 0 and 25
int Number_Generat()
{
    int num = 0;
    num = rand()%26;
    return num;
}

//function sums the array
int sum(int temp_Array[50])
{
    int total=0;
    for(int i=0; i<50;i++)
    {
        total = total+temp_Array[i];
    }
    return total;
}

//function to find mean
int mean(int temp_Array[50])
{
    int mean = sum(temp_Array)/50;
    return mean;
}

//function to find largest of 50 elements
int largest(int temp_Array[50])
{
    int tmp=temp_Array[0];
    for(int i =1;i<50;i++)
    {
        if(temp_Array[i] >tmp)
        tmp = temp_Array[i];
    }

    return tmp;
}

//function to find smallest of 50 elements
int smallest(int temp_Array[50])
{
    int tmp=temp_Array[0];
    for(int i =1;i<50;i++)
    {
        if(temp_Array[i] < tmp)
        tmp = temp_Array[i];
    }

    return tmp;
}