Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

NEED IN C++ AND IN FUNCTIONS 2. (Video Game Player Program) : Determine the aver

ID: 3568840 • Letter: N

Question

NEED IN C++ AND IN FUNCTIONS

2. (Video Game Player Program): Determine the average score for a group of players and then determine who scored below average. Write your program to do the following:

In main, declare a PlayerName Array and a Score Array. Declare the size of the arrays to be 100.

In the InputData function, input the player name and score into the arrays for an unknown number of players up to 100.

In the DisplayPlayerData function, display the name and score of each player.

In the CalculateAverageScore function, calculate the average score and return it by value.

In the DisplayBelowAverage function, display the name and score for any player who scored below the average. Do not use global variables.

Output from Program:

Enter Player Name (Q to quit): Bob

Enter score for Bob: 3245

Enter Player Name (Q to quit): Sue

Enter score for Sue: 1098

Enter Player Name (Q to quit): Dave

Enter score for Dave: 8219

Enter Player Name (Q to quit): Pat

Enter score for Pat: 3217

Enter Player Name (Q to quit): Q

Name   Score

Bob        3245

Sue        1098

Dave       8219

Pat        3217

Average Score: 3944.75

Players who scored below average

Name    Score

Bob        3245

Sue        1098

Pat        3217

Press any key to continue . . .

Explanation / Answer

#include<iostream>

using namespace std;

int inputData(string playerNameArray[], int scoreArray[]){
int count = 0;
while(1){
cout << "Enter Player Name(Q to quit): ";
cin >> playerNameArray[count];
if(playerNameArray[count].compare("Q") == 0){
return count;
}
cout << "Enter score for " << playerNameArray[count] << ": ";
cin >> scoreArray[count];
count++;
}
}

void displayPlayerData(string playerNameArray[], int scoreArray[], int count){
cout << "Name Score ";
for(int i=0; i<count; i++){
cout << playerNameArray[i] << " " << scoreArray[i] << endl;
}
}

double calculateAverageScore(int scoreArray[], int count){
int sum = 0;
for(int i=0; i<count; i++){
sum += scoreArray[i];
}
return ((double)sum/count);
}

void displayBelowAverage(string playerNameArray[], int scoreArray[], int count, double average){
cout << "Players who scored below average ";
cout << "Name Score ";
for(int i=0; i<count; i++){
if(scoreArray[i] < average){
cout << playerNameArray[i] << " " << scoreArray[i] << endl;
}
}
}

int main(){
string playerNameArray[100];
int scoreArray[100];
int count = inputData(playerNameArray, scoreArray);
displayPlayerData(playerNameArray, scoreArray, count);
double average = calculateAverageScore(scoreArray, count);
cout << "Average Score: " << average << endl;
displayBelowAverage(playerNameArray, scoreArray, count, average);
return 0;
}