本文整理汇总了C#中Lab301.Fraction.setValue方法的典型用法代码示例。如果您正苦于以下问题:C# Fraction.setValue方法的具体用法?C# Fraction.setValue怎么用?C# Fraction.setValue使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Lab301.Fraction
的用法示例。
在下文中一共展示了Fraction.setValue方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Fraction
public static Fraction operator +(Fraction a,Fraction b)
{
Fraction c = new Fraction();
int lcm = LCM(a.Denom, b.Denom);
c.setValue(a.Numer * (lcm / a.Denom) + b.Numer * (lcm / b.Denom), lcm);
return c;
}
示例2: Fraction
public static Fraction operator +(Fraction a, Fraction b)
{
Fraction c = new Fraction();
c.Numerator = (a.Numerator * b.Denominator) + (b.Numerator * a.Denominator);
c.Denominator = (a.Denominator * b.Denominator);
c.setValue(c.Numerator, c.Denominator);
return c;
}
示例3: Main
public static void Main(string[] args)
{
Fraction r1 = new Fraction();
Fraction r2 = new Fraction(2);
Fraction r3 = new Fraction(3,9);
Console.WriteLine ("***** " + Fraction.Count + " Fraction objects have been created *****");
Fraction r4 = r1+r2;
Fraction r5 = r2-r3;
Fraction r6 = new Fraction(100,50);
r6 += r2;
// Fraction r7 = new Fraction(r3); // case#1
Fraction r7 = r3; // case#2
r7++;
Console.WriteLine ("***** " + Fraction.Count + " Fraction objects have been created *****");
Fraction r8 = 10 - (new Fraction(80,40));
Fraction r9 = (new Fraction(5,25)) + 1;
Console.WriteLine ("***** " + Fraction.Count + " Fraction objects have been created *****");
r1.output();
r2.output();
r3.output();
r4.output();
r5.output();
r6.output();
r7.output();
r8.output();
r9.output();
/*Console.WriteLine (r2);
Console.WriteLine (r3);
Console.WriteLine (r4);
Console.WriteLine (r5);
Console.WriteLine (r6);
Console.WriteLine (r7);
Console.WriteLine (r8);
Console.WriteLine (r9);*/
Console.WriteLine (r2==r4);
Console.WriteLine (r4.Equals (r2)); // Equals method must be overriden
Console.WriteLine (r2!=r4);
r3.setValue (10,12/3*0);
r3.output();
//Console.WriteLine (r3);
Console.WriteLine ("***** " + Fraction.Count + " Fraction objects have been created *****");
Console.WriteLine("GCD of 3650 and 360: " + Fraction.GCD (3650,360));
Console.WriteLine("GCD of 3600 and 360: " + Fraction.GCD (3600,360));
}
示例4: Fraction
public static Fraction operator +(Fraction x, int y)
{
Fraction a = new Fraction();
a.setValue((x.Numer+(y*x.Demon)), x.Demon);
return a;
}
示例5: Fraction
public static Fraction operator -(Fraction a,int b){
Fraction c = new Fraction(b);
c.setValue(c.Numerator - (b*c.Denominator), c.Denominator);
return c;
}