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

PLz make sure the program run Each runner is assigned a score equal to their fin

ID: 3669752 • Letter: P

Question

PLz make sure the program run

Each runner is assigned a score equal to their finishing place. In the example above team Z's runners achieved scores of 1,2 and 4. Team A's runners scores were 3,5, and 6 respectively. The team's score is the sum of the members score divided by the number of people on the team. So team A's score is (3+5+6)/3 = 14/3=4.66 and team Z's score is (1+2+4)73=7/3=2.33 Write a program to score races as described above. Your program will ask the user to input a string of uppercase characters indicating the outcome of a race. Your program will output: The number of teams. The number of runners on a team. The names of the teams - in alphabetical order - together with the team score. The name and score of the winning team. So for the example above the program will print: The winning team is team Z with a score of 2.33. Your program should loop asking for input processing the data until the user enters "done". Your program should detect the error condition where teams do not have the same number of runners. In that case it should print an error message, and resume by requesting the next input.

Explanation / Answer

#include <iostream>
#include <string>
#include <ctype.h>

using namespace std;
string input;
int NumOfLetters;

void findWinner(double score[],int size,char team[]){
   double min=score[0];
   int winningTeam=0;
   for(int i=0;i<size;i++)
       if(min>score[i]){
       min=score[i];
       winningTeam=i;
       }
cout<<"The winning team is team "<<team[winningTeam]<<" with a score of "<<min<<". ";

}


void Sort(char *array, int size){ //bubble sort
char temp;
   for(int i=0;i<size;i++)
       for(int j=0;j<size-1;j++)
           if(array[j]>array[i]){
           temp = array[i];
           array[i]=array[j];
           array[j]=temp;
           }

}


//check if everything is uppercase;
bool checkUpper(string input){
for(int i=0;i<input.length();i++)
   if(!isupper(input[i])) return false;
return true;
}

//check to see if there are the same number of runners for each team;
//It does the checking and everything else!
bool checkTeam(string input){
char* Letters= new char[input.length()]();//worst case, all letters are used once;
NumOfLetters=0;

bool flag=true;
for(int i=0; i<input.length();i++){   //get same letters once to an array;
   for(int j=0;j<NumOfLetters;j++){
       if(Letters[j]==input[i]){
       flag=false;
       break;
       }
       else flag=true;
   }
if(flag){
   Letters[NumOfLetters]=input[i];
   NumOfLetters++;
}

}

int *CountLetters= new int[NumOfLetters]();
double *Scores=new double[NumOfLetters]();

for(int i=0; i<NumOfLetters;i++){
   for(int j=0;j<input.length();j++)
       if(Letters[i]==input[j])CountLetters[i]++;
}

for(int i=0; i<NumOfLetters;i++){   //check to see if there are equal number of letters;
   if(CountLetters[i]!=CountLetters[0]){
       delete[] Scores;
       delete[] Letters;
       delete[] CountLetters;
       return false;
   }
}
Sort(Letters,NumOfLetters);

for(int i=0;i<input.length();i++)
   for(int j=0;j<NumOfLetters;j++)
       if(input[i]==Letters[j])Scores[j]+=i+1;

cout<<" There are "<<NumOfLetters<<" teams. ";
cout<<"Each team has "<<CountLetters[0]<<" runners. ";
cout<<"Team   Score ";
for(int i=0;i<NumOfLetters;i++)
   cout<<Letters[i]<<"   "<<(Scores[i]=Scores[i]/CountLetters[0])<<endl;

findWinner(Scores,NumOfLetters,Letters);

delete[] Scores;
delete[] Letters;
delete[] CountLetters;
return true;
}

int main(){
while(true){
cout<<" Enter a string of uppercase characters to indicate places(enter done to terminate):";
cin>>input;
if(input=="done") break;
if(!checkUpper(input)){
cout<<"Uppercase letters ONLY! try again. ";
continue;
}
if(!checkTeam(input)){   //checks and do all the rest;
cout<<"Each team must have the same number of runners! try again. ";
}

}//while
return 0;
}

OUTPUT

Enter a string of uppercase characters to indicate places(enter done to terminate):A                                                                        
                                                                                                                                                            
There are 1 teams.                                                                                                                                          
                                                                                                                                                            
Each team has 1 runners.                                                                                                                                    
                                                                                                                                                            
Team    Score                                                                                                                                               
A       1                                                                                                                                                   
The winning team is team A with a score of 1.                                                                                                               

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote