I need help explaining this code, ESPECIALLY the median part of this code. So if
ID: 3635899 • Letter: I
Question
I need help explaining this code, ESPECIALLY the median part of this code. So if you can just reference some important things to know about the code, key concepts, etc. and explain how the median part works it would be really helpful, thank you.#include<iostream>
#include<cmath>
using namespace std;
int main()
{
const int size=56;
double R[size]={45.3, 67.8, 34.3, 51.2, 48.5, 61.3, 59.3, 65.1,
49.3, 42.4, 63.5, 69.8, 71.2, 39.8, 55.5, 53.2,
56.7, 48.8, 61.5, 51.2, 58.9, 63.1, 67.5, 62.4,
52.4, 50.2, 49.8, 56.8, 59.7, 60.4, 45.8, 43.8,
51.3, 54.8, 55.1, 52.3, 56.2, 59.7, 63.0, 46.7,
63.1, 58.2, 41.9, 59.2, 57.2, 67.3, 68.2, 38.9,
51.3, 63.8, 53.4, 58.9, 56.3, 58.9, 53.2, 56.8};
double min, max, range, sum, mean, std, variance , median;
sum =0;
min = R[0];
max = R[0];
// Find average
for(int count=0; count < size; count++)
{
sum=sum+R[count];
//Find Maximum
if (R[count]> max)
{
max=R[count];
}
//Find Minimum
if (R[count]< min)
{
min=R[count];
}
}
mean=sum/size;
range=max -min;
// Find the variance and standard devisation
double sum1 =0;
for (int i=0; i<=size-1; i++)
{
sum1=sum1+(R[i] - mean)* (R[i] - mean);
}
variance= sum1 / size;
std=sqrt(variance);
// Find the Median
for (int i=0; i< size -1; i++)
for (int j=i+1; j< size; j++)
{
if ( R[i] > R[j] )
{
//swap R[i] and R[j]
double temp = R[i];
R[i] = R[j];
R[j] = temp;
}
}
if ( size % 2 == 0 )
{
median = (R[size/2] + R[size/2 -1]) / 2;
}
else median = R[size/2];
cout << "Maximum = " << max << endl;
cout << "Minimum = " << min << endl;
cout << "Range = " << range << endl;
cout << "Mean = " << mean << endl;
cout << "Standard deviation = " << std << endl;
cout << "Variance = " << variance << endl;
cout << "Median = " << median << endl;
return 0;
}
Explanation / Answer
#include // Calls the iostream library #include // Calls the cmath library using namespace std; int main() { const int size=56; // Sets a constant integer (that won't change) of 56 under the var //name: size double R[size]={45.3, 67.8, 34.3, 51.2, 48.5, 61.3, 59.3, 65.1, 49.3, 42.4, 63.5, 69.8, 71.2, 39.8, 55.5, 53.2, 56.7, 48.8, 61.5, 51.2, 58.9, 63.1, 67.5, 62.4, 52.4, 50.2, 49.8, 56.8, 59.7, 60.4, 45.8, 43.8, 51.3, 54.8, 55.1, 52.3, 56.2, 59.7, 63.0, 46.7, 63.1, 58.2, 41.9, 59.2, 57.2, 67.3, 68.2, 38.9, 51.3, 63.8, 53.4, 58.9, 56.3, 58.9, 53.2, 56.8}; // Creates and fills an array named R at a size of 56 variables to hold. double min, max, range, sum, mean, std, variance , median; //Defines variables of //type double sum =0; // Initializes variable "sum" to 0. min = R[0]; //Initialization max = R[0]; //Initialization // Find average for(int count=0; count max) { max=R[count]; } //Find Minimum (by checking if each variable is smaller than those previous) if (R[count]Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.