Answer to Question #233331 in C++ for SOM

Question #233331

Write a program to find out the greatest between two numbers defined in two different classes by using friend function.


1
Expert's answer
2021-09-05T00:32:43-0400
#include<iostream>
#include <stdio.h>
#include <cstdlib>
#include<conio.h>
using namespace std;


class B;
class A
{
int m;
public:
void getm()
{
cout<<"Enter the value of interger m:";
cin>>m;
}
void clrscr() {
  system("cls");
  system("clear");  
}
friend void max(A, B);
};
class B
{
int n;
public:
void getn()
{
cout<<"\nEnter the value of interger n:";
cin>>n;
}
friend void max(A,B);
};
void max(A x,B y)
{
if(x.m>y.n)
{
cout<<"\nGreater number is:"<<x.m;	
 }
else
{
cout<<"\nGreater number is:"<<y.n;
}
}
int main()
{
A x;
B y;
x.getm();
y.getn();
max(x,y);
getch();
}

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