//**************************************************************************// // Authors: James P. Cohoon and Jack W. Davidson // // Date: 7/15/96 // // Version: 1.0b // // Modified: 01/30/97 by Michael A. Redmond // uses simplification of rationals capability added to // rational class by MAR // 12/02/98 by MAR // uses many other enhanced features of rational class //**************************************************************************// // Program 9.1: Demonstrate some member functions and // auxiliary operators of the Rational ADT #include #include "redmo5-rational.h" int main() { Rational r; Rational s; /* Rational sum1(0,1); Rational sum2(0,1); */ for (int i = 0; i < 4; i++) { cout << "Enter rational number (a/b): " << flush; cin >> r; cout << "Enter rational number (a/b): " << flush; cin >> s; Rational Sum = r + s; Rational Product = r * s; Rational Sub = r - s; Rational Divide = r / s; bool eq = (r == s); bool lessthan = (r < s); bool lessthaneq = (r <= s); bool greaterthan = (r > s); bool greaterthaneq = (r >= s); /* sum1 += r; sum2 += s; */ cout << endl; cout << "Your numbers are " << r << " and " << s << endl; cout << endl; cout << r << " + " << s << " = " << Sum << endl; cout << r << " * " << s << " = " << Product << endl; cout << r << " - " << s << " = " << Sub << endl; cout << r << " / " << s << " = " << Divide << endl; cout << r << " == " << s << " = " << eq << endl; cout << r << " < " << s << " = " << lessthan << endl; cout << r << " <= " << s << " = " << lessthaneq << endl; cout << r << " > " << s << " = " << greaterthan << endl; cout << r << " >= " << s << " = " << greaterthaneq << endl; /* cout << "Subtotal for first Numbers: " << sum1 << endl; cout << "Subtotal for second Numbers: " << sum2 << endl; */ } return 0; }