Advertisement
Guest User

Untitled

a guest
Oct 20th, 2017
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.64 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int main ()
  6. {
  7. int my_size = 0, total = 0, temp = 0, middle = 0;
  8.  
  9. int *my_size2;
  10.  
  11. cout << "How many students were surveyed about how many movies they see in a month?" << endl;
  12.  
  13. cin >> my_size;
  14.  
  15. cout << endl;
  16.  
  17. my_size2 = new int[my_size];
  18.  
  19. for (int i = 0; i < my_size; i++)
  20. {
  21. cin >> my_size2[i];
  22. }
  23.  
  24. for (int j = 0; j < my_size; j++)
  25. {
  26. total += my_size2[j];
  27. }
  28.  
  29. cout << endl << "Average is " << total / my_size;
  30.  
  31. cout << endl << endl;
  32.  
  33. for (int i = 0; i < my_size; i++)
  34. {
  35. for (int k = 0; k < my_size; k++)
  36. {
  37. if(my_size2[k] < my_size2[i])
  38. {
  39. temp = my_size2[i];
  40. my_size2[i] = my_size2[k];
  41. my_size2[k] = temp;
  42. }
  43. }
  44. }
  45.  
  46. cout << "Median is ";
  47.  
  48. if (my_size % 2 == 1)
  49. {
  50. cout << my_size2[my_size/2];
  51. }
  52. else if (my_size % 2 == 0)
  53. {
  54. cout << my_size2[my_size/2] + my_size2[(my_size/2)-1];
  55. }
  56.  
  57. cout << endl << endl;
  58.  
  59. int my_num = my_size2[0];
  60. int mode = my_num;
  61. int my_count = 1;
  62. int count_mode = 1;
  63.  
  64. for (int f = 0; f < my_size; f++)
  65. {
  66. if (my_size2[f] == my_num)
  67. {
  68. my_count++;
  69. }
  70. else
  71. {
  72. if (my_count > count_mode)
  73. {
  74. count_mode = my_count;
  75. count_mode = my_num;
  76. }
  77. my_count = 1;
  78. my_num = my_size2[f];
  79. }
  80. }
  81.  
  82. cout << endl << endl << mode;
  83.  
  84. return 0;
  85. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement