(10%)
Determine
whether the following code is correct or not. If it is
correct, predict its output. If it is incorrect, point out the
mistake(s).
// Operator Overloading (P.331)
#include <iostream>
class CRational
{
int numerator;
int denominator;
public:
CRational(int n, int d): numerator(n), denominator(d) {}
bool operator<(CRational b)
{
if (numerator * b.denominator < denominator * b.numerator)
return true;
else
return false;
}
};
int main()
{
CRational a(2,3), b(1,2);
std::cout << (a<b?"a<b":"a>=b") << std::endl;
return 0;
}