Answer to Question #339137 in C++ for ruski

Question #339137

Examine the incomplete program below. Write code that can be placed below the comment (// Write your code here) to complete the program. Use nested loops to calculate the sum and average of all scores stored in the 2-dimensional array: students so that when the program executes, the following output is displayed. Do not change any other part of the code.


OUTPUT:

Sum of all scores = 102

Average score = 17

CODE:

#include <iostream>

using namespace std;

int main()

{

  const int NUM_OF_STUDENTS = 2;

  const int NUM_OF_TESTS = 3;

  int sum = 0, average = 0;

   

  double students[NUM_OF_STUDENTS][NUM_OF_TESTS] =   

    {

      {11, 12, 13},

      {21, 22, 23}

    };

     

  // Write your code here:

   

   

   

  cout << "Sum of all scores = " << sum << endl;

  cout << "Average score = " << average << endl;

   

  return 0;

}


1
Expert's answer
2022-05-09T14:54:19-0400
#include <iostream>

using namespace std;

int main()

{

  const int NUM_OF_STUDENTS = 2;

  const int NUM_OF_TESTS = 3;

  int sum = 0, average = 0;

   

  double students[NUM_OF_STUDENTS][NUM_OF_TESTS] =   

    {

      {11, 12, 13},

      {21, 22, 23}

    };

     

  // Write your code here:
int i,j;
   for( i=0; i<NUM_OF_STUDENTS; ++i)   {
        for( j=0; j<NUM_OF_TESTS; ++j)  
            sum = sum + students[i][j];
                 }
average = sum/(NUM_OF_STUDENTS*NUM_OF_TESTS);
   

   

  cout << "Sum of all scores = " << sum << endl;

  cout << "Average score = " << average << endl;

   

  return 0;

}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS