jituTechnology

jituTechnology

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
The greatest no is y=8

No comments yet.

Add a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.



Connect with Me

GPO 8973 NPC 541; Kathmandu Nepal
Phone: +977 9851236800

Calendar

June 2019
S M T W T F S
« Jun    
 1
2345678
9101112131415
16171819202122
23242526272829
30