Write a C++ program using class which contains two data members of type integer. Create and initialize the object using default constructor,parameterized constructor, and parameterized constructor with default value. Write a member function to display maximum from given two numbers for all objects.
#include<iostream.h>
#include<conio.h>
class Example
{
int a,b;
public:
Example() {}
Example(int x,int y)
{
a=x;
b=y;
}
inline int maximum(int a,int b)
{
return a>b?a:b;
}
void display()
{
cout<<"\nValues:"<<a<<"\t"<<b;
}
};
int main()
{
int a,b;
Example m;
clrscr();
cout<<"\nEnter two numbers:";
cin>>a>>b;
cout<<"\nNumber 1:\t"<<a;
cout<<"\nNumber 2:\t"<<b;
cout<<"\n\nMaximum Number is:"<<m.maximum(a,b);
getch();
return 0;
}
#include<iostream.h>
#include<conio.h>
class Example
{
int a,b;
public:
Example() {}
Example(int x,int y)
{
a=x;
b=y;
}
inline int maximum(int a,int b)
{
return a>b?a:b;
}
void display()
{
cout<<"\nValues:"<<a<<"\t"<<b;
}
};
int main()
{
int a,b;
Example m;
clrscr();
cout<<"\nEnter two numbers:";
cin>>a>>b;
cout<<"\nNumber 1:\t"<<a;
cout<<"\nNumber 2:\t"<<b;
cout<<"\n\nMaximum Number is:"<<m.maximum(a,b);
getch();
return 0;
}