// rationaltest.cpp -- test program for rational arithmetic package. // cse143 assignment 1 sample solution, Jan. 1999. HP #include #include "rational.h" void main(void){ Rational r1, r2; int a,b,c,d; cout << "Enter fractions a/b and c/d as four integers a b c d.\n"; cout << "Enter four zeros to stop:" << endl; cout << "? "; cin>> a >> b >> c >> d; while (a!=0 || b!=0 || c!=0 || d!=0) { r1 = Rational(a,b); r2 = Rational(c,d); cout << endl; cout << "Numerator of " << r1 << " == " << num(r1) << endl; cout << "Denominator of " << r1 << " == " << denom(r1) << endl; cout << '-' << r1 << " == " << -r1 << endl; cout << r1 << " + " << r2 << " == " << r1+r2 << endl; cout << r1 << " - " << r2 << " == " << r1-r2 << endl; cout << r1 << " * " << r2 << " == " << r1*r2 << endl; cout << r1 << " / " << r2 << " == " << r1/r2 << endl; cout << r1 << " > " << r2 << " == " << (r1> r2) << endl; cout << r1 << " >= " << r2 << " == " << (r1>=r2) << endl; cout << r1 << " == " << r2 << " == " << (r1==r2) << endl; cout << r1 << " != " << r2 << " == " << (r1!=r2) << endl; cout << r1 << " <= " << r2 << " == " << (r1<=r2) << endl; cout << r1 << " < " << r2 << " == " << (r1< r2) << endl; cout << "\n? "; cin >> a >> b >> c >> d; } cout << "\nbye." << endl; }