コード例 #1
0
ファイル: Fraction.cs プロジェクト: rjlgithub/CCTB-245
        public static Fraction operator +(Fraction p1, Fraction p2)
        {
            Fraction newFraction = new Fraction(p1.Numerator, p1.Denominator);
            newFraction.Numerator = newFraction.Numerator * p2.Denominator + p2.Numerator * newFraction.Denominator;
            newFraction.Denominator = newFraction.Denominator * p2.Denominator;

            return newFraction;
        }
コード例 #2
0
ファイル: Program.cs プロジェクト: rjlgithub/CCTB-245
        static void Main(string[] args)
        {
            Fraction oneHalf = new Fraction(1, 2);
            Fraction oneQuarter = new Fraction(1, 4);

            Fraction overLoadedFraction = oneHalf + oneQuarter;

            Console.WriteLine("{0} + {1} = {2}", oneHalf.ToString(), oneQuarter.ToString(), overLoadedFraction.ToString());
        }