// Implementation file: GcdProblemSolver.cpp
// Description: Command-line calculator for greatest common divisor
//					 of integer pairs.
// Date: 2011-05-12 Khu

#include "GcdProblemQAI.hpp"

#include <cstdlib>
#include <iostream>

	int main (int argc, char * argv[])
	// Given integer pairs as command arguments,
	// print their greatest common divisor.
	{
		if (argc < 3)
		{
			std::cout
				<< "Please call the gcd problem solver"
				<< "with integer pairs as arguments!" << std::endl;
		}
		else
		{
			GcdProblemQAI * gcd_problem = new GcdProblemQAI();
			int p, q;
			for (int i = 2; i < argc; i += 2)
			{
				p = std::atoi(argv[i-1]);
				q = std::atoi(argv[i]);
				gcd_problem->set(p, q);
				std::cout
					<< "gcd(" << p << ", " << q << ") = "
					<< gcd_problem->solution().gcd() << std::endl;
			}
			delete gcd_problem;
		}
		return 0;
	}
