fork download
  1. #include <iostream>
  2. #include <cmath>
  3. #include <fstream>
  4. #include <iomanip>
  5. using namespace std;
  6.  
  7. const int MAXSIZE = 1000;
  8.  
  9.  
  10.  
  11.  
  12. /**
  13. * computes the maximum and minimum values in the data set
  14. * @param data - an array containing the measurements
  15. * @param count - the number of measurements
  16. * @param min - the minimum measurement
  17. * @param max - the maximum measurement
  18. */
  19.  
  20. void minMax(const double data [ ], int count, double& min, double& max)
  21. {
  22. min = data[0];
  23. for(count = 0; count<MAXSIZE;)
  24. {
  25. count++;
  26. }
  27. if (data[count] < min)
  28. {
  29. min = data[count];
  30. }
  31. max = data[0];
  32. for(count=0; count<MAXSIZE;)
  33. {
  34. count++;
  35. }
  36. if(data[count] > max)
  37. {
  38. max = data[count];
  39. }
  40. double range = max - min;
  41. cout<<"Min: " <<setprecision(4)<<setw(20)<<min;
  42. cout<<"Max: " <<setprecision(4)<<setw(20)<<max;
  43. cout<<"range: " <<setprecision(4)<<setw(18)<<range;
  44. /**
  45. * computes the sample mean
  46. * @param data - an array containing the measurements
  47. * @param count - the number of measurements
  48. * @return the mean of the set of measurements
  49. */
  50.  
  51. double calcMean(const double data[ ], int count)
  52. {
  53. double sum = 0;
  54. double mean;
  55. int i;
  56. for(i = 0; i < count; i++);
  57. {
  58. sum += data[i];
  59. mean = sum/count;
  60. }
  61. return mean;
  62. }
  63. /**
  64. * computes the sample variance
  65. * @param data - an array containing the measurements
  66. * @param count - the number of measurements
  67. * @return the sample variance of the set of measurements
  68. */
  69.  
  70. double calcVariance(const double data[ ], int count)
  71. {
  72. double sum = 0;
  73. double var = 0;
  74. double mean;
  75. int i;
  76. for(i = 0; i < count; i++);
  77. {
  78. sum += data[i];
  79. mean = sum/count;
  80. var = pow(data[i]-mean,2);
  81. }
  82. return var;
  83. }
  84.  
  85. int main()
  86. {
  87. double data[MAXSIZE];
  88. double range, mean, variance, stand_dev;
  89. string file;
  90. int count;
  91. cout<<"Enter the name of the data file>"<<endl;
  92. cin>>file;
  93. cout<<endl;
  94. cout<<"Descriptive Statistics"<<endl;
  95. cout<<"------------------------------"<<endl;
  96.  
  97.  
  98. ifstream inputFile;
  99. inputFile.open("sewage.data");
  100. if(!inputFile)
  101. {
  102. cout<<"error opening File."<<endl;
  103. }
  104. while(count = 0,count < MAXSIZE && inputFile >> data[count])
  105. {
  106. count++;
  107. }
  108. cout<<"N: "<<setw(22);
  109. cin>>count;
  110. minMax(data, count, min, max);
  111. cout<<"range: " <<setprecision(4)<<setw(18);
  112. mean = calcMean(data, count);
  113. cout<<"mean:"<<setprecision(4)<<setw<<(19)<<mean<<endl;
  114. variance = calcVariance(data, count);
  115. cout<<"variance:"<<setw(15)<<setprecision<<(4)<<variance<<endl;
  116. stand_dev = sqrt(variance);
  117. cout<<"Standard Deviation: "<<setw(6)<<setprecision(4)<<stand_dev<<endl;
  118. inputFile.close();
  119. return 0;
  120. }
  121.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp: In function ‘void minMax(const double*, int, double&, double&)’:
prog.cpp:52:4: error: a function-definition is not allowed here before ‘{’ token
    {
    ^
prog.cpp:120:1: error: expected ‘}’ at end of input
 }
 ^
stdout
Standard output is empty