Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Author: Jonathan Samaroo, Austin Janzs, Joseph Wolfman
- Date: 20 February 2017
- Purpose: OOP - Lab 4 - Arrays
- */
- #include <iostream>
- #include "MyInputValidation.h"
- #include <string>
- using namespace std;
- using namespace myValidation;
- template <int N>
- void GetScores (int bowlerScores[][N], const int NUM_BOWLERS,const int NUM_SCORES);
- template <int N>
- void ReportScores(int bowlerScores[][N], const int NUM_BOWLERS, const int NUM_SCORES);
- string BowlerName(int);
- const int MIN_GRADE = 0.0;
- const int MAX_GRADE = 300.0;
- const int NUM_BOWLERS = 4;
- const int NUM_SCORES = 3;
- int main()
- {
- int bowlerScores[NUM_BOWLERS][NUM_SCORES]={0.0};
- GetScores(bowlerScores, NUM_BOWLERS, NUM_SCORES);
- ReportScores(bowlerScores, NUM_BOWLERS, NUM_SCORES);
- system("pause");
- return 0;
- } //end of main
- string BowlerName(int iIndex)
- {
- const string aPlayerNames[NUM_BOWLERS] = {"Thom", "Kevin", "Bill", "Devi"};
- return aPlayerNames[iIndex];
- }
- template <int N>
- void GetScores(int bowlerScores[][N], const int NUM_BOWLERS, const int NUM_SCORES)
- {
- for (int j=0; j < NUM_BOWLERS; j++)
- {
- cout << "\nPlease enter round score for " << BowlerName(j) << ": "<< endl;
- for(int i=0; i < NUM_SCORES; i++)
- {
- cout << "\tScore " << i+1 <<": ";
- bowlerScores[j][i] = GetValidInteger(MIN_GRADE,MAX_GRADE);
- }
- }
- }
- template <int N>
- void ReportScores(int bowlerScores[][N], const int NUM_BOWLERS, const int NUM_SCORES)
- {
- double teamAverage = 0;
- for (int j=0; j < NUM_BOWLERS; j++)
- {
- double bowlerAverage = 0;
- cout << "\nResults for " << BowlerName(j) << ": " << endl;
- cout << "================";
- cout << fixed << setprecision(1);
- for (int i=0; i<NUM_SCORES; i++)
- {
- bowlerAverage += bowlerScores[j][i];
- cout << "\nGame " << i+1 << "\t" << bowlerScores[j][i];
- }
- teamAverage += bowlerAverage;
- bowlerAverage = bowlerAverage / NUM_SCORES;
- cout << "\nAverage Score for " << BowlerName(j) << ": " << bowlerAverage << endl;
- }
- teamAverage = teamAverage / (NUM_SCORES*NUM_BOWLERS);
- cout << "\n==========================\nAverage Team Score: " << teamAverage << endl;
- cout << "==========================";
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement