Function -> void inputScores(string[], double[][5]); This function populates an
ID: 656085 • Letter: F
Question
Function -> void inputScores(string[], double[][5]);
This function populates an array of strings with the names in the file.
This function populates a 2D array of doubles with the 5 scores associated with each name.
Function -> void computeAverage(double[][5], double&);
Function -> void computeLetterGrade(double, char&);
Function -> void printGrades(double[][5], string[], double, char);
printGrades should call computeAverage and computeLetterGrade.
The function prototypes using void return type are only suggestions.
There are always different ways to create a program.
You may change the function behavior if necessary or expedient to do so
student data
Explanation / Answer
Function declare like below
const size_t SCORE_NUM = 5;
const size_t STUDENT_NUM = 100;
size_t inputScores( std::ifstream &, std::string[], double[][SCORE_NUM], size_t );
double computeAverage( const double[], size_t );
char computeLetterGrade( double );
void printGrades( const std::string[], const double[][SCORE_NUM], size_t );
computeAverage as follows below:
double averageCompute( const double scores[], size_t n )
{
double sum = 0.0;
for ( size_t i = 0; i < n; i++ ) sum += scores[i];
return ( n == 0 ? sum : sum / n );
}
it should be called for each row of the array
size_t inputScores( std::ifstream &in,
std::string students[],
double scores[][SCORE_NUM],
size_t n )
{
std::string record;
size_t i = 0;
while ( i < n && std::getline( in, record ) )
{
std::istringstream is( record );
std::string lastName;
if ( is >> students[i] && is >> lastName )
{
students[i] += ' ';
students[i] += lastName;
}
std::memset( scores[i], 0, SCORE_NUM * sizeof( double ) );
size_t j = 0;
while ( j < SCORE_NUM && is >> scores[i][j] ) ++j;
++i;
}
return i;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.