1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
|
#include <iostream>
#include <cmath>
#include <fstream>
#include <string>
using namespace std;
float calculateSD(ifstream& nameFile);
int main()
{
string input;
ifstream nameFile("data.txt");
if (!nameFile)
return (cout << " ERROR : cannot open file.\n"), 1;
while (getline(nameFile, input))
cout << input << endl;
nameFile.clear();
nameFile.seekg(0);
calculateSD(nameFile);
}
float calculateSD(ifstream& nameFile);
{
int a {}, b {}, c {}, d {}, e {};
nameFile >> a >> b >> c >> d >> e;
float sum1 = 0.0, sum2 = 0.0, sum3 = 0.0;
float mean1, mean2, mean3;
float standardDeviation1 = 0.0, standardDeviation2 = 0.0, standardDeviation3 = 0.0;
for (int a {}, b {}, c {}, d {}, e {}; nameFile >> a >> b >> c >> d >> e; )
{
sum1 += c;
sum2 += d;
sum3 += e;
}
mean1 = sum1/10;
mean2 = sum2/10;
mean3 = sum3/10;
for (int a {}, b {}, c {}, d {}, e {}; nameFile >> a >> b >> c >> d >> e; )
{
standardDeviation1 += pow(c - mean1, 2);
standardDeviation2 += pow(d - mean2, 2);
standardDeviation3 += pow(e - mean3, 2);
}
cout << "Standard Deviation 1 = " << sqrt(standardDeviation1 / 10) << endl;
cout << "Standard Deviation 2 = " << sqrt(standardDeviation2 / 10)<< endl;
cout << "Standard Deviation 3 = " << sqrt(standardDeviation3 / 10)<< endl;
return 0;
}
| |