Advertisement
Guest User

Untitled

a guest
Feb 20th, 2012
1,780
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.00 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <algorithm>
  4. #include <map>
  5. using namespace std;
  6.  
  7. int main()
  8. {
  9. //unsigned c = 0;
  10. //int n = 0;
  11.  
  12. ////while( (cin >> n).good() )
  13. //while( cin >> n )
  14. //{
  15. // ++c;
  16. //}
  17.  
  18. //cout << "You entered: " << c << " integers." << endl;
  19.  
  20. // load a vector of integers from the console.
  21. vector<int> v;
  22.  
  23. int n;
  24. while( cin >> n )
  25. v.push_back( n );
  26.  
  27. cout << "You entered: " << v.size() << " integers" << endl;
  28.  
  29. sort(v.begin(), v.end());
  30. vector<int>::iterator vMin, vMax;
  31.  
  32. vMin = v.begin();
  33. cout << "The minumum value in the vector is: " << *vMin << endl;
  34.  
  35. vMax = v.end() - 1;
  36. cout << "The maximum value in the vector is: " << *vMax << endl;
  37.  
  38.  
  39. double median;
  40.  
  41. if (v.size() % 2 == 0)
  42. {
  43. median = (v[(int)(v.size()/2.0-1)] + v[(int)(v.size()/2.0)])/2.0;
  44. }
  45.  
  46. else
  47. {
  48. median = v[v.size() / 2];
  49. }
  50.  
  51. cout << "The median of the vector is: " << median << endl;
  52.  
  53.  
  54. //Find the Mean
  55. double sum = 0;
  56. double mean;
  57. for(size_t i = 0; i < v.size(); ++i)
  58. sum += v[i];
  59. mean = (double)sum / v.size();
  60. cout << "The arithmetic mean is: " << mean << endl;
  61.  
  62. sum = 0;
  63. double variance;
  64. for(size_t i=0; i < v.size(); ++i)
  65. sum += pow (v[i] - mean,2);
  66. variance = sum / (double) v.size();
  67. cout << "The variance of the vector is: " << variance << endl;
  68.  
  69. double standardD = sqrt(variance);
  70. cout << "The standard deviation of the vector: " << standardD << endl;
  71.  
  72. map<int,unsigned> frequencyCount;
  73. //This is my attempt to increment the values of the map everytime one of the same numebers
  74. for(size_t i = 0; i < v.size(); ++i)
  75. frequencyCount[v[i]]++;
  76.  
  77. unsigned currentMax = 0;
  78. unsigned checked = 0;
  79. unsigned maax = 0;
  80. for(auto it = frequencyCount.cbegin();
  81. it != frequencyCount.cend(); ++it )
  82. //checked = it->second;
  83.  
  84. if (it ->second > currentMax)
  85. {
  86. maax = it->first;
  87. }
  88. //if(it ->second > currentMax){
  89. //v = it->first
  90.  
  91. cout << " The highest value within the map is: " << maax << endl;
  92. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement