Esempio n. 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);
        }
Esempio n. 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();
        }