0

I am new to c++ and i am supposed to do a test case using my stub with hand calculated mean & standard deviation of number of students that are saved in the .o file in linux.

my code is

```
#include <iostream>
#include <fstream>
#include <cmath>
using namespace std;
const int nMax = 10;
int main() {
int nScore[nMax];
double fMean;
double fVar;
double fStdev;
int i;
ifstream in("score.txt", ios::in);
for ( i = 0; i < nMax; i++ ) {
in >> nScore[i];
}
in.close();
cout << "Numbers are" << endl;
for ( i = 0; i < nMax; i++ ) {
cout << nScore[i] << endl;
}
cout << endl;
// average
int nTotal = 0;
for ( i = 0; i < nMax; i++ ) {
nTotal += nScore[i];
}
fMean = (double)nTotal/(double)nMax;
//variance
fVar = 0.0;
for ( i = 0; i < nMax; i++ ) {
fVar += ((double)nScore[i]-fMean) * ((double)nScore[i]-fMean);
}
fVar /= (double)nMax;
// standard deviation
fStdev = sqrt(fVar);
cout << "average\t\t: " << fMean << endl;
cout << "standard deviation\t: " << fStdev << endl;
return 0;
}
```

and I am not sure I am going in to right direction or not. And I do not have clear understanding about stub. so can anyone help me with this?

*Edited 5 Years Ago by pok.kys90*: n/a