Write a program to find the maximum of two numbers using template.

#include<iostream.h>
#include<conio.h>
#include<iomanip.h>
class max
{
    public:
       int x,y;
    void getdata()
    {
    cout<<endl<<"\nEnter a number:";
    cin>>x;
    cout<<endl<<"\nEnter another number:";
    cin>>y;
    }
    void showdata()
    {
    cout<<endl<<"x is :"<<x;
    cout<<endl<<"y is :"<<y;
    }
    friend int larger (max m);
};
int larger (max m)
{
   if(m.x>m.y)
     return m.x;
    else
       return m.y;
}
void main()
{
   max m;
   clrscr();
   m.getdata();
   m.showdata();
   cout<<endl<<"\nLarger is:"<<larger(m);
   getch();
}

No comments:

Post a Comment