Advertisement
Guest User

Untitled

a guest
Mar 26th, 2017
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.07 KB | None | 0 0
  1. //struct QB TD counter.
  2. #include <iostream>
  3. //#include <vector>
  4. using namespace std;
  5.  
  6. struct ModeStruct
  7. {
  8. int mode;
  9. int modeFreq;
  10.  
  11. };
  12.  
  13. struct Playerdata
  14. {
  15.  
  16. int touchDowns;
  17. //int total;
  18.  
  19. };
  20.  
  21. ModeStruct GetMode(Playerdata daArray[], int iSize);
  22. /*void printStruct(Playerdata info)
  23. {
  24. cout << info.playerName << "\t" << info.touchDowns << "\t " << endl;
  25.  
  26. }
  27. */
  28.  
  29. int main()
  30. {
  31.  
  32. string playerName;
  33. int years;
  34.  
  35. //vector <Playerdata> touchDowns;
  36. double total = 0;
  37. double average = 0;
  38. int highest = 0;
  39. int lowest;
  40.  
  41. cout << "Enter a QB name: " << endl;
  42. getline(cin, playerName);
  43. cout << playerName;
  44.  
  45. cout << "How many years for Touch Down Totals: " << endl;
  46. cin >> years;
  47.  
  48. Playerdata tds_ea_year[years];
  49.  
  50.  
  51.  
  52.  
  53. for (int val = 0; val < years; val++)
  54. {
  55. cout << "Enter the total TD's for year #" << (val + 1) << ": " << endl;
  56. cin >> tds_ea_year[val].touchDowns;
  57.  
  58. lowest = tds_ea_year[0].touchDowns;
  59. total += tds_ea_year[val].touchDowns;
  60.  
  61. if (tds_ea_year[val].touchDowns > highest) highest = tds_ea_year[val].touchDowns;
  62.  
  63. if (tds_ea_year[val].touchDowns < lowest) lowest = tds_ea_year[val].touchDowns;
  64. }
  65.  
  66. cout << "Here's the contents of the array: " << endl;
  67. for (int val = 0; val < years; val++)
  68. {
  69. cout << "year #: " << (val + 1) << "\t"<< tds_ea_year[val].touchDowns << endl;
  70. }
  71. average = total / years;
  72. ModeStruct finalMode;
  73.  
  74. finalMode = GetMode(tds_ea_year, years);
  75.  
  76.  
  77.  
  78. cout << "The Total is: " << total << endl;
  79. cout << "The mean is: " <<average << endl;
  80. if (finalMode.modeFreq < 1)
  81. cout << "No mode..." << endl;
  82. else
  83. cout << "The mode is: " << finalMode.mode << " and the frequency is: " << finalMode.modeFreq << endl;
  84. cout << "The Maximum value is: " << highest << endl;
  85. cout << "The Minimum value is: " << lowest << endl;
  86.  
  87.  
  88.  
  89.  
  90.  
  91.  
  92.  
  93. // printStruct(tdsPerYear);
  94. }
  95. ModeStruct GetMode(Playerdata daArray[], int iSize) {
  96. // Allocate an int array of the same size to hold the
  97. // repetition count
  98. ModeStruct currentMode;
  99. int frequency;
  100.  
  101. int* ipRepetition = new int[iSize];
  102. for (int i = 0; i < iSize; ++i) {
  103. ipRepetition[i] = 0;
  104. int j = 0;
  105. bool bFound = false;
  106. while ((j < i) && (daArray[i].touchDowns != daArray[j].touchDowns)) {
  107. if (daArray[i].touchDowns != daArray[j].touchDowns) {
  108. ++j;
  109. }
  110. }
  111. ++(ipRepetition[j]);
  112. }
  113. int iMaxRepeat = 0;
  114.  
  115.  
  116.  
  117.  
  118. for (int i = 1; i < iSize; ++i) {
  119. if (ipRepetition[i] > ipRepetition[iMaxRepeat]) {
  120. iMaxRepeat = i;
  121. frequency++;
  122. }
  123. }
  124.  
  125. currentMode.modeFreq = ipRepetition[iMaxRepeat];
  126. currentMode.mode = daArray[iMaxRepeat].touchDowns;
  127. delete [] ipRepetition;
  128.  
  129.  
  130.  
  131.  
  132.  
  133.  
  134.  
  135.  
  136.  
  137. return currentMode;
  138.  
  139. }
  140. /*
  141. gcc version 4.6.3
  142.  
  143. Enter a QB name:
  144. Dave
  145. DaveHow many years for Touch Down Totals:
  146. 15
  147. Enter the total TD's for year #1:
  148. 22
  149. Enter the total TD's for year #2:
  150. 23
  151. Enter the total TD's for year #3:
  152. 22
  153. Enter the total TD's for year #4:
  154. 25
  155. Enter the total TD's for year #5:
  156. 26
  157. Enter the total TD's for year #6:
  158. 27
  159. Enter the total TD's for year #7:
  160. 26
  161. Enter the total TD's for year #8:
  162. 19
  163. Enter the total TD's for year #9:
  164. 18
  165. Enter the total TD's for year #10:
  166. 17
  167. Enter the total TD's for year #11:
  168. 16
  169. Enter the total TD's for year #12:
  170. 22
  171. Enter the total TD's for year #13:
  172. 22
  173. Enter the total TD's for year #14:
  174. 22
  175. Enter the total TD's for year #15:
  176. 22
  177. Here's the contents of the array:
  178. year #: 1 22
  179. year #: 2 23
  180. year #: 3 22
  181. year #: 4 25
  182. year #: 5 26
  183. year #: 6 27
  184. year #: 7 26
  185. year #: 8 19
  186. year #: 9 18
  187. year #: 10 17
  188. year #: 11 16
  189. year #: 12 22
  190. year #: 13 22
  191. year #: 14 22
  192. year #: 15 22
  193. The Total is: 329
  194. The mean is: 21.9333
  195. The mode is: 22 and the frequency is: 6
  196. The Maximum value is: 27
  197. The Minimum value is: 22
  198. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement