Answer to Question #238487 in C++ for Ravi

Question #238487

Write a program to find the greatest of two given m two different classes using friend function.


1
Expert's answer
2021-09-17T05:27:02-0400
#include <iostream>

using namespace std;


class Class_A 
{
	private:
   		int x, y;
	public:
	   void GetNumbers() 
	   {
       	cout << "\n\tEnter two numbers: ";
       	cin >> x>>y;
   	   }	
    friend void GetLargest(Class_A t);
};


void GetLargest(Class_A t) 
{
   if (t.x > t.y) cout << "\n\tThe Largest number is: " << t.x;
   if(t.x < t.y)  cout << "\n\tThe Largest number is: " << t.y;
   if(t.x == t.y) cout << "\n\tBoth numbers are equal. " << t.x<<" = "<<t.y;
}


int main() 
{
   Class_A t;
   t.GetNumbers();
   GetLargest(t);
   return 0;
}





Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS