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

>> and I am not sure I am going in to right direction or not.

Does it give you the right answer? Does it give you the right answer no matter what's in the input file? Then it's probably right. If not, it's wrong. What's the data file look like, what is your program SUPPOSED to output, and what does it really.


>> And I do not have clear understanding about stub.

I don't have a clear understanding about what you mean by "stub".

And I do not have clear understanding about stub.
I don't have a clear understanding about what you mean by "stub".

in the book it says a stub may consist of a single trace output statement, indicating that we have reached the function, or a group of debug output statements, showing the current values of the parameter.

Edited 3 Years Ago by happygeek: fixed formatting

This article has been dead for over six months. Start a new discussion instead.