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

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

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

Assume that a bank maintains two kinds of accounts, are called as saving account and current account. The saving account provides compound interest and withdrawal facilities but no cheque book facility. The current account provides cheque book facility but no interest. Current account holders should also maintain a minimum balance and if the balance falls below the level, a service charge is imposed. Create a class account that stores customer name, account number and type of account. From this derive the classes cur_acct and sav_acct to make them more specific to their requirements. Include necessary member functions in order to achieve the following tasks: a.Include constructor for all the three classes. b.Accept deposit amount from the customer and update the balance. c.Display the balance. d.Compute and deposit interest. e.Permit withdrawal and update the balance. f. Check for minimum balance, impose penalty, necessary and update the balance.