Question

In: Computer Science

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

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

Write a function that calculates the average of student averages. (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 other functions are declared.

In the main program, invoke this function.

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

#include “stdafx.h”

#include <iostream>

#include <iomanip>

const int NUMBER_STUDENTS = 5, NUMBER_QUIZZES = 3;

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

//Precondition: Global constants NUMBER_STUDENTS and NUMBER_QUIZZES

//are the dimensions of the array grade. Each of the indexed variables

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

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

//number stu_num.

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

//Precondition: Global constants NUMBER_STUDENTS and NUMBER_QUIZZES

//are the dimensions of the array grade. Each of the indexed variables

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

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

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

//Precondition: Global constants NUMBER_STUDENTS and NUMBER_QUIZZES are //the dimensions of the array grade. Each of the indexed variables //grade[st_num-1, quiz_num-1] contains the score for 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 has been //output.

int main( )

{

    using namespace std;

    int grade[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 <<”][“<<quiz_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], double st_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 the sum of the quiz scores for student number       

        //st_num.

        st_ave[st_num -1] = sum/NUMBER_QUIZZES;

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

    }

}

void compute_quiz_ave(const int grade[][NUMBER_QUIZZES], double quiz_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 the sum of all student scores on quiz number

        //quiz_num.

        quiz_ave[quiz_num -1] = sum/NUMBER_STUDENTS;

        //Average for quiz quiz_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"

         << setw(5) << "Ave"

         << setw(15) << "Quizzes\n";

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

    {//Display for one st_num:

        cout << setw(10) << st_num

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

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

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

        cout << endl;

    }

    cout << "Quiz averages = ";

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

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

    cout << endl;

}

Solutions

Expert Solution

//main.cpp


#include <iostream>
#include <iomanip>
const int NUMBER_STUDENTS = 4, NUMBER_QUIZZES = 3;

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

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

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


int main( )
{
using namespace std;
int grade[NUMBER_STUDENTS][NUMBER_QUIZZES];
double st_ave[NUMBER_STUDENTS];
double quiz_ave[NUMBER_QUIZZES];

//The code for filling the array grade goes here, but is not shown.
compute_st_ave(grade, st_ave);
compute_quiz_ave(grade, quiz_ave);
display(grade, st_ave, quiz_ave);
return 0;
}

void compute_st_ave(const int grade[][NUMBER_QUIZZES], double st_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 the sum of the quiz scores for student number st_num.
st_ave[st_num -1] = sum/NUMBER_QUIZZES;
//Average for student st_num is the value of st_ave[st_num-1]
}
}


void compute_quiz_ave(const int grade[][NUMBER_QUIZZES], double quiz_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 the sum of all student scores on quiz number quiz_num.
quiz_ave[quiz_num -1] = sum/NUMBER_STUDENTS;
//Average for quiz quiz_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"
<< setw(5) << "Ave"
<< setw(15) << "Quizzes\n";
for (int st_num = 1; st_num <= NUMBER_STUDENTS; st_num++)
{//Display for one st_num:
cout << setw(10) << st_num
<< setw(5) << st_ave[st_num-1] << " ";
for (int quiz_num = 1; quiz_num <= NUMBER_QUIZZES; quiz_num++)
cout << setw(5) << grade[st_num -1][quiz_num -1];
cout << endl;
}

cout << "Quiz averages = ";
for (int quiz_num = 1; quiz_num <= NUMBER_QUIZZES; quiz_num++)
cout << setw(5) << quiz_ave[quiz_num -1];
cout << endl;
}

=====================================================================

sample output:


Related Solutions

USING PYTHON 3.7 AND USING def functions. Write a function called GPA that calculates your grade...
USING PYTHON 3.7 AND USING def functions. Write a function called GPA that calculates your grade point average (GPA) on a scale of 0 to 4 where A = 4, B = 3, C = 2, D = 1, and F = 0. Your function should take as input two lists. One list contains the grades received in each course, and the second list contains the corresponding credit hours for each course. The output should be the calculated GPA. To...
C++ Write a program that has two functions. The 1st function is the main function. The...
C++ Write a program that has two functions. The 1st function is the main function. The main function should prompt the user for three inputs: number 1, number 2, and an operator. The main function should call a 2nd function called calculate. The 2nd function should offer the choices of calculating addition, subtraction, multiplication, and division. Use a switch statement to evaluate the operator, then choose the appropriate calculation and return the result to the main function.
Write a program that contains a function that takes in three arguments and then calculates the...
Write a program that contains a function that takes in three arguments and then calculates the cost of an order. The output can be either returned to the program or as a side effect. 1. Ask the user via prompt for the products name, price, and quantity that you want to order. 2. Send these values into the function. 3. Check the input to make sure the user entered all of the values. If they did not, or they used...
Write a function that implements the following formula to calculates the amount of financial assistance for...
Write a function that implements the following formula to calculates the amount of financial assistance for families in need: • If the annual family income is between $30,000 and $40,000 and the family has at least 3 children, the assistance amount will be $1,000 per child. • If the annual family income is between $20,000 and $30,000 and the family has at least 2 children, the assistance amount will be $1,500 per child. • If the annual family income is...
Write a Racket function "combine" that takes two functions, f and g, as parameters and evaluates...
Write a Racket function "combine" that takes two functions, f and g, as parameters and evaluates to a new function. Both f and g will be functions that take one parameter and evaluate to some result. The returned function should be the composition of the two functions with f applied first and g applied to f's result. For example (combine add1 sub1) should evaluate to a function equivalent to (define (h x) (sub1 (add1 x))). You will need to use...
For this assignment, you will write a program that consists of four function definitions, including one...
For this assignment, you will write a program that consists of four function definitions, including one main() function. The main function gets inputs from the user, and the other functions show output to the user. When the program is executed, it asks the user to enter a small amount of information, and then shows output based on the user's info. Specification: Here are some specific requirements for this program: The program should consist of four function definitions, written one after...
Please solve the following problem for MATLAB Write a user-defined function that calculates the average and...
Please solve the following problem for MATLAB Write a user-defined function that calculates the average and the standard deviation of a list of numbers. Use the function to calculate the average and the standard deviation of the following list of grades : 80 75 91 60 79 89 65 80 95 50 81
Even Odd Average (C++ LANGUAGE) Write the following functions: Function #1 Write the function Print. The...
Even Odd Average (C++ LANGUAGE) Write the following functions: Function #1 Write the function Print. The function will have one int 1D array n and one int size as parameters. The function will display all the values of n on one line. Function #2 Write the function AverageEvenOdd. The function will have one int 1D array n and one int size as parameters. The size of the array is given by the parameter int size. Therefore, the function should work...
Write a MATLAB function that calculates the approximate value of arctan(x) using the Maclaurin series approximation:...
Write a MATLAB function that calculates the approximate value of arctan(x) using the Maclaurin series approximation: arctan⁡(x)=x-x^3/3+x^5/5-x^7/7+⋯ The function should accept 3 parameters: value of x, number of significant figures accuracy i.e. n, and the maximum number of iterations. In the function, use ε_s=(0.5×〖10〗^(2-n ) )% in order to continue until the ε_a falls below this criteria. The function should return 3 values: the approximate value of arctan(x) at the end of the program, final ε_a and the number of...
(Python3) Write a function friend_besties() that calculates the "besties" (i.e. degree-one friends) of a given individual...
(Python3) Write a function friend_besties() that calculates the "besties" (i.e. degree-one friends) of a given individual in a social network. The function takes two arguments: individual, an individual in the social network, in the form of a string ID. bestie_dict, a dictionary of sets of friends of each individual in the social network (as per the first question of the Project) The function should return a sorted list, made up of all "degree-one" friends for the individual. In the instance...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT