Create a C++ class Mindata to perform following functions: int min( int, int) – returns the minimum of two integer arguments. float min(float, float, float) – returns the minimum of three float arguments. int min( int [ ] ,int) – returns the minimum of all elements in an array of size ‘n’.
//Note: If you are not using Borland or Turbo C then add the following line after header files :
//using namespace std;
#include<conio.h>
#include<iostream.h>
class mindata
{
public:
int min(int a,int b) //function overloading
{
if(a<b)
{
return(a);
}
else
return(b);
}
float min(float a,float b) //function overloading
{
if(a<b)
{
return(a);
}
else
return(b);
}
int min(int a[],int n) //function overloading
{
int i;
int s;
s=a[0];
for(i=1;i<n;i++)
{
if(a[i]<s)
{
s=a[i];
}
}
return(s);
}
};
void main()
{
int a,b,p[10],n,i;
float c,d;
mindata m; //object created
cout<<"Enter (integer)value of 1st no: ";
cin>>a;
cout<<"Enter (integer)value of 2nd no: ";
cin>>b;
cout<<m.min(a,b)<<" is minimum."<<endl;
cout<<"Enter (float)value of 1st no: ";
cin>>c;
cout<<"Enter (float)value of 2nd no: ";
cin>>d;
cout<<m.min(c,d)<<" is minimum."<<endl;
cout<<"Enter how many no in an array: ";
cin>>n;
for(i=0;i<n;i++)
{
cout<<"Enter the elements: ";
cin>>p[i];
}
cout<<m.min(p,n)<<" is minimum."<<endl;
getch();
}
0 Comments