#include <iostream>
using namespace std;
int main( ) {
int numValue = 1 ,
double variance,
mean,
standDeviation,
num,
sumvalueSquare,
sumValue;
ifstream myFile;
myFile. open ( "statsFile.txt" ) ;
while ( myFile >> num )
{
sumValue = sumValue + num;
sumvalueSquare = pow ( sumValue, 2.0 ) ;
variance = pow ( sumValue, 2.0 ) - ( pow ( sumValue, 2.0 ) / numValue) / ( numValue - 1 ) ;
standDeviation = sqrt ( variance) ;
mean = sumValue / numValue;
cout << num << endl << cout << "The variance is :" << variance << endl
<< "The standard deviation is:" << standDeviation << endl
<< "The mean is:" << mean << endl;
}
myFile. close ( ) ;
}
return 0 ;
//SPEC SHEET:
//1. Declare a variable to hold a counter (that will count the number of
// values read from the file)
//2. (NO stop value is needed. The loop stops when all values have been read
// from the file)
//3. Declare one variable to be used (And re-used) for the reading of each
// value from the file.
//4. Declare variables for the variance, the mean, and the standard deviation
//5. Declare variable for two total sums: sum of values and sum of each value
// squared
//6. Read the values from the file one at a time, and update each of the 2
// totals
//7. use both totals to calculate the variance
//8. Use the first total (sum of values) to calculate the mean (mean = total
// / number of values)
//9. Display the variance, standard deviation and mean
// The teacher also mentioned using getline in the class that day, but she
// did not specifically say that she wanted it on the program, but there could
// be a chance.
}
I2luY2x1ZGUgPGlvc3RyZWFtPgp1c2luZyBuYW1lc3BhY2Ugc3RkOwoKCmludCBtYWluKCkgewoKCWludCBudW1WYWx1ZSA9IDEsCglkb3VibGUgdmFyaWFuY2UsCgkJICAgbWVhbiwKCQkgICBzdGFuZERldmlhdGlvbiwKCQkgICBudW0sCgkJICAgc3VtdmFsdWVTcXVhcmUsCgkJICAgc3VtVmFsdWU7CgoJaWZzdHJlYW0gbXlGaWxlOwoJbXlGaWxlLiBvcGVuICgic3RhdHNGaWxlLnR4dCIpOwoKCgl3aGlsZSAoIG15RmlsZSA+PiBudW0gKQoJewoJICAgc3VtVmFsdWUgPSBzdW1WYWx1ZSArIG51bTsKCSAgIHN1bXZhbHVlU3F1YXJlID0gcG93IChzd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pYXRpb24KLy81LiBEZWNsYXJlIHZhcmlhYmxlIGZvciB0d28gdG90YWwgc3Vtczogc3VtIG9mIHZhbHVlcyBhbmQgc3VtIG9mIGVhY2ggdmFsdWUgCi8vICAgc3F1YXJlZAovLzYuIFJlYWQgdGhlIHZhbHVlcyBmcm9tIHRoZSBmaWxlIG9uZSBhdCBhIHRpbWUsIGFuZCB1cGRhdGUgZWFjaCBvZiB0aGUgMiAKLy8gICAgIHRvdGFscwovLzcuIHVzZSBib3RoIHRvdGFscyB0byBjYWxjdWxhdGUgdGhlIHZhcmlhbmNlCi8vOC4gVXNlIHRoZSBmaXJzdCB0b3RhbCAoc3VtIG9mIHZhbHVlcykgdG8gY2FsY3VsYXRlIHRoZSBtZWFuIChtZWFuID0gdG90YWwKLy8gICAgLyBudW1iZXIgb2YgdmFsdWVzKQovLzkuIERpc3BsYXkgdGhlIHZhcmlhbmNlLCBzdGFuZGFyZCBkZXZpYXRpb24gYW5kIG1lYW4KCi8vIFRoZSB0ZWFjaGVyIGFsc28gbWVudGlvbmVkIHVzaW5nIGdldGxpbmUgaW4gdGhlIGNsYXNzIHRoYXQgZGF5LCBidXQgc2hlCi8vIGRpZCBub3Qgc3BlY2lmaWNhbGx5IHNheSB0aGF0IHNoZSB3YW50ZWQgaXQgb24gdGhlIHByb2dyYW0sIGJ1dCB0aGVyZSBjb3VsZAovLyBiZSBhIGNoYW5jZS4KfQ==
compilation info
prog.cpp: In function 'int main()':
prog.cpp:8:2: error: expected unqualified-id before 'double'
double variance,
^
prog.cpp:15:11: error: aggregate 'std::ifstream myFile' has incomplete type and cannot be defined
ifstream myFile;
^
prog.cpp:19:20: error: 'num' was not declared in this scope
while ( myFile >> num )
^
prog.cpp:21:5: error: 'sumValue' was not declared in this scope
sumValue = sumValue + num;
^
prog.cpp:22:5: error: 'sumvalueSquare' was not declared in this scope
sumvalueSquare = pow (sumValue, 2.0);
^
prog.cpp:22:40: error: 'pow' was not declared in this scope
sumvalueSquare = pow (sumValue, 2.0);
^
prog.cpp:23:5: error: 'variance' was not declared in this scope
variance = pow (sumValue, 2.0) - (pow (sumValue, 2.0) / numValue) / (numValue - 1);
^
prog.cpp:24:5: error: 'standDeviation' was not declared in this scope
standDeviation = sqrt (variance);
^
prog.cpp:24:36: error: 'sqrt' was not declared in this scope
standDeviation = sqrt (variance);
^
prog.cpp:25:5: error: 'mean' was not declared in this scope
mean = sumValue / numValue;
^
prog.cpp: At global scope:
prog.cpp:34:2: error: expected unqualified-id before 'return'
return 0;
^
prog.cpp:56:1: error: expected declaration before '}' token
}
^
stdout