// driver for problem 8.17, Deitel and Deitel #include "Rational.h" void print(const Rational &R); // demonstrate Rational numbers, etc. int main() { Rational w(4), x(7,6), y(3,8), z, copy(x); cout << "The copy object looks just like its parameter, copy = "; print(copy); cout << endl; // z = x + y; z = plusOp(x,y); // cout << x << " + " << y << " = " << z << endl; print(x); cout << " + "; print(y); cout << " = "; print(z); cout << endl; // z = w + y; z = plusOp(w,y); // cout << w << " + " << y << " = " << z << endl; print(w); cout << " + "; print(y); cout << " = "; print(z); cout << endl; // z = x - y; z = minusOp(x,y); // cout << x << " - " << y << " = " << z << endl; print(x); cout << " - "; print(y); cout << " = "; print(z); cout << endl; // z = x * y; z = starOp(x,y); // cout << x << " * " << y << " = " << z << endl; print(x); cout << " * "; print(y); cout << " = "; print(z); cout << endl; // z = x / y; z = slashOp(x,y); // cout << x << " / " << y << " = " << z << endl; print(x); cout << " / "; print(y); cout << " = "; print(z); cout << endl; /* z = x + 5; cout << x << " + " << 5 << " = " << z << endl; //ERROR -- no match for operator +(int, class Rational) // z = 5 + x; z = Rational(5) + x; cout << 5 << " + " << x << " = " << z << endl; //ERROR -- no match for operator -(class Rational, class Rational) // z -= x; cout << x << " + " << y; x += y; cout << " = the now changed " << x << endl; */ return 0; } void print(const Rational &R) { cout << R.getNumerator() << '/' << R.getDenominator(); }