// Example of overloaded operator functions // Original authors: Brenda Parker & Hyrum Carroll // Extended by: #include using namespace std; /* Class to represent a fraction (with it's numerator and denominator stored * separately) and corresponding operations on a fraction (e.g., adding another * fraction to this one, etc.). */ class Fraction{ }; int main(){ Fraction aFraction(2,3); Fraction bFraction(3,8); Fraction cFraction; cout << "aFraction: " << aFraction << endl; cout << "bFraction: " << bFraction << endl; cFraction = aFraction + bFraction; cout << aFraction << " + " << bFraction << " = " << cFraction << endl; cFraction = bFraction - aFraction; cout << bFraction << " - " << aFraction << " = " << cFraction << endl; cout << "++(" << aFraction << ") = "; cFraction = ++aFraction; cout << cFraction << endl; cout << "(" << bFraction << ")++ = "; cFraction = bFraction++; cout << cFraction << endl; cin >> aFraction; cout << "You entered: " << aFraction << endl; cin >> bFraction; cout << "You entered: " << bFraction << endl; if( aFraction == bFraction){ cout <<"The fractions are equal\n"; }else{ if( aFraction > bFraction){ cout << aFraction << " is larger than " << bFraction << endl; }else if( aFraction < bFraction){ cout << aFraction << " is smaller than " << bFraction << endl; }else{ cout << "ERROR: " << aFraction << " is not ==, > nor < than " << bFraction << endl; } } return 0; }