Question: Write an == function that determines if two EvenNumber objects are equal. We will define them as being equal if they have the same value

Write an == function that determines if two EvenNumber objects are equal. We will define them as being equal if they have the same value (seems logical enough). The operator is declared in the class, you need to implement it after the class declaration.

#include using namespace std;

class EvenNumber { public: EvenNumber(int n) { value = (n % 2 == 0) ? n : n - 1; //must be even }

bool operator==(const EvenNumber& other) const;

int getValue() const { return value; } private: int value; };

//Do not modify anything on or above the line below this //YOUR_CODE_BELOW

//YOUR_CODE

//YOUR_CODE_ABOVE //Do not modify anything on or below the line above this

int main() { EvenNumber n1(6); EvenNumber n2(6); EvenNumber n3(8);

cout << std::boolalpha; //print bools as true/false cout << (n1 == n2) << endl; cout << (n1 == n3) << endl;

return 0; }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!