Advertisement
Guest User

Untitled

a guest
Mar 26th, 2017
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.52 KB | None | 0 0
  1. #include <iostream>
  2. #include <array>
  3. #include <bits/stdc++.h>
  4. using namespace std;;
  5.  
  6. int SIZE;
  7. struct Record {
  8.   int min;
  9.   int max;
  10.   int mode;
  11.   int freq = 0;
  12.   float mean;
  13.   int total;
  14. };
  15. Record player;
  16.  
  17.  
  18.  
  19. void setMinMax(int touchYear[]) {
  20.   player.min = touchYear[0];
  21.   player.max = touchYear[0];
  22.   for (int x = 0; x < SIZE; x++) {
  23.     if (touchYear[x] < player.min) {
  24.       player.min = touchYear[x];
  25.     }
  26.    
  27.     if (touchYear[x] > player.max) {
  28.       player.max = touchYear[x];
  29.     }
  30.   }
  31.   cout << "Player Min:\t" << player.min <<endl;
  32.   cout << "Player Max:\t" << player.max <<endl;
  33. }
  34.  
  35. void setMode(int touchYear[]) {
  36.   int freq = 1;
  37.   int mode = touchYear[0];
  38.   sort(touchYear, touchYear + SIZE);
  39.   for(int y = 0; y < SIZE; y++) {
  40.     if(freq > player.freq){
  41.       player.freq = freq;
  42.       player.mode = touchYear[y];
  43.     }
  44.    
  45.     if(touchYear[y + 1] == touchYear[y]) {
  46.       freq++;
  47.     }
  48.    
  49.     else {
  50.       freq = 1;
  51.     }
  52.   }
  53.   cout << "Player Mode:\t" << player.mode << endl;
  54.   cout << "Player Freq:\t" << player.freq << endl;
  55. }
  56.  
  57. void setTotal(int touchYear[]) {
  58.   for(int x = 0; x < SIZE; x++) {
  59.     player.total += touchYear[x];
  60.   }
  61.   player.mean = (float)player.total/(float)SIZE;
  62.   cout << "Player Mean:\t" << player.mean << endl;
  63.   cout << "Player Total:\t" << player.total << endl;
  64. }
  65.  
  66. int main() {
  67.   cout << "How many years of data do you need to enter?" << endl;
  68.   cin >> SIZE;
  69.   int tdRec[SIZE];
  70.   int count = 0;
  71.   while(count < SIZE) {
  72.     cout << "Please enter in touchdown count for year " << count + 1 << ":\t";
  73.     cin >> tdRec[count];
  74.     cout << endl;
  75.     count++;
  76.   } //Collects Touchdown Data from User
  77.  
  78.   cout << "Your Touchdown list: ";
  79.   for (int m = 0; m < SIZE; m++) {
  80.     cout << tdRec[m] << " ";
  81.   } //Prints Touchdown list
  82.   cout <<"\n------------------------------------------------" << endl;
  83.  
  84.   setMinMax(tdRec);
  85.   setMode(tdRec);
  86.   setTotal(tdRec);
  87.   return 0;
  88. }
  89.  
  90. /*
  91. input
  92. clear
  93. gcc version 4.6.3
  94.    
  95. How many years of data do you need to enter?
  96.  6
  97. Please enter in touchdown count for year 1:  5
  98.  
  99. Please enter in touchdown count for year 2:  5
  100.  
  101. Please enter in touchdown count for year 3:  5
  102.  
  103. Please enter in touchdown count for year 4:  7
  104.  
  105. Please enter in touchdown count for year 5:  8
  106.  
  107. Please enter in touchdown count for year 6:  9
  108.  
  109. Your Touchdown list: 5 5 5 7 8 9
  110. ------------------------------------------------
  111. Player Min: 5
  112. Player Max: 9
  113. Player Mode:    5
  114. Player Freq:    3
  115. Player Mean:    6.5
  116. Player Total:   39
  117. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement