fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4.  
  5. int main() {
  6.  
  7. int numValue = 1,
  8. double variance,
  9. mean,
  10. standDeviation,
  11. num,
  12. sumvalueSquare,
  13. sumValue;
  14.  
  15. ifstream myFile;
  16. myFile. open ("statsFile.txt");
  17.  
  18.  
  19. while ( myFile >> num )
  20. {
  21. sumValue = sumValue + num;
  22. sumvalueSquare = pow (sumValue, 2.0);
  23. variance = pow (sumValue, 2.0) - (pow (sumValue, 2.0) / numValue) / (numValue - 1);
  24. standDeviation = sqrt (variance);
  25. mean = sumValue / numValue;
  26. cout << num << endl << cout << "The variance is :" << variance << endl
  27. << "The standard deviation is:" << standDeviation << endl
  28. << "The mean is:" << mean << endl;
  29.  
  30. }
  31.  
  32. myFile. close ();
  33. }
  34. return 0;
  35.  
  36. //SPEC SHEET:
  37. //1. Declare a variable to hold a counter (that will count the number of
  38. // values read from the file)
  39. //2. (NO stop value is needed. The loop stops when all values have been read
  40. // from the file)
  41. //3. Declare one variable to be used (And re-used) for the reading of each
  42. // value from the file.
  43. //4. Declare variables for the variance, the mean, and the standard deviation
  44. //5. Declare variable for two total sums: sum of values and sum of each value
  45. // squared
  46. //6. Read the values from the file one at a time, and update each of the 2
  47. // totals
  48. //7. use both totals to calculate the variance
  49. //8. Use the first total (sum of values) to calculate the mean (mean = total
  50. // / number of values)
  51. //9. Display the variance, standard deviation and mean
  52.  
  53. // The teacher also mentioned using getline in the class that day, but she
  54. // did not specifically say that she wanted it on the program, but there could
  55. // be a chance.
  56. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
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
Standard output is empty