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

Popular Post

Define a class to represent a Bank Account. Include the following members: Data Members: i. Name of the depositor ii. Account number iii. Type of account iv. Balance amount in the account Member Functions: 1. To Input initial values 2. To deposit an amount 3. To withdraw an amount after checking the balance 4. To display name and balance Also write constructor for this class that takes four arguments. It should also handle type of account as savings by default

Create a base class called shape .Use this class to store two double type values that could be used to compute the area of figures, Derive two specific classes called triangle and rectangle from the base shape .Add to the base class, a member function get_data() to initialise base class data members and another member function display_area() to compute and display the area of figures. Make display_area () as a virtual function and redefine this function in the derived class to suit their requirements. Using these three classes, design a program that will accept dimensions of a triangle or a rectangle interactively and display the area. Area of rectangle = x*y Area of triangle = ½*x*y