Question: Can someone explain what part of the code does what? #include #include #include #include using namespace std; //define a structure for team struct team{ //fields

Can someone explain what part of the code does what?

#include #include #include #include using namespace std;

//define a structure for team struct team{

//fields of a team string name; float scores[11]; float mean; float median; };

int main(){ string filepath = "";

cout<<"Enter the filepath ";

//read file location from user getline(cin, filepath);

// opening data file fstream fp; fp.open(filepath);

//if file has opened successfully if(fp.is_open()){ //declare array of team objects team tm[1000];

//Read the records string temp; int k = 0, team_count = 0; while(getline(fp, temp)){ //cout<

//assign the team name to teh team object tm[team_count].name = temp; k = 1; }

else if(k == 1){

int l = 0; //extract team scores

char* line = new char[temp.length() + 1];

copy(temp.begin(), temp.end(), line);

//splitting the line about spaces char *tk = strtok(line, " ");

//keep on extracting the space seperated values from the line while (tk != NULL) { tm[team_count].scores[l] = atof(tk); tk = strtok(NULL, " "); l++; }

//displaying the team name alongwith scores cout<< tm[team_count].name<

for(int i = 0; i < 11; i++){ cout<< tm[team_count].scores[i]<<" "; }

cout<

//sorting the team scores sort(tm[team_count].scores, tm[team_count].scores + 11);

//calculating the average and median float sum = 0; for(int i = 1; i < 10; i++){ sum += tm[team_count].scores[i]; } //average of qualifying scores tm[team_count].mean = sum / 9; //Median tm[team_count].median = tm[team_count].scores[5];

cout<<"average score: "<

//displaying team count cout<<" Total teams: "<

//determining the winning team string name; float median = INT_MIN, mean = INT_MIN; for(int i = 0; i < team_count; i++){ if(tm[i].mean > mean){ mean = tm[i].mean; median = tm[i].median; name = tm[i].name; }

else if(tm[i].mean == mean && tm[i].median > median){ median = tm[i].median; name = tm[i].name; } }

//check if the winning team has won by breaking the tie int flag = 0; for(int i = 0; i < team_count; i++){

//yes we foun it! if(mean == tm[i].mean && median > tm[i].median) flag = 1; }

cout<<"Winning team: "<

//if team has won by breaking the ties if(flag == 1){ cout<<"This team has won by breaking the ties with median value: "<

return 0; }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!