コード例 #1
0
ファイル: Main.cs プロジェクト: debuglevel/GaussTool
        public static void Main(string[] args)
        {
            Arguments clArgs = new Arguments(args);

            bool fromFile    = false;
            bool doRound     = false;
            bool doFrac      = false;
            bool gaussjordan = false;
            bool inverse     = false;


            //Rundung-Tests
            clArgs.AddAlias("roundtest", "rt");
            if (clArgs["roundtest"] != null)
            {
                Round.RundungTest();
                return;
            }


            //change forecolor to black
            clArgs.AddAlias("schwarz", "s");
            if (clArgs["schwarz"] != null)
            {
                Console.ForegroundColor = ConsoleColor.Black;
            }


            clArgs.AddAlias("bruch", "b");
            if (clArgs["bruch"] != null)
            {
                Console.WriteLine("· Bruchmodus aktiviert");
                doFrac = true;
            }


            clArgs.AddAlias("rundung", "r");
            int runden_stellen = 0;

            if (clArgs["rundung"] != null && Int32.TryParse(clArgs["rundung"], out runden_stellen))
            {
                Console.WriteLine("· Rundungsmodus ({0} gültige Stellen) aktiviert", runden_stellen);
                doRound = true;
            }
            else if (clArgs["rundung"] != null)
            {
                WriteLineColored("Bitte Anzahl gültiger Stellen bei -r angeben.", ConsoleColor.Red);
                return;
            }


            clArgs.AddAlias("gaussjordan", "gj");
            clArgs.AddAlias("gauss", "g");
            if (clArgs["gaussjordan"] != null && clArgs["gauss"] == null)
            {
                Console.WriteLine("· Gauß-Jordan aktiviert");
                gaussjordan = true;
            }
            else if (clArgs["gaussjordan"] != null && clArgs["gauss"] != null)
            {
                Console.WriteLine("Entweder -g oder -gj auswählen");
                return;
            }
            else
            {
                Console.WriteLine("· Gauß aktiviert");
            }


            clArgs.AddAlias("inverse", "i");
            if (clArgs["inverse"] != null)
            {
                Console.WriteLine("· Inverse aktiviert (Gauß-Jordan aktiviert)");
                gaussjordan = true;
                inverse     = true;
            }


            clArgs.AddAlias("file", "f");
            if (clArgs["file"] != null && clArgs["file"] != "")
            {
                if (File.Exists(clArgs["file"]) == false)
                {
                    Console.WriteLine("Datei " + clArgs["file"] + " existiert nicht.");
                    return;
                }

                Console.WriteLine("· File-Input aktiviert: " + clArgs["file"]);

                fromFile = true;
            }

            clArgs.AddAlias("credits", "c");
            if (clArgs["credits"] != null)
            {
                credits();
                return;
            }

            clArgs.AddAlias("help", "h");
            if ((clArgs["help"] != null) || (doRound == false && doFrac == false))
            {
                if (doRound == false && doFrac == false)
                {
                    help(true);
                }
                else
                {
                    help(false);
                }
                return;
            }

            clArgs.AddAlias("debug", "d");
            if (clArgs["debug"] != null)
            {
                debug = true;
            }


            Console.Write("Anzahl der Unbekannten: ");
            n = Convert.ToInt32(Console.ReadLine());

            Console.Write("Anzahl der Gleichungen: ");
            m = Convert.ToInt32(Console.ReadLine());


            A = new Fraction[m + 1, n + 1];
            b = new Fraction[m + 1];


            if (fromFile == true)
            {
                ReadFromFile(clArgs["file"]);
            }
            else
            {
                ReadFromConsole();
            }


            //Einheitsmatrix deklarieren und füllen
            e = new Fraction[m + 1, n + 1];
            Matrix.Einheitsmatrix(e);


            Fraction[,] copyA = new Fraction[m + 1, n + 1];
            Fraction[] copyb = new Fraction[m + 1];
            copyA = (Fraction[, ])A.Clone();
            copyb = (Fraction[])b.Clone();


            Console.WriteLine("\nDas LGS wurde wie folgt eingelesen:");
            PrintLGS(inverse);


            if (doFrac)
            {
                WriteLineColored("\nGauss mit Brüchen", ConsoleColor.Yellow);
                WriteLineColored("=================\n", ConsoleColor.Yellow);
                Gauss.DoGauss(false, gaussjordan, inverse, A, b, e);
            }

            if (doRound)
            {
                A = (Fraction[, ])copyA.Clone();
                b = (Fraction[])copyb.Clone();
                Round.Runden(A);
                Round.Runden(b);

                WriteLineColored("\nGauss mit Rundungen", ConsoleColor.Yellow);
                WriteLineColored("===================\n", ConsoleColor.Yellow);

                Console.WriteLine("Das LGS wurde wie folgt gerundet:");
                PrintLGS(inverse);
                Console.WriteLine();

                Gauss.DoGauss(true, gaussjordan, inverse, A, b, e);
            }
        }