C++ program functions arrays -


this program should work in microsoft visual studio

function -> void inputscores(string[], double[][5]);

this function populates array of strings names in file.

this function populates 2d array of doubles 5 scores associated 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 , computelettergrade.

the function prototypes using void return type suggestions.

there different ways create program.

you may change function behavior if necessary or expedient so

students data are:

ritch blackmore, 85 95 57 78 56

jimmy page, 89 78 45 69 98

pete townsend, 93 56 67 67 45

alvin lee, 93 67 89 90 45

pete green, 89 34 56 78 98

jeff beck, 85 34 67 87 65

eric clapton, 95 34 56 65 87

david gilmour, 90 67 89 90 98

tony iommi, 86 45 67 87 98

carlos santana, 95 56 78 96 56

mark knopfler, 75 54 67 76 87

alex lifeson, 80 56 76 87 98

frank zappa, 80 65 76 56 98

mick taylor, 85 45 65 76 87

robert fripp, 70 43 90 80 78

peter frampton, 83 45 65 76 54

ry cooder, 95 34 56 78 87

keith richards, 95 45 67 89 67

joe walsh, 95 45 78 90 45

steve hackett, 95 34 56 54 76

i declare functions following way

const size_t score_num = 5; const size_t student_num = 100; // @ least not less number of records in file  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 ); 

for example function computeaverage defined as

double computeaverage( const double scores[], size_t n ) {    double sum = 0.0;     ( size_t = 0; < n; i++ ) sum += scores[i];     return ( n == 0 ? sum : sum / n ); } 

it should called each row of array of doubles.

the definition of function inputscores (without testing):

size_t inputscores( std::ifstream &in,                      std::string students[],                      double scores[][score_num],                      size_t n ) {    std::string record;    size_t = 0;     while ( < n && std::getline( in, record ) )    {       std::istringstream is( record );        std::string lastname;        if ( >> students[i] && >> lastname )       {          students[i] += ' ';          students[i] += lastname;       }        std::memset( scores[i], 0, score_num * sizeof( double ) );        size_t j = 0;        while ( j < score_num && >> scores[i][j] ) ++j;         ++i;    }     return i; } 

Comments

Popular posts from this blog

apache - Remove .php and add trailing slash in url using htaccess not loading css -

javascript - jQuery show full size image on click -