a) Write a friend function called \'equal\' for the class \'Enterprize\' that wa
ID: 3821066 • Letter: A
Question
a) 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. b) 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
since the structure of the enterprize calss is not given so assuming some points
let suppose the class Enterprize has two fields
a) categories of type int
b) HEB of type string
1)
the two objects of class are equal if the value for each data memeber of the two objects are equal, so we will comparing the value of the data memeber in equal() method to check if both objects are equal
first declare the friendFunction in the class
friend bool equal(Enterprize a , EnterPrize b);
and outsie the class the definationn of the function is as:
bool equal(Enterprize a , EnterPrize b)
{
if(a.categories == b.categories) // comparing int type
{
if(strcmp(a.HEB, b.HEB)==0) //comparing the string variables for class Enterprize
{
cout<<"both objects are equal"<<endl;
return true;
}
}
else
{
cout<<"Objects are not equal"<<endl;
return false;
}
return false;
}
2)
bool Enterprize::operator==(Enterprize a){
if(a.categories == this.categories) // comparing int type
{
if(strcmp(a.HEB, this.HEB)==0) //comparing the string variables for class Enterprize
{
cout<<"both objects are equal"<<endl;
return true;
}
}
else
{
cout<<"Objects are not equal"<<endl;
return false;
}
return false;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.