1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92
|
// William_wk5_iLab.cpp : main project file.
#include "stdafx.h"
#include "iostream"
#include "string"
#include "iomanip"
using namespace std;
int InputData(string playerName[], double score[], int &index, int &scoreCount, int ARRAYSIZE);
void DisplayPlayerData(string playerName[], double score[], int &index, int scoreCount, double avgScore);
double CalculateAverageScore(double score[], int &index, int scoreCount);
void DisplayBelowAverage(string playerName[], double score[], int &index, int scoreCount, double avgScore);
int main(array<System::String ^> ^args)
{
const int ARRAYSIZE = 100;
int scoreCount, index = 0;
string playerName[ARRAYSIZE];
double score[ARRAYSIZE], avgScore;
cout << fixed << setprecision(2);
while (1)
{
InputData(playerName, score, index, scoreCount, ARRAYSIZE);
if (playerName[index] == "q" || playerName[index] == "Q")
break;
}
avgScore = CalculateAverageScore(score, index, scoreCount);
DisplayPlayerData(playerName, score, index, scoreCount, avgScore);
DisplayBelowAverage(playerName, score, index, scoreCount, avgScore);
system("pause");
return 0;
}
int InputData(string playerName[], double score[], int &index, int &scoreCount, int ARRAYSIZE)
{
while (index < ARRAYSIZE)
{
cout << "\n\nEnter Player Name (Q to quit): ";
cin >> playerName[index];
if (playerName[index] == "q" || playerName[index] == "Q")
break;
cout << "\nEnter score for " << playerName[index] << ": ";
cin >> score[index];
index++;
scoreCount++;
}
return 0;
}
double CalculateAverageScore(double score[], int &index, int scoreCount)
{
double avg = 0, total = 0;
for (index = 0; index < scoreCount; index++)
{
total = total + score[index];
}
avg = total / scoreCount;
return avg;
}
void DisplayPlayerData(string playerName[], double score[], int &index, int scoreCount, double avgScore)
{
cout << " Name Score\n";
for (index = 0; index < scoreCount; index++)
cout << playerName[index] << setw(19) << score[index] << endl;
cout << "\n\nAverage Score: " << avgScore << endl;
}
void DisplayBelowAverage(string playerName[], double score[], int &index, int scoreCount, double avgScore)
{
cout << "\nPlayers who scored below average are:\n\n"
<< " Name Score\n";
for (index = 0; index < scoreCount; index++)
{
if (score[index] < avgScore)
cout << playerName[index] << setw(19) << score[index] << endl;
}
}
|