1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85
|
#include <iostream>
using namespace std;
void Instruct();
void GetNumbers(int [],int);
int FindLargest(int [],int);
int FindSmallest(int [],int);
int Sum(int [],int);
float Avg(int,int);
void Output(int,int,int,float);
int main()
{
int array[10];
Instruct();
GetNumbers(array,10);
FindLargest(array,10);
FindSmallest(array,10);
Sum(array,10);
Avg(Sum(array,10),10);
Output(larg,small,sum,avg);
return 0;
}
void Instruct(void) //This function provides an introduction to the program.
{
cout<<"This program will determine the smallest and largest value in a set of ten numbers."<<endl<<"It will also compute the sum and average of these numbers."<<endl;
}
void GetNumbers (int a[],int n) //This function takes the the user input and places it in an array
{
cout<<endl<<"Please enter a set of ten numbers each separated by a space: "<<endl;
for(int i=0;i<n;i++)
{
cin>>a[i];
}
cout<<endl<<"Your array has these values: ";
for(int i=0;i<n;i++)
{cout<<a[i]<<" ";}
cout<<endl;
}
int FindLargest (int a[],int n) //This function finds the largest value in the array.
{
int larg=a[0];
for (int i=0;i<n;i++)
{ if (a[i]>larg)
larg=a[i];
}
return larg;
}
int FindSmallest (int a[],int n) //This function finds the smallest value in the array.
{
int small=a[0];
for (int i=0;i<n;i++)
{ if (a[i]<small)
small=a[i];
}
return small;
}
int Sum (int a[],int n) //This function finds the sum of the array.
{
int sum=0;
for (int i=0;i<n;i++)
sum+=a[i];
return sum;
}
float Avg (int s,int n) //This function finds the average of the array.
{
float avg=0;
avg=s/n;
return avg;
}
void Output(int l,int sm,int sum, float avg)
{
cout<<endl<<"From your list of ten numbers: "<<endl;
cout<<"\t Largest:\t"<<l<<endl;
cout<<"\t Smallest:\t"<<sm<<endl;
cout<<"\t Sum:\t"<<sum<<endl;
cout<<"\t Average:\t"<<avg<<endl;
}
|