/* Main */ #include #include "Number.h" #include "Rational.h" using std::cout; using std::cin; using std::endl; Rational yellowSubRoutine( Rational x ) { cout << "NoOfNumbers (YSR): " << Number::noOfNumbers() << endl; if ( !x.isPositive() ) x = x * Rational( -1 ); x = Rational( 1, 1 ) / x; return x; } int main() { Rational a, b( 7 ), c( 4, 3 ), d=c; cout << "Value from default numerator and denominator: "; a.write(); cout << endl; cout << "Value from default denominator: "; b.write(); cout << endl; cout << "Value from constructor call with two parameters: "; c.write(); cout << endl; cout << "Value from copy constructor: "; d.write(); cout << endl; cout << "7 / FourThirds: "; ( b / c ).write(); // same as ( b.operator/(c) ).write cout << endl; cout << "NoOfNumbers: " << Number::noOfNumbers() << endl; while ( true ) { Rational input, result; cout << "Please enter a rational number (exit with '0 1') : " << endl; input.read(); if ( input == Rational( 0, 1 ) ) break; // abort while loop result = yellowSubRoutine( input ); cout << "Positive Inverse: "; result.write(); cout << endl; cout << "NoOfNumbers: " << Number::noOfNumbers() << endl; } return 0; }