Ejemplo n.º 1
0
    public virtual void Add(Rational other) {
      Contract.Requires(other != null);
      int newN = this.Numerator * other.Denominator + other.Numerator * this.Denominator;
      int newD = this.Denominator * other.Denominator;

      this.Numerator = newN;
      this.Denominator = newD;
    }
Ejemplo n.º 2
0
    static void Main(string[] args)
    {
      var r1 = new Rational(10, 5);

      Console.WriteLine("r1 truncated = {0}", r1.Truncate());

      var r2 = new PositiveDenominatorRational(5, 3);

      r2.Divide(-5);

      var r3 = new PositiveDenominatorRational(5, 0);

      var r4 = new NormalizedRational(10, 2);

      r4.Divide(0);

      Console.WriteLine("r1 truncated = {0}", r3.Truncate());
    }