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

Here is program so far: #include <string> #include <cmath> #include \"Person.hpp

ID: 3869353 • Letter: H

Question

Here is program so far:

#include <string>
#include <cmath>
#include "Person.hpp"

using namespace std;

double stdDev(Person array[], int size)
{

double sum=0.0;
double mean;
double stdDev=0.0;

for (int i=0;i<=size;i++)
{
cout<<array[i].getAge()<<endl;
cout<<array[i].getName()<<endl;
sum+=array[i].getAge();
}

mean=sum/size;

for (int i=0;i<=size;i++)
{
stdDev += pow(array[i].getAge() - mean, 2);
}
return sqrt(stdDev/size);
}


int main()
{
double result;
Person myArray[]={
Person("Joe",25),
Person("Joey",40),
Person("Kyle",20),
Person("Dave",28)
};
result=stdDev(myArray, 3);
cout<<"The standard deviation is: "<<result<<endl;

return 0;
}

for my output i get:
25
Joe
40
Joey
20
Kyle
28
Dave
The standard deviation is: 13.8015.

However, this is not the correct standard deviation and I only want the program to print the standard deviation. How do I go about to fix this?

Explanation / Answer

The problem is with statndard deviation function.while calculating average you used the size value.Instrad u have to use (size+1) and also while calculating the standard deviation.Because the size is 4.

while u r calling the function u passed the size of an array as 3.

If u didnt get clarity just tell me.I will explain u clearly.Thank You.

______________________

double stdDev(Person array[], int size)
{
double sum=0.0;
double mean;
double stdDev=0.0;
for (int i=0;i<=size;i++)
{
sum+=array[i].getAge();
}
mean=sum/(size+1);
cout<<"mean "<<mean<<endl;
for (int i=0;i<=size;i++)
{
stdDev += pow(array[i].getAge() - mean, 2);
}
return sqrt(stdDev/(size+1));
}

__________________Plz rate me well.Thank You

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