Using friend function find the maximum number from given two numbers from two different classes. Write all necessary functions and constructors for the program.
CODING:
#include<iostream.h>
#include<conio.h>
class B;
class A
{
int a;
public:
A()
{
a=5;
}
void disp()
{
cout<<a;
}
friend void max(A,B);
};
class B
{
int b;
public:
B()
{
b=8;
}
void disp()
{
cout<<b;
}
friend void max(A,B);
};
void max(A a1,B b1)
{
if(a1.a>b1.b)
{
cout<<a1.a<<" Greatest number.";
}
else
{
cout<<b1.b<<" Greatest number.";
}
}
void main()
{
A obj1;
B obj2;
clrscr();
obj1.disp();
cout<<endl;
obj2.disp();
cout<<endl ;
max(obj1,obj2);
getch();
}
CODING:
#include<iostream.h>
#include<conio.h>
class B;
class A
{
int a;
public:
A()
{
a=5;
}
void disp()
{
cout<<a;
}
friend void max(A,B);
};
class B
{
int b;
public:
B()
{
b=8;
}
void disp()
{
cout<<b;
}
friend void max(A,B);
};
void max(A a1,B b1)
{
if(a1.a>b1.b)
{
cout<<a1.a<<" Greatest number.";
}
else
{
cout<<b1.b<<" Greatest number.";
}
}
void main()
{
A obj1;
B obj2;
clrscr();
obj1.disp();
cout<<endl;
obj2.disp();
cout<<endl ;
max(obj1,obj2);
getch();
}
Comments
Post a Comment