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

I\'m having problems with finishing the code we started in class. I\'m not a CS

ID: 3699035 • Letter: I

Question

I'm having problems with finishing the code we started in class. I'm not a CS major, so I'm too invested in expending a lot of time to finish this up. Any help will be appreciated.

#include <iostream>
#include <fstream>

using namespace std;

const int NUM_PLAYERS = 25;
const int MAX_COLS = 6; // Number of categories in players statistics

void get_average(int [][MAX_COLS], int, int [], int );
void get_min_index(int [][MAX_COLS], int, int [], int );

int main()
{
int pscores[NUM_PLAYERS][MAX_COLS];
int avg[MAX_COLS]; // Array passed as argument to get_average. Avg values are stored in this array
int minim[MAX_COLS]; // Array passed as argument to get_min_index. Avg values are stored in this array
string pname[NUM_PLAYERS], temp;
int i, num, score, min_index;
int row, col;
ifstream infile;

infile.open("nbastats.txt");
if (!infile){
cout << "Invalid file name ";
return -1;
}
// Skip the header line
getline(infile, temp);

// Read the rest of the data and store them in the arrays
for (row = 0; row < NUM_PLAYERS; row++){ // ROW BY ROW
infile >> pname[row]; // First read the player name
// Now read the stats for the player read above
for (col = 0; col < MAX_COLS; col++){
infile >> pscores[row][col];
}
}

// call the functions to calculate average and min for each category
get_average(pscores, NUM_PLAYERS, avg, MAX_COLS );
get_min_index(pscores, NUM_PLAYERS, minim, MAX_COLS );

// Write the code to display the result


}

void get_average(int scores[][MAX_COLS], int s_size, int avg[], int a_size )
{
// This function should calculate the average of each category of players statistics
// Store the results in avg[]
// s_size contains the number of rows of scores[][]
// a_size is the size of avg[]
//write your code below


}


void get_min_index(int scores[][MAX_COLS], int s_size, int minimum[], int m_size )
{
// This function should find the index of the minimum value in each category of players statistics
// Store the results in minimum[]
// s_size contains the number of rows of scores[][]
// m_size is the size of avg[]
// Write you code below

}

Explanation / Answer

#include <iostream>

#include <fstream>

using namespace std;

const int NUM_PLAYERS = 25;

const int MAX_COLS = 6; // Number of categories in players statistics

void get_average(int [][MAX_COLS], int, int [], int );

void get_min_index(int [][MAX_COLS], int, int [], int );

int main()

{

int pscores[NUM_PLAYERS][MAX_COLS];

int avg[MAX_COLS]; // Array passed as argument to get_average. Avg values are stored in this array

int minim[MAX_COLS]; // Array passed as argument to get_min_index. Avg values are stored in this array

string pname[NUM_PLAYERS], temp;

int i, num, score, min_index;

int row, col;

ifstream infile;

infile.open("nbastats.txt");

if (!infile){

cout << "Invalid file name ";

return -1;

}

// Skip the header line

getline(infile, temp);

// Read the rest of the data and store them in the arrays

for (row = 0; row < NUM_PLAYERS; row++){ // ROW BY ROW

infile >> pname[row]; // First read the player name

// Now read the stats for the player read above

for (col = 0; col < MAX_COLS; col++){

infile >> pscores[row][col];

}

}

// call the functions to calculate average and min for each category

get_average(pscores, NUM_PLAYERS, avg, MAX_COLS );

get_min_index(pscores, NUM_PLAYERS, minim, MAX_COLS );

// Write the code to display the result

}

void get_average(int scores[][MAX_COLS], int s_size, int avg[], int a_size )

{

// This function should calculate the average of each category of players statistics

// Store the results in avg[]

// s_size contains the number of rows of scores[][]

// a_size is the size of avg[]

//write your code below

int i, j, avg;

for (i = 0; i < a_size; i++) {

avg_tmp = 0;

for (j = 0; j < s_size; j++)

avg_tmp += scores[j][i];

avg_tmp /= s_size;

avg[i] = avg_tmp;

}

}

void get_min_index(int scores[][MAX_COLS], int s_size, int minimum[], int m_size )

{

// This function should find the index of the minimum value in each category of players statistics

// Store the results in minimum[]

// s_size contains the number of rows of scores[][]

// m_size is the size of avg[]/ minimum[]

// Write you code below

int i, j;

for (i = 0; i < a_size; i++) {

minimum[i] = 0;

for (j = 1; j < s_size; j++)

if (scores[j][i] < scores[minimum[i]][i])

minimum[i] = j;

}

}

Hey champ!! I have edited 2 function. If you need any more help, please comment below

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