// main.cpp

#include "rational.h"
#include <iostream>
using namespace std;

void main()
{
	Rational twoSevenths(2,7), oneSixth(1,6), result;
	// test the methods:
	result = oneSixth.add(twoSevenths);
	cout << "1/6 add 2/7 = " << result << endl;
	result = oneSixth.sub(twoSevenths);
	cout << "1/6 sub 2/7 = " << result << endl;
	result = oneSixth.mult(twoSevenths);
	cout << "1/6 mult 2/7 = " << result << endl;
	result = oneSixth.div(twoSevenths);
	cout << "1/6 div 2/7 = " << result << endl << endl;
	// test the overloaded arithmetic operators:
	result = oneSixth + 1;
	cout << "1/6 + 1 = " << result << endl;
	result = 1 + oneSixth;
	cout << "1 + 1/6 = " << result << endl;
	result = oneSixth + twoSevenths;
	cout << "1/6 + 2/7 = " << result << endl;
	result = oneSixth - twoSevenths;
	cout << "1/6 - 2/7 = " << result << endl;
	result = oneSixth * twoSevenths;
	cout << "1/6 * 2/7 = " << result << endl;
	result = oneSixth / twoSevenths;
	cout << "1/6 / 2/7 = " << result << endl << endl;
	// test unary - and the prefix and postfix ++ and -- operators:
	cout << "Testing unary operators:" << endl;
	cout << "negating 1/6 yields: " << -oneSixth << 
			" while oneSixth still holds: " << oneSixth << endl;
	cout << "Taking negation one step further with instantiation: ";
	const Rational negans = -oneSixth;
	cout << "negans holds " << negans << " (it should be -1/6)" << endl;
	cout << "(pre)incrementing 1/6 returns: " << ++oneSixth <<
			" and leaves oneSixth holding: " << oneSixth << endl;
	cout << "(pre)decrementing oneSixth returns: " << --oneSixth <<
			" and oneSixth now holds: " << oneSixth << endl;
	cout << "(post)incrementing 1/6 returns: " << oneSixth++ <<
			" and leaves oneSixth holding: " << oneSixth << endl;
	cout << "(post)decrementing oneSixth returns: " << oneSixth-- <<
			" and leaves oneSixth holding: " << oneSixth << endl << endl;
	// test the overloaded extractor operator:
	cout << "Enter a rational number of the form i/j: ";
	cin >> result;
	cout << result << " * " << twoSevenths << " = " << result * twoSevenths << endl;
	// test the overloaded relational operators:
	if (result < twoSevenths)
		cout << result << " is less than " << twoSevenths << endl;
	else
		cout << result << " is >= " << twoSevenths << endl;
	if (result <= twoSevenths)
		cout << result << " is less than or equal to " << twoSevenths << endl;
	else
		cout << result << " is > " << twoSevenths << endl;
	if (result > twoSevenths)
		cout << result << " is greater than " << twoSevenths << endl;
	else
		cout << result << " is <= " << twoSevenths << endl;
	if (result >= twoSevenths)
		cout << result << " is greater than or equal to " << twoSevenths << endl;
	else
		cout << result << " is < " << twoSevenths << endl;
	if (result == twoSevenths)
		cout << result << " is equal to " << twoSevenths << endl;
	else
		cout << result << " is != " << twoSevenths << endl;
	if (result != twoSevenths)
		cout << result << " is not equal to " << twoSevenths << endl;
	else
		cout << result << " is == " << twoSevenths << endl;

	// test arithmetic assignment operators:
	result += 1;
	cout << "result += 1 returns " << result << endl;
	result -= 1;
	cout << "result -= 1 returns " << result << endl;
	result *= 3;
	cout << "result *= 3 returns " << result << endl;
	result /= 3;
	cout << "result /= 1 returns " << result << endl;
	
}