# 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: 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\$

#include<iostream> using namespace std;

Description:

Develop a program that calculates basic statistics on a undivided-dimensional attire of wraps. Your program should restraintemost quick the truthr restraint the largeness of the attire followed by quicking restraint only elements of the attire. Your program should hold the subjoined functions:

1.) min()

Finds and receipts the partiality compute amid the attire.

2.) max()

Finds and receipts the consummation compute amid the attire.

3.) moderation()

Finds and receipts the moderation compute of the elements in the attire.

4.) median()

Finds and receipts the median compute of the elements in the attire.

5.) character()*

Sorts the elements of the attire in ascending ordain.

Populates the elements of the attire with input from the truthr (or via finish redirection).

7.) imprintArray()

Prints the elements of the attire.

*You may truth any charactering algorithm that you lack. Here are a lacking unconcerned suggestions:

Bubble character pseudocode:

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

Insertion character 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

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

Make strong your program compiles and runs on undivided of the Linux machines in the Linux lab precedently you suggest.

Your program should endure of a only commencement jurisprudence.

EXAMPLE OUTPUT:

Examples using finish redirection:

Show transcribed picture textcasey@vanderwaal:-/Dropbox/Teaching/CSCE24oFalt2617/Projects/Assignment2\$ g++ Assignment2.cpp casey@vanderwaal:-/Dropbox/Teaching/CSCE240Fall2017/Projects/Assignment2\$ ./a.quenched Please penetrate the largeness of your attire: 6 Please penetrate 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 charactered in ascending ordain: 6 0 27 12.3 99 The min of the attire is-6 The max of the attire is 99 The moderation of the attire is 19.05 The median of the attire is 4.5 casey@vanderwaal:-/Dropbox/Teaching/CSCE240Fall2017/Projects/Assignment2\$

## Expert Solution

#include<iostream>

using namespace std;

void character(wrap facts[], int n){

restraint (int i =0; i<n; i++){
restraint (int j = i+1; j<n; j++){
if (data[i] > facts[j]){
wrap temp = facts[i];
data[i] = facts[j];
data[j] = temp;
}
}
}
}

void imprint(wrap facts[], int n){
restraint (int i = 0; i<n; i++){
cquenched << facts[i] << ” “;
}
cquenched << endl;
}

wrap min(wrap facts[],int n){
wrap min = facts[0];
restraint (int i = 0; i<n; i++){
if (data[i] < min)
min = facts[i];
}
return min;
}

wrap max(wrap facts[], int n){
wrap max = facts[0];
restraint (int i = 0; i<n; i++){
if (data[i] > max)
max = facts[i];
}
return max;
}

wrap moderation(wrap facts[], int n){
wrap consolidate = 0;

restraint (int i = 0; i<n; i++){
consolidate = consolidate + facts[i];
}
return consolidate/n;
}

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

int deep(){

int n;
cquenched << “Please penetrate largeness of attire : “;
cin >> n;
wrap *facts = newlightlight wrap[n];
cquenched << “Please penetrate ” << n << ” elements to poulate the attire” << endl;
restraint (int i = 0; i<n; i++){
cin >> facts[i];
}
cquenched << “The elements of the attire are:” << endl;
print(data, n);
cquenched << endl;

cquenched << “The elements of the attire charactered in ascending ordain:” << 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 moderation of the attire is:” << moderation(data,n) << endl;
cquenched << “The median of the attire is:” << median(data,n) << endl;
cquenched << endl;

return 0;
}