Answer to Question #232864 in C++ for Arup

Question #232864
Write a program in C++ to create two classes separately each having one integer value as its private data member. Compare both the values and display in main functions whether the values are equal or not. Use pass by address method to execute the code.
1
Expert's answer
2021-09-03T06:45:15-0400
#include <iostream>


using namespace std;
class B;


class A  {
    private:
    	int a;
    	friend void compare(A n1 , B n2);
    	
    public:
    	A (int a){
    		this->a=a;
    		cout<<"Number A: "<<a<<"\n";
    	}
};


class B {
    private:
    	int b;
    	friend void compare(A n1 , B n2);
    public:
    	B (int b){
    		this->b=b;
    		cout<<"Number B: "<<b<<"\n";
    	}
};


void compare(A n1,B n2) {
	if (n1.a==n2.b)
	    cout<<"\nThe two numbers are equal.";
	else
	    cout<<"\nThe two numbers are not equal.";
}
int main (){
	A a(67);
	B b(67);
	compare(a,b);
	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