Write a Cpp program to display largest number by using multiple constructor, friend function, multiple class?

All QuestionsCategory: Cpp LanguageWrite a Cpp program to display largest number by using multiple constructor, friend function, multiple class?
Chetan Shidling Staff asked 5 years ago

I need short information.

1 Answers
Chetan Shidling Staff answered 5 years ago

Code:

#include <iostream>
using namespace std;
class xyz;
class abc
{
int a;
public:void get()
{
a = 10;
}
friend void add(abc, xyz);
};
class xyz
{
int b;
public:void get()
{
b = 20;
}
friend void add(abc, xyz);
};
void add(abc obj1, xyz obj2)
{
if(obj1.a>obj2.b)
cout<<“Obj1 is greater:”<<obj1.a;
else
cout<<“Obj2 is greater:”<<obj2.b;
}
int main()
{
abc a;
xyz b;
a.get();
b.get();
add(a,b);
return 0;
}

Output:

Obj2 is greater:20