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

Write a C/C+ program that asks the user to type in N test grades from the keyboa

ID: 3816422 • Letter: W

Question

Write a C/C+ program that asks the user to type in N test grades from the keyboard, then calculates and displays the following statistical values: Sum of grades S = S + grades[i] Mean of grades = M/N Variance: V = V + (grades[i]-mean)*(grades[i]-mean); standard deviation: (SD = squareroot (V)/(N + 1) Minimum grade = Min Maximum grade = Max Number even grades = evens Number odd grades = odds You must calculate the above by using for loops, if-else if loops or while loops, along with the modulus function (e.g modulus (remainder) of x divided by 2 is given by x%2).Note that M and SD are the only single point values (i.e. SD and M are not calculated within a for loops), all others require a for loop to calculate correctly. After writing your program, you should test it with the following list of 39 grades: Grades = {77 84 67 62 57 59 88 68 91 94 75 60 96 63 78 81 90 79 87 85 65 71 95 98 69 50 83 73 82 72 99 61 70 85 79 97 66 92 62}

Explanation / Answer

//program and output is given below

#include <iostream>
#include<math.h>

using namespace std;

int main()
{
   int grades[100];
   double S=0,M,N,V=0,SD,Min,Max,evens=0,odds=0;
   int i;
   //prompt user and accept grades store number of grades in N
   cout<<"How many grades user want to enter:";
   cin>>N;
   for(i=0;i<N;i++)
   cin>>grades[i];
   //calculate sum of grades and store it in S
   for(i=0;i<N;i++)
   S=S+grades[i];
   //calculate mean store it in M
   M=S/N;

   //I used formula given in problem but correct formula for variance and
   // Standard deviation is little bit different therefore results may be wrong
   // because i am using your formula given in problem

   //calculate variance by given formula and store in V
   for(i=0;i<N;i++)
   V=V+(grades[i]-M)*(grades[i]-M);

   //calculate standard deviation
   SD=sqrt(V)/(N+1);

   //find min and max in grades
   Min=grades[0];
   Max=grades[0];
   for (i=0;i<N;i++)
    {
      if (grades[i]>Max)
        {
          Max=grades[i];
        }
      else if (grades[i]<Min)
        {
          Min=grades[i];
        }
    }

   //find number of odd and even grades
   for(i=0;i<N;i++)
   {
       if(grades[i]%2==0)
       evens=evens+1;
       else
       odds=odds+1;
   }

   cout<<"Sum of grades:"<<S<<endl;
   cout<<"Mean of grades:"<<M<<endl;
   cout<<"Variance:"<<V<<endl;
   cout<<"Standard Deviation:"<<SD<<endl;
   cout<<"Min grade:"<<Min<<endl;
   cout<<"Max grade:"<<Max<<endl;
   cout<<"Number of even grades:"<<evens<<endl;
   cout<<"Number of odd grades:"<<odds<<endl;
   return 0;
}

/* Output

How many grades user want to enter:37                                                                                                                                    

77 84 67 62 57 59 88 68 91 94 75 60 96 63 78 81 90 79 87 85 65 71 95 98 69 50 83 73 82 72 99 61 70 85 79 97 66 92 62                                                     

Sum of grades:2856                                                                                                                                                       

Mean of grades:77.1892                                                                                                                                                   

Variance:6205.68                                                                                                                                                         

Standard Deviation:2.07306                                                                                                                                               

Min grade:50                                                                                                                                                             

Max grade:99                                                                                                                                                             

Number of even grades:15                                                                                                                                                 

Number of odd grades:22  

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote