namespace Gcd { /// /// Command-line calculator for greatest common divisor of two integers. /// public class GcdClient { protected static PairWithGcdR pairRR = new PairWithGcdRR(0, 0); protected static PairWithGcdR pairRI = new PairWithGcdRI(0, 0); protected static PairWithGcdV pairVR = new PairWithGcdVR(); protected static PairWithGcdV pairVI = new PairWithGcdVI(); protected const string Hint = "Please call the gcd client with two integer arguments! "; public static void Write (string name, int p, int q, int gcd) { System.Console.WriteLine("Gcd" + name + " (" + p + ", " + q + ") = " + gcd); } public static void Main (string[] args) { if (args.Length < 2) { System.Console.WriteLine("Missing Argument. " + Hint); } else { try { int p = System.Convert.ToInt32(args[0]); int q = System.Convert.ToInt32(args[1]); pairRR.Set(p, q); pairRI.Set(p, q); pairVR.Set(p, q); pairVI.Set(p, q); Write("RR", p, q, pairRR.Gcd()); Write("RI", p, q, pairRI.Gcd()); Write("VR", p, q, pairVR.Gcd()); Write("VI", p, q, pairVI.Gcd()); } catch (System.Exception e) { System.Console.WriteLine("Wrong Argument. " + Hint + e.Message); } } } } }