示例#1
0
        public static Matrix simulFill(int a)
        {
            Matrix b = new Matrix(a, a + 1);

            if (a == 2 || a == 3)
            {
                if (a == 2)
                {
                    Console.WriteLine("\r\nEnter the values (In the form aX + bY = c)!");
                }
                else
                {
                    Console.WriteLine("\r\nEnter the values (In the form aX + bY + cZ = c)!");
                }
                for (int i = 0; i < a; i++)
                {
                    Console.Write("\r\nEnter the co-efficient of X: ");
                    b.matrix[i, 0] = CheckClass.checkDouble(Console.ReadLine());
                    Console.Write("Enter the co-efficient of y: ");
                    b.matrix[i, 1] = CheckClass.checkDouble(Console.ReadLine());
                    if (a == 3)
                    {
                        Console.Write("Enter the co-efficient of Z: "); b.matrix[i, 2] = CheckClass.checkDouble(Console.ReadLine());
                    }
                    Console.Write("Enter the constant term: ");
                    if (a == 2)
                    {
                        b.matrix[i, 2] = CheckClass.checkDouble(Console.ReadLine());
                    }
                    else
                    {
                        b.matrix[i, 3] = CheckClass.checkDouble(Console.ReadLine());
                    };
                }
            }
            else
            {
                Console.WriteLine("\r\nWrong dimension. Only for 2 or 3 unknowns!\r\n");
            }
            return(b);
        }
示例#2
0
        /// <summary>
        /// To test functionalities
        /// </summary>
        public static void run()
        {
            Console.WriteLine("An application to carry out arithmetic operations on fractions!\r\n");
            Console.WriteLine("What Operation do you wish to perform? ");
            Console.WriteLine("Enter '1' for addition, '2' for substraction,");
            Console.WriteLine("'3' for multiplication, '4' for division,");
            Console.WriteLine("'5' to change a fraction to a decimal, '6' to change a decimal to a fraction,");
            Console.WriteLine("and '7' to reduce a fraction to its lowest term.");
            string cont = "y";

            while (cont.ToUpper() == "Y" || cont.ToUpper() == "YES")
            {
                Console.Write("\r\nEnter the operation code for your operation: ");
                string chkInt = Console.ReadLine();
                while (!Regex.IsMatch(chkInt, "^(1|2|3|4|5|6|7)$") && chkInt.ToUpper() != "exit".ToUpper())
                {
                    Console.Write("Please enter an appropriate operation number (or 'exit' to stop program): ");
                    chkInt = Console.ReadLine();
                }
                if (chkInt.ToUpper() == "exit".ToUpper())
                {
                    goto end;                                        //Environment.Exit(0);
                }
                int op = int.Parse(chkInt);
                Console.Write("\r\nOperation code: " + op);
                string ops = "";
                if (op == 1)
                {
                    ops = "Sum";
                }
                else if (op == 2)
                {
                    ops = "Difference";
                }
                else if (op == 3)
                {
                    ops = "Multiplication";
                }
                else if (op == 4)
                {
                    ops = "Division";
                }
                else if (op == 5)
                {
                    ops = "Convert fraction to decimal";
                }
                else if (op == 6)
                {
                    ops = "Convert decimal to fraction";
                }
                else
                {
                    ops = "Lowest term reduction";
                }
                Console.WriteLine(" <=> (" + ops + " Operation).");
                Console.WriteLine("\r\nNOTE: You must enter a fraction in the form x/y\r\n");
                if (op >= 1 && op <= 4)
                {
                    Console.Write("Enter the first fraction: ");
                    Fraction a = Console.ReadLine();
                    Console.Write("\r\nEnter the second fraction: ");
                    Fraction b    = Console.ReadLine();
                    Fraction c    = new Fraction();
                    string   sign = "";
                    if (op == 1)
                    {
                        c = a + b; sign = " + ";
                    }
                    else if (op == 2)
                    {
                        c = a - b; sign = " - ";
                    }
                    else if (op == 3)
                    {
                        c = a * b; sign = " * ";
                    }
                    else
                    {
                        c = a / b; sign = " / ";
                    }
                    Console.WriteLine("\r\nFirst Fraction: " + a.ToString());
                    Console.WriteLine("Second Fraction: " + b.ToString());
                    Console.WriteLine("Answer: " + c.ToString() + "\r\n");
                    Console.WriteLine(a.ToString() + sign + b.ToString() + " = " + c.ToString());
                }
                if (op == 5 || op == 6 || op == 7)
                {
                    if (op == 5)
                    {
                        Console.Write("Enter the fraction: ");
                        Fraction a = Console.ReadLine();
                        Console.WriteLine("\r\nThe decimal equivalent is: " + (double)a);
                    }
                    else if (op == 6)
                    {
                        Console.Write("Enter the decimal: ");
                        Fraction a = CheckClass.checkDouble(Console.ReadLine());
                        Console.WriteLine("\r\nThe decimal equivalent is: " + a.ToString());
                    }
                    else
                    {
                        Console.Write("Enter the unresolved fraction: ");
                        Fraction a = Console.ReadLine();
                        Console.WriteLine("\r\nThe resolved fraction is: {0}", Fraction.lowestTerm(a));
                    }
                }
                Console.Write("\r\nDo you wish to continue? Enter 'y' for yes and 'n' for no: ");
                cont = Console.ReadLine();
            }
            end : Console.WriteLine("\r\nTHE END!      (press any key to exit)");
            Console.ReadKey();
        }
示例#3
0
        public static void run()
        {
            //    Console.WriteLine("A program to multiply two matrices \r\n");
            //    Console.WriteLine("\r\nFirst MatriRow\r\n");
            //    Matrix a = new Matrix();
            //    Console.Write("Enter the Row-dimension: ");
            //    a.Row = CheckClass.checkInt(Console.ReadLine());
            //    Console.Write("Enter the Column-dimension: ");
            //    a.Column = CheckClass.checkInt(Console.ReadLine());
            //    a.fill();
            //    Console.WriteLine("\r\nSecond MatriRow\r\n");
            //    Matrix b = new Matrix();
            //    Console.Write("Enter the Row-dimension: ");
            //    b.Row = CheckClass.checkInt(Console.ReadLine());
            //    Console.Write("Enter the Column-dimension: ");
            //    b.Column = CheckClass.checkInt(Console.ReadLine());
            //    b.fill();
            //    //MatriRow c = new MatriRow();
            //    Matrix c = a * b;
            //    Console.WriteLine("");
            //    Console.WriteLine("The first matriRow is: " + a);
            //    Console.WriteLine("The second matriRow is: " + b);
            //    Console.WriteLine("Their product is: " + c);
            //    Console.ReadKey();
            Console.WriteLine("A program to solve simultaneous equations!");
            string cont = "y";

            while (cont.ToUpper() == "Y" || cont.ToUpper() == "YES")
            {
                Console.Write("\r\nHow many variables/unknowns: ");
                int var = CheckClass.checkInt(Console.ReadLine());
                if (var == 2 || var == 3)
                {
                    try
                    {
                        Matrix simul = Matrix.simulFill(var);
                        Matrix ans;
                        if (var == 2)
                        {
                            ans = Matrix.simul2(simul); Console.Write("\r\nValue of X and Y is: {0, 30}", ans);
                        }
                        else
                        {
                            ans = Matrix.simul3(simul); Console.Write("\r\nValue of X and Y is: {0, 30}", ans);
                        }
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine("\r\nError: " + ex.Message);
                        Console.WriteLine("Stack Trace: " + ex.StackTrace);
                    }
                }
                else
                {
                    Console.WriteLine("Wrong variable input. Can resolve 2 or 3 variables/unknowns");
                }
                Console.Write("\r\nDo you wish to continue? Enter 'y' for yes and 'n' for no: ");
                cont = Console.ReadLine();
            }
            Console.WriteLine("\r\nTHE END!    Press any key to exit.");
            Console.ReadKey();
        }