------------------------------------------------------------------------
#include <math.h>
#include <string>
#include <iostream>
#include <fstream>
using namespace std;
int main()
{
int xn=0, N = 30;
double x[N],m=0,s=0;
string filename,outfilename;
ifstream instream;
cout<<"file"<<endl;
cin>>filename;
instream.open(filename.c_str());
cout <<"successful"<<endl;
while(xn != N)
{
instream >> x[xn];
// cout << "x"<<xn << " = " << x[xn] << endl;
xn++;
}
for(xn=0;xn!=N;xn++)
{
m=m+x[xn];
}
m=m/N;
cout<<"median = "<<m<<endl;
for(xn=0;xn!=N;xn++)
{
s=s+(x[xn]-m)*(x[xn]-m);
}
s=sqrt(s/N);
cout<<"standard deviation = "<<s<<endl;
/*cout<<"outfile"<<endl;
cin>>outfilename;
ofstream outfile(outfilename.c_str());
for(xn=0;xn!=N;xn++)
{
outfile<<xn<<" "<<x[xn];
if(xn%2 != 0){outfile<<endl;}
else{outfile<<" ";}
}*/
cout<<"done"<<endl;
return 0;
}
-------------------------------------------
No comments:
Post a Comment