//
// Program name:  test_rationals_v1
// Author:  B. Massingill 
//
// Purpose:  test RationalNum class (version 1)
//
#include <iostream.h>
#include "rationals_v1.h"		// class definition

// -------- function prototypes --------

// precondition:
// postcondition:  functions of RationalNum class have been tested, 
//	using p and q
void testRationalNum(RationalNum p, RationalNum q);

// precondition:
// postcondition:  p has been printed to cout, preceded by msg and
//	followed by end-of-line
void printIt(const char msg[], RationalNum p);

// -------- main program --------

int main()
{
	char prompt1[] = "Enter first number, in the form m/n, "
		"or ctrl-D to end:  ";
	char prompt2[] = "Enter second number, in the form m/n:  ";

	RationalNum p;
	RationalNum q;

	cout << prompt1;
	while (p.stream_in(cin))
	{
		cout << prompt2;
		q.stream_in(cin);
		testRationalNum(p, q);
		cout << prompt1;
	}
	cout << endl;
	return 0 ;
}

// -------- function definitions --------

void testRationalNum(RationalNum p, RationalNum q)
{
	printIt("p = ", p);
	printIt("q = ", q);
	p.reduce();
	q.reduce();
	// test comparisons
	if (equals(p, q))
		cout << "p == q" << endl;
	if (lessThan(p, q))
		cout << "p < q" << endl;
	if (greaterThan(p, q))
		cout << "p > q" << endl;
	// test reduce
	printIt("reduced p = ", p);
	printIt("reduced q = ", q);
	// test arithmetic functions
	printIt("p + q = ", add(p, q));
	printIt("p - q = ", subtract(p, q));
	printIt("p * q = ", multiply(p, q));
	printIt("p / q = ", divide(p, q));
	return;
}

void printIt(const char msg[], RationalNum p)
{
	cout << msg;
	p.stream_out(cout);
	cout << endl;
	return;
}