CS Electrical And Electronics
@cselectricalandelectronics

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?
CS Electrical And Electronics Staff asked 4 years ago

I need short information.

1 Answers
CS Electrical And Electronics Staff answered 4 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