Can someone please help with this programming question (Friend function & Operat
ID: 3839639 • Letter: C
Question
Can someone please help with this programming question
(Friend function & Operator overloading) Write a friend function called 'equal' for the class 'Enterprize' that was created above. The function takes two objects of this class and compares their categories. It returns a (true) Boolean value if they are equal. Write only the function declaration and the function definition (do not write the class definition again). In the main function, write statements to compare the categories of Salvation army and HEB using the friend function 'equal' and print appropriate messages. Overload the '==' operator for the class 'Enterprize' that was created above. It should carry out exactly the same steps as that of the 'equal' function above. Write only the function declaration and the function definition. In the main function, write statements to compare the categories of Salvation_army and HEB using the overloaded operator'==' and to print appropriate messages.Explanation / Answer
#include <iostream>
using namespace std;
// forward declaration
class B;
class Enterprize {
public:
int numA;
// friend function declaration
friend bool equal(Enterprize, B);
};
class B {
public:
int numB;
// friend function declaration
friend bool equal(Enterprize , B);
};
// Function add() is the friend function of classes A and B
// that accesses the member variables numA and numB
bool equal(Enterprize objectA, B objectB)
{
if(objectA.numA == objectB.numB)return true;
return false;
}
int main()
{
Enterprize e;
B b;
e.numA =1;
b.numB=1;
cout<<"Check:"<<equal(e,b)<<endl;
return 0;
}