Question
Write a < < operator that allows for easy output of EvenNumbers to cout, a file, or any other stream. The proper operator is dclared
Write a<< operator that allows for easy output of EvenNumbers to cout, a file, or any other stream. The proper operator is dclared as a friend to the class, you need to implement it.
Code:
#include
class EvenNumber { public: explicit EvenNumber(int n) { value = (n % 2 == 0) ? n : n - 1; //must be even }
friend ostream& operator<<(ostream& theStream, const EvenNumber& number);
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);
cout << n1 << "----" << endl;
return 0;
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started