We would like to calculate the (biased) variance of an array inputted from array:dat by passing a function as a parameter. In the following program variance.cpp, you need to define function

`float var (float, int);`

and modify function

`float sum (float (*) (float, int), int*, int s);`

to complete the program of calculating the variance. The code segments to be
defined are highlighted (in red) (also have //comments written)

 ``123456789101112131415161718192021222324252627282930313233343536`` ``````//variance.cpp #include #include #include using namespace std; float sum (float (*) (float, int), int*, int s); float var (float, int); int main(){ int a[10] = {8,5,12,6,13,11,9,7,10,14}; // input from array.dat instead int s = (sizeof a)/4; cout << "Mean = " << sum(NULL, a, s) << endl; cout << "Variance=" << sum(var, a, s) << endl; cout << "\n\n\nPress any key to close console window: "; char c; cin >> c; return 0; } float sum (float (*pf) (float, int), int*n, int s) { float sum=0; int*p=n; ...// calculate mean for (int i=0; i
What I have so far...
 ``12345678910111213141516171819202122232425262728293031323334353637383940`` `````` //variance.cpp #include #include #include using namespace std; float sum (float (*) (float, int), int*, int s); float var (float, int); int main(){ ifstream arrayfile; // me trying to input .dat file arrayfile.open ("array.dat"); // so lost? int s = (sizeof a)/4; cout << "Mean = " << sum(NULL, a, s) << endl; cout << "Variance=" << sum(var, a, s) << endl; cout << "\n\n\nPress any key to close console window: "; char c; cin >> c; return 0; } float sum (float (*pf) (float, int), int*n, int s) { float sum=0; int*p=n; ...// calculate mean ... I know its the average, but since i dont know how to input the .dat I can't start on this yet. for (int i=0; i
Do you have a question or problem?

I see a possible problem in your sum() function. You have named a variable with the same name as the function, probably a problem. You shouldn't name variables the same name as your functions.