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

Write a program that dynamically allocates an array large enough to hold a user-

ID: 3758835 • Letter: W

Question

Write a program that dynamically allocates an array large enough to hold a user-defined number of test scores. Once all the scores are entered, the array should be passed to a function that sorts them in ascending order.

Another function should be called that calculates the average score of the items in the array.

The program should display the sorted array of scores and averages with appropriate headings. After the sorted array (and its average) has been displayed, drop the lowest score and re-display the sorted array and new average.

Use pointer notation rather than array notation whenever possible.  Input Validation: Do not accept negative numbers for test scores.

Explanation / Answer

#include<iostream.h>
#include<conio.h>
void av(int a[], int n)
{
   int i,s=0;
   double avg;

   for(i=0;i<n;i++)
   {
       s=s+a[i];

   }
   avg=s/n;
   cout<<"Average ="<<avg<<endl;
}
void sort(int a[], int n)
{
   int i,j,lr,temp;

   lr=a[0];

   for(i=0;i<n;i++)
   {
       for(j=0;j<n;j++)
       {
           if(a[i]<a[j])
           {
               temp=a[i];
               a[i]=a[j];
               a[j]=temp;
           }
       }
   }
   cout<<"sorted array is"<<endl;
   for(i=0;i<n;i++)
   {
       cout<<a[i]<<endl;
   }
   getch();
}

void main()
{
   int a[10000],s=0,i,n;

   cout<<"Enter number of students";
   cin>>n;
  
   for(i=0;i<n;i++)
   {
       cout<<"Enter Scores";
       cin>>a[i];
  
   }
  

   av(a,n);

   sort(a,n);
   s=a[0];
   for(i=0;i<n;i++)
   {
       if(a[i]<s)
       {
           s=a[i];
       }  
   }

   for(i=0;i<n;i++)
   {
       if(a[i]==s)
       {
           a[i]=a[i+1];
       }  
   }
   n=n-1;
   av(a,n);
   sort(a,n);

}


  
     

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