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

Write a program that will read data of type double. Find the smallest value, asc

ID: 3635394 • Letter: W

Question

Write a program that will read data of type double.
Find the smallest value, ascending order ,descending order,sum and the average of the data .use -1 as a sentinel.
Reference array where appropriate?

Bring in array arguments as constant,so that the function will not alter what is in the array.

Criteria: six functions:
first Function will fill array with data from the keyboard and return actual data.
Initialize that data to integral size .use -1 to mark end of array.

Second function Sort the data in ascending order and return the data in ascending order.

Third function will reverse the data and return the data in descending order.

Fourth function find and output the smallest value of the data in the array.
Bring in array arguments as constant,so that the function will not alter what is in the array.



Fifth function Find the sum and average values of the array.
Bring in array arguments as constant so that the function will not alter what is in the array.
lastly main function.

Explanation / Answer

please rate - thanks

if there is any proble, please message me before rating

thanks

#include <iostream>
using namespace std;
void fillArray(double[]);
void ascending(double[]);
void descending(double[]);
void minimum(const double[]);
void sumAverage(const double[],double&,double&);
void print(double[],char[]);
int main()
{double m,i=0,min,max;
double avg,sum;
double num[50];
fillArray(num);
print(num,"original array");
ascending(num);
print(num,"array ascending");
descending(num);
print(num,"array descending");
minimum(num);
sumAverage(num,avg,sum);
cout<<"the sum of the numbers is: "<<sum<<endl;
cout<<"the average of the numbers is: "<<avg<<endl;
system("pause");
return 0;
}
void fillArray(double n[])
{int i=-1;
do
   {i++;
    cout<<"Enter a number (-1 to exit) ";
    cin>>n[i];   
    }while(n[i]!=-1);
}
void print(double n[],char mess[])
{int i=-1;
cout<<mess<<endl;
while(n[++i]!=-1)
     cout<<n[i]<<" ";
cout<<endl<<endl;
}
void ascending(double a[])
{int i,j,m=0;
double temp;
while(a[m++]!=-1);
m--;
for(i=0;i<m-1;i++)
   for(j=i;j<m;j++)
      if(a[i]>a[j])
         {temp=a[i];
         a[i]=a[j];
         a[j]=temp;
         }
}
void descending(double a[])
{int i,j,m=0;
double temp;
while(a[m++]!=-1);
i=0;
m-=2;
while(m>i)
{temp=a[i];
    a[i]=a[m];
    a[m]=temp;
    m--;
    i++;
   }
}
void minimum(const double a[])
{int i=0;
double max=a[0];
while(a[++i]!=-1)
    if(a[i]<max)
        max=a[i];
cout<<"Smallest value in the array is: "<<max<<endl<<endl;
}
void sumAverage(const double a[],double& avg,double& sum)
{
int i=0;
sum=0;
while(a[i]!=-1)
   sum+=a[i++];
avg=sum/i;

}

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