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

Write the C++ codes and run the program for the results. Requirments for the C++

ID: 2267843 • Letter: W

Question

Write the C++ codes and run the program for the results. Requirments for the C++ codes: 1. Must use Loop (for/while) 2. Must use array Must use Interactive statements cin, cout to allow the user to input 5 valid grades through the keyboard. The grade between 0 and 100 is considered "valid". Hint: if+ continue; e.g. if the input grade is not valid, the invalid grade should not be counted and the system should allow the user to continue to input the grade. 3. 4. 5. 6. Find and display the minimum grade Find and display the maximum grade Find and display the average grade

Explanation / Answer

#include <iostream>
#include <cmath>
using namespace std;

int main ()
{
   int grades[5], min, max, sum, min_sub, max_sub;
   float avg;
   for (int i = 0; i < 5 ; ) {
   cout << "Enter the grades (valid between 0 to 100) for subject " << i + 1 << endl;
   cin >> grades[i];
   if ((grades[i] > 100) || (grades[i] < 0)) {
   cout << "You have entered the invalid grades. Please enter valid grades" << endl;
   continue;
   }
   else {
   i++;
   }
   }
   min = 100;
   max = 0;
   sum = 0;
   min_sub = 1;
   max_sub = 1;
   for (int i = 0 ; i < 5; i++) {
   if (grades[i] > max) {
   max = grades[i];
   max_sub = i + 1;
   }
   if (grades[i] < min) {
   min = grades[i];
   min_sub = i + 1;
   }
   sum = sum + grades[i];
   }
   avg = sum / 5.0;
   cout << "The minimun grades is :: " << min << " for subject " << min_sub << endl;
   cout << "The maximun grades is ::" << max << " for subject " << max_sub << endl;
   cout << "The average of total 5 subjects grades is :: " << avg << endl;

return 0;
}
/********************* Output of Program ****************************
Enter the grades (valid between 0 to 100) for subject 1
78
Enter the grades (valid between 0 to 100) for subject 2
49
Enter the grades (valid between 0 to 100) for subject 3
68
Enter the grades (valid between 0 to 100) for subject 4
61
Enter the grades (valid between 0 to 100) for subject 5
94
The minimun grades is :: 49 for subject 2
The maximun grades is ::94 for subject 5
The average of total 5 subjects grades is :: 70
*********************************************************************/

Dr Jack
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Chat Now And Get Quote