/*	Shean T. McMahon
	P231, Final Project
	Number Theory class and methods
*/

#include <iostream.h>
#include "Numbers.h"


//	Function declarations

void invalid_option();					//	Displays a message when a nonvalid entry is given
void GCD_LCM_Menu();
void Prime_Menu();


//	Global definitions

char option = NULL;						//	Control variable
char cont = 'y';						//	Continuation variable
int status;

//	Class Instances

GreatestCD Value_GCD;					//	Instance of GreatestCD
LeastCM Value_LCM;						//	Instance of LeastCM
Prime Value_Prime;						//	Instance of Prime
Twin_Prime Value_Twinprime;				//	Instance of Twinprime
Rel_Prime Value_Rel_Prime;				//	Instance of Rel_Prime
NumberPrimes Value_Num_Primes;			//	Instance of NumberPrimes
Factorization Value_Factor;				//	Instance of Factorization

int main()
{						
	while(cont == 'y')					//	Main Menu 
	{
		cout	<< "Which type of operations do you wish to perform?\n"
				<< "\n\t(g) GCD or LCM operations."
				<< "\n\t(p) Prime number tests."
				<< "\n\t(f) Prime factorization."
				<< "\n\n\tEnter your choice:	";
		
		cin >> option;
		cout << endl;

		switch(option)
		{
		case 'g':	GCD_LCM_Menu();		//	Call GCD_LCM Menu
					break;
		case 'p':	Prime_Menu();		//	Call Prime Menu
					break;
		case 'f':	Data_in(Value_Factor);	
					Value_Factor.Factor();	//	Call Factorization function
					break;
		default:	invalid_option();
					continue;
		}
	
		cout << "\nDo you wish to return to the main menu? (y/n):	";
		cin >> cont;
		cout << endl;
	}
	return 0;

}

void invalid_option()					//	Definition of invalid option function
{
	cout << "\tThat is an invalid option.\n";
}

void GCD_LCM_Menu()						//	GCD and LCM menu definition
{
	number entries;

	while ( cont == 'y')				//Run control loop
	{
		cout	<< "\nWhich GCD or LCM operation do you wish to perform?\n" 
				<< "\n\t(g) Find the GCD for two numbers."
				<< "\n\t(G) Find the GCD for n numbers."
				<< "\n\t(l) Find the LCM for two numbers."
				<< "\n\t(L) Find the LCM for n numbers."
				<< "\n\n\tEnter your choice:	";

		cin >> option;
		cout << endl;

		switch(option)
		{
		case 'g':	Data_in(Value_GCD);					
					Value_GCD.GCD();			//	Call GCD function 				
					Data_out(Value_GCD);
					break;
		case 'G':	cout << "Enter the number of values to test: ";
					cin >> entries;
					Value_GCD.GCD(entries);		//	Call GCD function for many entries
					break;
		case 'l':	Data_in(Value_LCM);
					Value_LCM.LCM();			//	Call LCM function
					Data_out(Value_LCM);
					break;
		case 'L':	cout << "Enter the number of values to test: ";
					cin >> entries;
					Value_LCM.LCM(entries);		//	Call LCM function for many entries
					break;
		default:	invalid_option();
		}
		cout << "\n\nDo you wish to perform any other GCD or LCM tests? (y/n):	";
		cin >> cont;
	}
}

void Prime_Menu()							//	Prime number menu definition
{
	while (cont == 'y')						//	Run control loop
	{	
		cout	<< "\nWhich Prime number operation do you wish to perform?\n" 
				<< "\n\t(p) Test if a number is prime."
				<< "\n\t(r) Test if two numbers are relatively prime."
				<< "\n\t(t) Determine if a twin prime exists for a given number."
				<< "\n\t(n) For a given number a, find the number of primes less than a."
				<< "\n\n\tEnter your choice:	";

		cin >> option;
		cout << endl;

		switch(option)
		{
		case 'p':	Data_in(Value_Prime);
					Value_Prime.Is_Prime();				//	Call Is_Prime
					Data_out(Value_Prime);
					break;
		case 'r':	Data_in(Value_Rel_Prime);
					Value_Rel_Prime.RelativePrime();	//	Call RelativePrime
					Data_out(Value_Rel_Prime);
					break;
		case 't':	Data_in(Value_Twinprime);
					Value_Twinprime.TwinPrime();		//	Call TwinPrime
					Data_out(Value_Twinprime);
					break;
		case 'n':	Data_in(Value_Num_Primes);
					Value_Num_Primes.Num_Primes();		//	Call Num_Primes
					Data_out(Value_Num_Primes);
					break;
		default:	invalid_option();
		}
		cout << "\n\nDo you wish to perform any other prime number tests? (y/n):	";
		cin >> cont;
	}
}

