Here is the input case for my files :
#include "Person.cpp"
#include <cmath>
const double EPS = 0.00001;
Person a("alice", 92);
Person b("bernice", 77);
Person array[] = {a,b};
double result = stdDev(array, 2);
ASSERT_TRUE(fabs(result-7.5) < EPS);
**********************Below are my separate CPP and HPP files for the function. When i use my own main the function works but the above input does not. thoughts?
--------------------------------Person.hpp----------------------------
#ifndef MY_PERSON
# define MY_PERSON
#include<iostream>
using namespace std;
class Person
{
int age;
string name;
public:
// constructor
Person();
// constructor
Person(string, int);
// getter methods
string getName();
int getAge();
};
#endif
---------------------------------------------------Peron.cpp--------------------------------------------------------------
#include "Person.hpp"
// constructor
Person::Person()
{
name = "";
age = 0;
}
// constructor
Person::Person(string n, int a)
{
name = n;
age = a;
}
// getter methods
string Person::getName()
{
return name;
}
int Person::getAge()
{
return age;
}
-------------------------------------------------stdDev.cpp-----------------------------------------------
#include "Person.cpp"
#include<cmath>
double stdDev(Person arr[], int n)
{
double mean = 0.0, sum = 0.0;
int i;
// get the total of age of all person
for( i = 0 ; i < n ; i++ )
{
sum += (double)arr[i].getAge();
}
// calculate mean
mean = sum / (double)n;
double temp_sum = 0.0;
for( i = 0 ; i < n ; i++ )
{
temp_sum += pow(arr[i].getAge() - mean, 2);
}
return sd;
}
-----------------------------------------------------main.cpp---------------------------------------------------------
#include "stdDev.cpp"
int main()
{
Person *arr = new Person[6];