Thursday, July 9, 2009

C++ array help 4 class?

how do i write a program that computes and outputs the mean and the standard deviation of a set of integer values that are stored in an input file. The number of integer values, n, is stored as the first data item in the file then the actual data values follow. The program will read the data items from the file and store them in an integer array defined to hold these numbers. The program will access the elements of that array in order to compute the standard deviation. In addition, your program must find the largest and smallest values in the read data items and display them on the screen.





This is what i have so far:


#include%26lt;iostream%26gt;


#include%26lt;fstream%26gt;


#include%26lt;cmath%26gt;


#include%26lt;string%26gt;





using namespace std;





int main()


{


ifstream input;


int number;


double mean;


int count;


int total;


double standd;





input.open("inputFile-1.txt");








I am not sure where to take it from here. Can some one please show an example of how to read the data items from the file and store them in an array

C++ array help 4 class?
the following is a suggestion but the file must be sequential to work:





ifstream ClientFile ( "Clients.txt", ios::in)


if ( !ClientFile ) {


cerr%26lt;%26lt;"File Corrupted.\n";


exit(1);


}








int x;


int counter=0;


while ( ClientFile %26gt;%26gt; x )


{


counter++;//this will give you the number of values in file


}





//there is an error here but i don't know why try it on the compiler


const int y = counter;


int array [ y ];


while ( ClientFile %26gt;%26gt; x )


{


for ( int i=0; i%26lt;=counter; i++)


array [ i ] = x;


};


i hope i help you.....and i'll figure out the full solution

wedding florist

No comments:

Post a Comment