Write a program to find the maximum of two member variables suing friend function
/*Write a program to find the maximum of two member variables suing friend function
Programmed by: KiranShrestha
Roll No.: 10121
Programmed on: 31st july,2011*/
#include <iostream.h>
#include <conio.h>
class D
{
intx,y;
public:
D(int a, int b)
{
x= a;
y=b;
}
void display()
{
max(x,y);
}
friend void max (int ,int);
};
void max(inta,int b)
{
if(a>b)
cout<<“the greatest no is x= “<<a<<endl;
else
cout<<“the greatest no is y= “<<b<<endl;
}
int main()
{
inta,b;
cout<<“Enter ta value of x: “;
cin>>a;
cout<<“Enter ta value of y: “;
cin>>b;
D c(a,b);
c.display();
getch();
}
Output sample:
Enter the value of x: 6
Enter the value of y: 8