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

Write a MATLAB program to: Prompt the user to enter numeric grades (one at a tim

ID: 1719270 • Letter: W

Question

Write a MATLAB program to: Prompt the user to enter numeric grades (one at a time) within a while loop. Any number of grades can be entered. Determine the number of grades in each grade range using a standard 10 point scale: A (90 or higher), B (80-90), C (70-80), D (60-70), and F (0-60). Determine the maximum, minimum, and average grade. Display the results including the number of grades, maximum grade, minimum grade, and the number of grades in each grade range. Test the program for cases including 4 grades, 10 grades, and 20 grades with the grades reasonably distributed between the grades ranges.

Explanation / Answer

#include <iostream>

using namespace std;
void calculate(int[],int,double&,double&,int&,int&);
int main()
{int a[50],i=0,j,low,high,again;
double average,median;
do
{i=0;
cout<<"Enter a grade (<0 to exit): ";
cin>>a[i];
while(a[i]>=0)
   {i++;
    cout<<"Enter a grade (<0 to exit): ";
    cin>>a[i];
    }
cout<<"Number Grade ------ ----- ";
for(j=0;j<i;j++)
    cout<<j+1<<" "<<a[j]<<endl;
calculate(a,i,average,median,low,high);
cout<<"The class average: "<<average<<endl;
cout<<"Highest Grade is: "<<high<<endl;
cout<<"Lowest Grade: "<<low<<endl;
cout<<"Median Grade: "<<median<<endl;
cout<<"again?(1 for yes, 2 for no): ";
cin>>again;
}while(again==1);
return 0;
}
void calculate(int a[],int n,double& avg,double& median,int& high,int& low)
{int i,j,t,sum=0;;
for(i=0;i<n-1;i++)
    {for(j=i;j<n;j++)
       if(a[i]<a[j])
           {t=a[i];
           a[i]=a[j];
           a[j]=t;
           }
       }
for(i=0;i<n;i++)
     sum+=a[i];
    
avg=sum/(double)n;
low=a[0];
high=a[n-1];
if(n%2==0)
    median=(a[n/2]+a[n/2-1])/2.;
else
    median=a[n/2];
}

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