Advertisement
Guest User

Untitled

a guest
Feb 20th, 2017
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.33 KB | None | 0 0
  1. /*
  2.     Author: Jonathan Samaroo, Austin Janzs, Joseph Wolfman
  3.     Date:   20 February 2017
  4.  
  5.     Purpose:    OOP - Lab 4 - Arrays
  6. */
  7.  
  8. #include <iostream>
  9. #include "MyInputValidation.h"
  10. #include <string>
  11.  
  12.  
  13. using namespace std;
  14. using namespace myValidation;
  15.  
  16. template <int N>
  17. void GetScores (int bowlerScores[][N], const int NUM_BOWLERS,const int NUM_SCORES);
  18.  
  19. template <int N>
  20. void ReportScores(int bowlerScores[][N], const int NUM_BOWLERS, const int NUM_SCORES);
  21.  
  22. string BowlerName(int);
  23.  
  24. const int MIN_GRADE = 0.0;
  25. const int MAX_GRADE = 300.0;
  26. const int NUM_BOWLERS = 4;
  27. const int NUM_SCORES = 3;
  28.  
  29. int main()
  30. {
  31.     int bowlerScores[NUM_BOWLERS][NUM_SCORES]={0.0};
  32.  
  33.     GetScores(bowlerScores, NUM_BOWLERS, NUM_SCORES);
  34.     ReportScores(bowlerScores, NUM_BOWLERS, NUM_SCORES);
  35.  
  36.     system("pause");
  37.     return 0;
  38. }   //end of main
  39.  
  40. string BowlerName(int iIndex)
  41. {
  42.     const string aPlayerNames[NUM_BOWLERS] = {"Thom", "Kevin", "Bill", "Devi"};
  43.     return aPlayerNames[iIndex];
  44. }
  45.  
  46. template <int N>
  47. void GetScores(int bowlerScores[][N], const int NUM_BOWLERS, const int NUM_SCORES)
  48. {
  49.     for (int j=0; j < NUM_BOWLERS; j++)
  50.     {
  51.         cout << "\nPlease enter round score for " << BowlerName(j) << ": "<< endl;
  52.         for(int i=0; i < NUM_SCORES; i++)
  53.         {
  54.             cout << "\tScore " << i+1 <<": ";
  55.             bowlerScores[j][i] = GetValidInteger(MIN_GRADE,MAX_GRADE);
  56.         }
  57.     }
  58. }
  59. template <int N>
  60. void ReportScores(int bowlerScores[][N], const int NUM_BOWLERS, const int NUM_SCORES)
  61. {
  62.     double teamAverage = 0;
  63.    
  64.     for (int j=0; j < NUM_BOWLERS; j++)
  65.     {
  66.         double bowlerAverage = 0;
  67.         cout << "\nResults for " << BowlerName(j) << ": " << endl;
  68.         cout << "================";
  69.         cout << fixed << setprecision(1);
  70.  
  71.         for (int i=0; i<NUM_SCORES; i++)
  72.         {
  73.             bowlerAverage += bowlerScores[j][i];
  74.             cout << "\nGame " << i+1 << "\t" << bowlerScores[j][i];
  75.         }
  76.         teamAverage += bowlerAverage;
  77.         bowlerAverage = bowlerAverage / NUM_SCORES;
  78.         cout << "\nAverage Score for " << BowlerName(j) << ": " << bowlerAverage << endl;
  79.  
  80.     }
  81.     teamAverage = teamAverage / (NUM_SCORES*NUM_BOWLERS);
  82.     cout << "\n==========================\nAverage Team Score: " << teamAverage << endl;
  83.     cout << "==========================";
  84. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement