コード例 #1
0
ファイル: Program.cs プロジェクト: KalliKall/Skoli
        static void Main(string[] args)
        {
            string action = string.Empty;
            string fractionA = string.Empty;
            string fractionB = string.Empty; do
            {
                Console.WriteLine("Enter +, -, * or / (q to quit)");
                action = Console.ReadLine();
                if (!(action == "q" || action == "Q"))
                {
                    Console.WriteLine("Enter the first fraction (example: 1/2):");
                    fractionA = Console.ReadLine();
                    Console.WriteLine("Enter the second fraction (example: 5/9):");
                    fractionB = Console.ReadLine();

                    Fraction A = new Fraction(fractionA);
                    Fraction B = new Fraction(fractionB);
                    Fraction result = new Fraction();

                    switch (action)
                    {
                        case "+": result = A + B;
                            break;
                        case "-": result = A - B;
                            break;
                        case "*": result = A * B;
                            break;
                        case "/": result = A / B;
                            break;
                    }
                    Console.WriteLine("The result is: " + result);
                }
            } while (!(action == "q" || action == "Q"));
        }
コード例 #2
0
ファイル: Fraction.cs プロジェクト: KalliKall/Skoli
        public static Fraction operator -(Fraction a, Fraction b)
        {
            Fraction result = new Fraction();

            result.Numerator = (a.Numerator * b.Denominator) - (a.Denominator * b.Numerator);
            result.Denominator = a.Denominator * b.Denominator;

            result.Normalize();

            return result;
        }
コード例 #3
0
 public bool IsEqualTo(Fraction secondFraction)
 {
     return(secondFraction.Denominator / secondFraction.Numerator == Denominator / Numerator);
 }