Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

q6) CONSIDER THE FOLLOWING CODE: using the following input: 5, 9, 7, 8, 6, 7.5;

ID: 3810038 • Letter: Q

Question

q6)

CONSIDER THE FOLLOWING CODE:
using the following input: 5, 9, 7, 8, 6, 7.5;
void Question()
{
      int NumTests;
      double grades = 0;
      double temp = 0;
      cout << "How many tests do you have? ";
      cin >> NumTests;
      for (int index = 0; index<NumTests; index++)
      {
            cout << "Enter test score :";
            cin >> grades;
            temp += grades;
      }
      cout << endl;
      cout << "Here are the answer :" << temp / NumTests << endl;
}

Select one:

a. Here are the answer :6

b. Here are the answer :7.5

c. Here are the answer :7

d. Here are the answer :8

please explain how you get the answer. Thank you

Explanation / Answer

Answer is b.Here are the answer:7.5

when u enter the first input 5,it sets variable NumTests to 5. As a result the for loop runs for 5 times as index is 0 and loop will run for index<5 i.e 0,1 ,2 ,3 ,4.

inside the loop. we are entering the scores in variables grades and in the next line all the grades are being added together and stored in variable temp.

hence temp stores 9+7+8+6+7.5=37.5

cout << "Here are the answer :" << temp / NumTests << endl;

this outputs the sum of scores kept in temp(37.5) divided by no. of tests kept in NumTests(5).

Hence 37.5/55=7.5