Homework Solution: Develop a program that calculates basic statistics on a one-dimensional a…

    Description: Develop a program that calculates basic statistics on a one-dimensional array of doubles. Your program should first prompt the user for the size of the array followed by prompting for individual elements of the array. Your program should contain the following functions: 1.) min() Finds and returns the minimum value within the array. 2.) max() Finds and returns the maximum value within the array. 3.) mean() Finds and returns the mean value of the elements in the array. 4.) median() Finds and returns the median value of the elements in the array. 5.) sort()* Sorts the elements of the array in ascending order. 6.) readArray() Populates the elements of the array with input from the user (or via file redirection). 7.) printArray() Prints the elements of the array. *You may use any sorting algorithm that you want. Here are a few easy suggestions: Bubble sort pseudocode: do swapped = false for each i in 1 to length(A) inclusive do: if A[i-1] > A[i] then swap A[i-1] and A[i] swapped = true end if end for while swapped Insertion sort pseudocode: i ← 1 while i < length(A) j ← i while j > 0 and A[j-1] > A[j] swap A[j] and A[j-1] j ← j - 1 end while i ← i + 1 end while Additional Specifications: Your program should not use any pre-existing classes such as string or vector classes! Make sure your program compiles and runs on one of the Linux machines in the Linux lab before you submit. Your program should consist of a single source code. EXAMPLE OUTPUT: casey@vanderwaal:-/Dropbox/Teaching/CSCE24oFalt2617/Projects/Assignment2$ g++ Assignment2.cpp casey@vanderwaal:-/Dropbox/Teaching/CSCE240Fall2017/Projects/Assignment2$ ./a.out Please enter the size of your array: 6 Please enter 6 elements to populate the array. 212.3-6799 θ The elements of the array are: 212.3-6 7 99 θ The elements of the array sorted in ascending order: 6 0 27 12.3 99 The min of the array is-6 The max of the array is 99 The mean of the array is 19.05 The median of the array is 4.5 casey@vanderwaal:-/Dropbox/Teaching/CSCE240Fall2017/Projects/Assignment2$ Examples using file redirection:
    Show transcribed image textcasey@vanderwaal:-/Dropbox/Teaching/CSCE24oFalt2617/Projects/Assignment2$ g++ Assignment2.cpp casey@vanderwaal:-/Dropbox/Teaching/CSCE240Fall2017/Projects/Assignment2$ ./a.out Please enter the size of your array: 6 Please enter 6 elements to populate the array. 212.3-6799 θ The elements of the array are: 212.3-6 7 99 θ The elements of the array sorted in ascending order: 6 0 27 12.3 99 The min of the array is-6 The max of the array is 99 The mean of the array is 19.05 The median of the array is 4.5 casey@vanderwaal:-/Dropbox/Teaching/CSCE240Fall2017/Projects/Assignment2$

    Expert Answer

     
    #include<iostream> using namespace std;

    Description:

    Develop a program that calculates basic statistics on a individual-dimensional attire of enfolds. Your program should chief alert the explanationr control the extent of the attire followed by alerting control special elements of the attire. Your program should hold the forthcoming functions:

    1.) min()

    Finds and income the partiality treaconfident among the attire.

    2.) max()

    Finds and income the zenith treaconfident among the attire.

    3.) balance()

    Finds and income the balance treaconfident of the elements in the attire.

    4.) median()

    Finds and income the median treaconfident of the elements in the attire.

    5.) class()*

    Sorts the elements of the attire in ascending manage.

    6.) readArray()

    Populates the elements of the attire with input from the explanationr (or via improve redirection).

    7.) imprintArray()

    Prints the elements of the attire.

    *You may explanation any classing algorithm that you omission. Here are a lacking indulgent suggestions:

    Bubble class pseudocode:

    do
    swapped = false
    control each i in 1 to tediousness(A) additive do:
    if A[i-1] > A[i] then
    swap A[i-1] and A[i]
    swapped = true
    end if
    end control
    while swapped

    Insertion class pseudocode:

    i ← 1
    while i < tediousness(A)
    j ← i
    while j > 0 and A[j-1] > A[j]
    swap A[j] and A[j-1]
    j ← j – 1
    end while
    i ← i + 1
    end while

    Additional Specifications:

    Your program should not attributable attributable attributable explanation any pre-existing classes such as string or vector classes!

    Make confident your program compiles and runs on individual of the Linux machines in the Linux lab precedently you surrender.

    Your program should stop of a only fount decree.

    EXAMPLE OUTPUT:

    casey@vanderwaal:-/Dropbox/Teaching/CSCE24oFalt2617/Projects/Assignment2$ g++ Assignment2.cpp casey@vanderwaal:-/Dropbox/Teaching/CSCE240Fall2017/Projects/Assignment2$ ./a.quenched Please invade the extent of your attire: 6 Please invade 6 elements to populate the attire. 212.3-6799 θ The elements of the attire are: 212.3-6 7 99 θ The elements of the attire classed in ascending manage: 6 0 27 12.3 99 The min of the attire is-6 The max of the attire is 99 The balance of the attire is 19.05 The median of the attire is 4.5 casey@vanderwaal:-/Dropbox/Teaching/CSCE240Fall2017/Projects/Assignment2$

    Examples using improve redirection:

    Show transcribed copy textcasey@vanderwaal:-/Dropbox/Teaching/CSCE24oFalt2617/Projects/Assignment2$ g++ Assignment2.cpp casey@vanderwaal:-/Dropbox/Teaching/CSCE240Fall2017/Projects/Assignment2$ ./a.quenched Please invade the extent of your attire: 6 Please invade 6 elements to populate the attire. 212.3-6799 θ The elements of the attire are: 212.3-6 7 99 θ The elements of the attire classed in ascending manage: 6 0 27 12.3 99 The min of the attire is-6 The max of the attire is 99 The balance of the attire is 19.05 The median of the attire is 4.5 casey@vanderwaal:-/Dropbox/Teaching/CSCE240Fall2017/Projects/Assignment2$

    Expert Vindication

     

    #include<iostream>

    using namespace std;

    void class(enfold basis[], int n){

    control (int i =0; i<n; i++){
    control (int j = i+1; j<n; j++){
    if (data[i] > basis[j]){
    enfold temp = basis[i];
    data[i] = basis[j];
    data[j] = temp;
    }
    }
    }
    }

    void imprint(enfold basis[], int n){
    control (int i = 0; i<n; i++){
    cquenched << basis[i] << ” “;
    }
    cquenched << endl;
    }

    enfold min(enfold basis[],int n){
    enfold min = basis[0];
    control (int i = 0; i<n; i++){
    if (data[i] < min)
    min = basis[i];
    }
    return min;
    }

    enfold max(enfold basis[], int n){
    enfold max = basis[0];
    control (int i = 0; i<n; i++){
    if (data[i] > max)
    max = basis[i];
    }
    return max;
    }

    enfold balance(enfold basis[], int n){
    enfold mix = 0;

    control (int i = 0; i<n; i++){
    mix = mix + basis[i];
    }
    return mix/n;
    }

    enfold median(enfold basis[], int n){
    enfold mix = 0;
    enfold median;
    if ( n% 2 == 0){
    int i = n/2-1;
    int j = n/2;
    median = (data[i] + basis[j])/2;
    }
    else {
    median = basis[n/2];
    }
    return median;
    }

    int main(){

    int n;
    cquenched << “Please invade extent of attire : “;
    cin >> n;
    enfold *basis = upstart enfold[n];
    cquenched << “Please invade ” << n << ” elements to poulate the attire” << endl;
    control (int i = 0; i<n; i++){
    cin >> basis[i];
    }
    cquenched << “The elements of the attire are:” << endl;
    print(data, n);
    cquenched << endl;

    cquenched << “The elements of the attire classed in ascending manage:” << endl;
    sort(data,n);
    print(data, n);
    cquenched << endl;

    cquenched << “The min of the attire is:” << min(data,n) << endl;
    cquenched << “The max of the attire is:” << max(data,n) << endl;
    cquenched << “The balance of the attire is:” << balance(data,n) << endl;
    cquenched << “The median of the attire is:” << median(data,n) << endl;
    cquenched << endl;

    return 0;
    }