Read the function definitions of the two functions: “compute_st_ave” and “compute_quiz_ave”. Write a function that calculates the...

80.2K

Verified Solution

Question

Programming

Read the function definitions of the two functions:“compute_st_ave” and “compute_quiz_ave”.

Write a function that calculates the average of studentaverages. (Student averages are stored in st_ave [5] array).Include a statement to print this average on the screen.

Declare this function above the “main” function where otherfunctions are declared.

In the main program, invoke this function.

//Reads quiz scores for each student into the two-dimensionalarray grade //(but the input code is not shown in this display).Computes the average //score for each student and the average scorefor each quiz. Displays //the quiz scores and the averages.

#include “stdafx.h”

#include

#include

const int NUMBER_STUDENTS = 5, NUMBER_QUIZZES = 3;

void compute_st_ave(const int grade[][NUMBER_QUIZZES], doublest_ave[]);

//Precondition: Global constants NUMBER_STUDENTS andNUMBER_QUIZZES

//are the dimensions of the array grade. Each of the indexedvariables

//grade[st_num-1, quiz_num-1] contains the score for studentst_num on //quiz quiz_num.

//Postcondition: Each st_ave[st_num-1] contains the average forstudent

//number stu_num.

void compute_quiz_ave(const int grade[][NUMBER_QUIZZES], doublequiz_ave[]);

//Precondition: Global constants NUMBER_STUDENTS andNUMBER_QUIZZES

//are the dimensions of the array grade. Each of the indexedvariables

//grade[st_num-1, quiz_num-1] contains the score for studentst_num on //quiz quiz_num.

//Postcondition: Each quiz_ave[quiz_num-1] contains the averagefor quiz //number quiz_num.

void display(const int grade[][NUMBER_QUIZZES], const doublest_ave[], const double quiz_ave[]);

//Precondition: Global constants NUMBER_STUDENTS andNUMBER_QUIZZES are //the dimensions of the array grade. Each of theindexed variables //grade[st_num-1, quiz_num-1] contains the scorefor student st_num on //quiz quiz_num. Each st_ave[st_num-1]contains the average for student //stu_num. Each quiz_ave[quiz_num-1] contains the average for quiz //number quiz_num.

//Postcondition: All the data in grade, st_ave, and quiz_ave hasbeen //output.

int main( )

{

    using namespace std;

    intgrade[NUMBER_STUDENTS][NUMBER_QUIZZES];

    double st_ave[NUMBER_STUDENTS];

    double quiz_ave[NUMBER_QUIZZES];

//The code for filling the array grade goes here.

    for (int st_num = 1; st_num <=NUMBER_STUDENTS; st_num++)

    {

        for (int quiz_num =1; quiz_num <= NUMBER_QUIZZES; quiz_num++)

           {cout << “Enter the grade [” << st_num<<”][“<

           =”;

           cin >> grade[st_num -1][quiz_num -1];

           }   

    }

    compute_st_ave(grade, st_ave);

    compute_quiz_ave(grade, quiz_ave);

    display(grade, st_ave, quiz_ave);

    system (“pause”);

    return 0;

}

void compute_st_ave(const int grade[][NUMBER_QUIZZES], doublest_ave[])

{

    for (int st_num = 1; st_num <=NUMBER_STUDENTS; st_num++)

    {//Process one st_num:

        double sum = 0;

        for (int quiz_num =1; quiz_num <= NUMBER_QUIZZES; quiz_num++)

           sum = sum + grade[st_num -1][quiz_num -1];

        //sum contains thesum of the quiz scores for studentnumber       

        //st_num.

        st_ave[st_num -1] =sum/NUMBER_QUIZZES;

        //Average for studentst_num is the value of st_ave[st_num-1]

    }

}

void compute_quiz_ave(const int grade[][NUMBER_QUIZZES], doublequiz_ave[])

{

    for (int quiz_num = 1; quiz_num <=NUMBER_QUIZZES; quiz_num++)

   {//Process one quiz (for all students):

        double sum = 0;

        for (int st_num = 1;st_num <= NUMBER_STUDENTS; st_num++)

           sum = sum + grade[st_num -1][quiz_num -1];

        //sum contains thesum of all student scores on quiz number

        //quiz_num.

        quiz_ave[quiz_num -1]= sum/NUMBER_STUDENTS;

        //Average for quizquiz_num is the value of quiz_ave[quiz_num-1]

    }

}

//Uses iostream and iomanip:

void display(const int grade[][NUMBER_QUIZZES],

                       const double st_ave[], const double quiz_ave[])

{

    using namespace std;

    cout.setf(ios::fixed);

    cout.setf(ios::showpoint);

    cout.precision(1);

    cout << setw(10) << \"Student\"

         <

         <

    for (int st_num = 1; st_num <=NUMBER_STUDENTS; st_num++)

    {//Display for one st_num:

        cout <

            << setw(5) << st_ave[st_num-1] << \" \";

        for (int quiz_num =1; quiz_num <= NUMBER_QUIZZES; quiz_num++)

           cout <

        cout <

    }

    cout << \"Quiz averages = \";

    for (int quiz_num = 1; quiz_num <=NUMBER_QUIZZES; quiz_num++)

        cout << setw(5)<< quiz_ave[quiz_num -1];

    cout << endl;

}

Answer & Explanation Solved by verified expert
4.2 Ratings (667 Votes)
maincppinclude include const int NUMBERSTUDENTS 4 NUMBERQUIZZES 3void computestaveconst int gradeNUMBERQUIZZES    See Answer
Get Answers to Unlimited Questions

Join us to gain access to millions of questions and expert answers. Enjoy exclusive benefits tailored just for you!

Membership Benefits:
  • Unlimited Question Access with detailed Answers
  • Zin AI - 3 Million Words
  • 10 Dall-E 3 Images
  • 20 Plot Generations
  • Conversation with Dialogue Memory
  • No Ads, Ever!
  • Access to Our Best AI Platform: Flex AI - Your personal assistant for all your inquiries!
Become a Member

Other questions asked by students