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

C++ Programming:Arrays Objectives: 1. Write a program that finds the highest, lo

ID: 3555522 • Letter: C

Question

C++ Programming:Arrays

Objectives:

1. Write a program that finds the highest, lowest, mean, and median values of a set of numerical data

2. Use Arrays to store data and sort

3. Use an array as argument in function Calls

Problem statement:

Write a program that will

a) Prompt the user to enter numerical grades of students in a test, one at a time, and store it in an array. This is accomplished in the main module. The user enters a negative number to indicate all the grades are entered. The program will keep the count of the number of grades entered.

b) Display all the grades in a tabular form as shown below.

c) Call function to sort the array of grades in ascending order, calculate and return the average grade of the class.

d) Finally display the class average, highest grade, the lowest grade, and the median at the bottom. At the end the user is prompted to exit or enter grades for another class.

Procedure or Details:

The array is passed to the function.

All calculations are done in the function.

The values are displayed in the main module.

The following is an example of the output:

Number Grade

---------- --------

1 65

2 90

3 72

4 86

5 89

6 62

7 82

8 92

9 95

10 68

The class average: 80.1

Highest Grade is: 92

Lowest Grade: 62

Median Grade: 84

This requires sorting of the array. The median is the middle number of the sorted grades if the number of grades is odd. The median is average of the two middle numbers if the number of grades is even. In the above example, the median is (82+86)/2 = 84

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