Write a program to display the minimum, maximum, sum, search and average of elements of an array.

 



#include<iostream>
using namespace std;
class array
{
     private:
             int a[100],i,j,sum,n;
     public:
             void get()
             {
                cout<<"enter the size of an array :"<<endl;
                cin>>n;
                cout<<"enter the elements of an array :"<<endl;
                for (int i = 0i < ni++)
                {
                    cin>>a[i];
                }
             }

             void maxmin()
             {
                cout<<"\n\n"<<endl;
                j=0;
                for (int i = 0i < ni++)
                {
                     if (a[i]>j)
                        j=a[i];
                }
                cout<<"the max no. is "<<j<<endl;
                  j=a[0];
                for (int i = 0i < ni++)
                {
                     if (a[i]<j)
                        j=a[i];
                }
                cout<<"the min no. is "<<j<<"\n\n"<<endl;
                cout<<"*******************************************************************"<<endl;
             }

             void add()
             {
                cout<<"\n\n"<<endl;
                sum=0;
                for (int i = 0i < ni++)
                {
                    sum=sum+a[i];
                }
                cout<<"the sum of your array is :"<<sum<<"\n\n"<<endl;
                cout<<"*******************************************************************"<<endl;
             }

             void search()
             {
                cout<<"\n\n"<<endl;
                int x;
                cout<<"enter the number which you want to find :"<<endl;
                cin>>x;
                int count = 0;
                for ( i = 0i < ni++)
                {
                    if (x==a[i])
                    {
                        count=2;
                        break;
                    }
                }
                    if(count==2)
                    cout<<x<<" is found at "<<i+1<<"rd position \n\n"<<endl;
                    else
                    cout<<"number is not found !!!"<<endl;
                    cout<<"*******************************************************************"<<endl;
             }

             void average()
             {
                cout<<"\n\n"<<endl;
                int avr=sum/n;
                cout<<"avarage of this array is "<<avr<<"\n\n"<<endl;
                cout<<"*******************************************************************"<<endl;
             }
};

int main()
{
    array c1;
    c1.get();
    c1.add();
    c1.maxmin();
    c1.search();
    c1.average();
}

output :
enter the size of an array :
7 enter the elements of an array : 34 12 67 56 9 12 99 the sum of your array is :289 ******************************************************************* the max no. is 99 the min no. is 9 ******************************************************************* enter the number which you want to find : 12 12 is found at 2rd position ******************************************************************* avarage of this array is 41 *******************************************************************

Comments