rendered paste body int top;
int bottom;
public Fraction(int top, int bottom)
{
this.top = top;
this.bottom = bottom;
}
public Fraction Add(int newTop, int newBottom)
{
if (newBottom == this.bottom)
{
return new Fraction((this.top + newTop), this.bottom);
}
Fraction tempFractionA = new Fraction((this.top * newBottom), (this.bottom * newBottom));
Fraction tempFractionB = new Fraction((newTop * this.bottom), (newBottom * this.bottom));
return tempFractionA.Add(tempFractionB);
}
public Fraction Add(Fraction newFraction)
{
return this.Add(newFraction.top, newFraction.bottom);
}
public Fraction Add(int newTop)
{
return this.Add(newTop, 1);
}
public Fraction Subtract(int newTop, int newBottom)
{
if (newBottom == this.bottom)
{
return new Fraction((this.top - newTop), this.bottom);
}
Fraction tempFractionA = new Fraction((this.top * newBottom), (this.bottom * newBottom));
Fraction tempFractionB = new Fraction((newTop * this.bottom), (newBottom * this.bottom));
return tempFractionA.Subtract(tempFractionB);
}
public Fraction Subtract(Fraction newFraction)
{
return this.Subtract(newFraction.top, newFraction.bottom);
}
public Fraction Subtract(int newTop)
{
return this.Subtract(newTop, 1);
}
public Fraction Multiply(int newTop, int newBottom)
{
return new Fraction((this.top * newTop), (this.bottom * newBottom));
}
public Fraction Multiply(Fraction newFrac)
{
return this.Multiply(newFrac.top, newFrac.bottom);
}
public Fraction Multiply(int newTop)
{
return this.Multiply(newTop, 1);
}
public Fraction Divide(int newTop, int newBottom)
{
return new Fraction((this.top * newBottom), (this.bottom * newTop));
}
public Fraction Divide(Fraction newFrac)
{
return this.Divide(newFrac.top, newFrac.bottom);
}
public Fraction Divide(int newTop)
{
return this.Divide(newTop, 1);
}
public Fraction Reduce()
{
foreach (int prime in primeArray)
{
if (this.bottom % prime == 0 && this.top % prime == 0)
{
return new Fraction((this.top / prime), (this.bottom / prime));
}
}
return new Fraction(this.top, this.bottom);
}
public Fraction Convert(double number)
{
double tempTop = (number * Math.Pow(10, (number.ToString().Length - 1)));
double tempBottom = (Math.Pow(10, tempTop.ToString().Length));
Fraction tempFraction = new Fraction(int.Parse(tempTop.ToString()), int.Parse(tempBottom.ToString()));
return tempFraction.Reduce();
}
public Fraction Pow(double Power)
{
return new Fraction(int.Parse(Math.Pow(double.Parse(this.top.ToString()), Power).ToString()), int.Parse(Math.Pow(double.Parse(this.bottom.ToString()), Power).ToString()));
}
public override string ToString()
{
return this.top + "/" + this.bottom;
}