using System;
using System.Collections.Generic;
using System.Dynamic;
using System.Reflection.Metadata.Ecma335;
using System.Text;
namespace ConsoleApp3
{
public class PhanSo
{
private int tu;
private int mau;
// constructor
public PhanSo()
{
this.tu = 0;
this.mau = 1;
}
public PhanSo(int tu, int mau)
{
this.tu = tu;
this.mau = mau;
}
// set,get
public int Tu
{
get { return tu; }
set { tu = value; }
}
public int Mau
{
get { return mau; }
set { mau = value; }
}
public static PhanSo operator +(PhanSo phanso1, PhanSo phanso2)
{
return new PhanSo
{
Tu = phanso1.Tu * phanso2.Mau + phanso1.Mau * phanso2.Tu,
Mau = phanso1.Mau * phanso2.Mau
};
}
public static PhanSo operator -(PhanSo phanso1, PhanSo phanso2)
{
return new PhanSo
{
Tu = phanso1.Tu * phanso2.Mau - phanso2.Tu * phanso1.Mau,
Mau = phanso1.Mau * phanso2.Mau
};
}
public static PhanSo operator *(PhanSo phanso1, PhanSo phanso2)
{
return new PhanSo
{
Tu = phanso1.Tu * phanso2.Tu,
Mau = phanso1.Mau * phanso2.Mau
};
}
public static PhanSo operator /(PhanSo phanso1, PhanSo phanso2)
{
return new PhanSo
{
Tu = phanso1.Tu * phanso2.Mau,
Mau = phanso1.Mau * phanso2.Tu
};
}
public void hoanvi(int a, int b)
{
int temp = a;
a = b;
b = temp;
}
public static int USCLN(int a, int b)
{
if (a == 0 || b == 0)
return a + b;
while (a != b)
if (a > b)
a = a - b;
else
b = b - a;
return a;
}
public bool latoigian()
{
return USCLN(tu, mau) == 1;
}
public PhanSo rutgon()
{
if (latoigian())
{
return this;
}
else
{
return new PhanSo
{
Tu = Tu / USCLN(Tu, Mau),
Mau = Mau / USCLN(Tu, Mau)
};
}
}
}
}