Class CPHANSO
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Bai22_honso
{
class CPHANSO
{
int Tu, Mau;
public int Mau1
{
get { return Mau; }
set { Mau = value; }
}
public int Tu1
{
get { return Tu; }
set { Tu = value; }
}
public void nhap()
{
Console.Write("Nhap tu so: ");
Tu = int.Parse(Console.ReadLine());
Console.Write("Nhap mau so: ");
Mau = int.Parse(Console.ReadLine());
}
public CPHANSO()
{
}
public CPHANSO(int tu, int mau)
{
Tu=tu;
Mau=mau;
}
public CPHANSO(CPHANSO a)
{
Tu=a.Tu;
Mau=a.Mau;
}
public int UCLN(int a, int b)
{
int t;
while (b != 0)
{
t = a;
a = b;
b = t % b;
}
return a;
}
public CPHANSO RutGon()
{
int t = UCLN(Tu, Mau);
int a = Tu / t;
int b = Mau / t;
CPHANSO k = new CPHANSO(a, b);
return k;
}
public void Xuat()
{
Console.WriteLine(Tu + "/" + Mau);
}
public CPHANSO tong(CPHANSO p)
{
int t = p.Tu * Mau + Tu * p.Mau;
int m = p.Mau * Mau;
CPHANSO k=new CPHANSO();
return k.RutGon();
}
public CPHANSO hieu(CPHANSO p)
{
int t = Tu * p.Mau - p.Tu * Mau;
int m = p.Mau * Mau;
CPHANSO k = new CPHANSO(t, m);
return k.RutGon();
}
public CPHANSO tich(CPHANSO p)
{
int t = Tu * p.Tu;
int m = p.Mau * Mau;
CPHANSO k = new CPHANSO(t, m);
return k.RutGon();
}
public CPHANSO thuong(CPHANSO p)
{
int t = Tu * p.Mau;
int m = Mau*p.Tu;
CPHANSO k = new CPHANSO(t, m);
return k.RutGon();
}
public static CPHANSO operator +(CPHANSO a, CPHANSO b)
{
int t = a.Tu * b.Mau + b.Tu * a.Mau;
int m = a.Mau * b.Mau;
CPHANSO k=new CPHANSO(t,m);
return k.RutGon();
}
public CHONSO honso()
{
CHONSO c = new CHONSO();
c.Nguyen = Tu / Mau;
c.Tu = Tu % Mau;
c.Mau = Mau;
return c;
}
}
}
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Bai22_honso
{
class CPHANSO
{
int Tu, Mau;
public int Mau1
{
get { return Mau; }
set { Mau = value; }
}
public int Tu1
{
get { return Tu; }
set { Tu = value; }
}
public void nhap()
{
Console.Write("Nhap tu so: ");
Tu = int.Parse(Console.ReadLine());
Console.Write("Nhap mau so: ");
Mau = int.Parse(Console.ReadLine());
}
public CPHANSO()
{
}
public CPHANSO(int tu, int mau)
{
Tu=tu;
Mau=mau;
}
public CPHANSO(CPHANSO a)
{
Tu=a.Tu;
Mau=a.Mau;
}
public int UCLN(int a, int b)
{
int t;
while (b != 0)
{
t = a;
a = b;
b = t % b;
}
return a;
}
public CPHANSO RutGon()
{
int t = UCLN(Tu, Mau);
int a = Tu / t;
int b = Mau / t;
CPHANSO k = new CPHANSO(a, b);
return k;
}
public void Xuat()
{
Console.WriteLine(Tu + "/" + Mau);
}
public CPHANSO tong(CPHANSO p)
{
int t = p.Tu * Mau + Tu * p.Mau;
int m = p.Mau * Mau;
CPHANSO k=new CPHANSO();
return k.RutGon();
}
public CPHANSO hieu(CPHANSO p)
{
int t = Tu * p.Mau - p.Tu * Mau;
int m = p.Mau * Mau;
CPHANSO k = new CPHANSO(t, m);
return k.RutGon();
}
public CPHANSO tich(CPHANSO p)
{
int t = Tu * p.Tu;
int m = p.Mau * Mau;
CPHANSO k = new CPHANSO(t, m);
return k.RutGon();
}
public CPHANSO thuong(CPHANSO p)
{
int t = Tu * p.Mau;
int m = Mau*p.Tu;
CPHANSO k = new CPHANSO(t, m);
return k.RutGon();
}
public static CPHANSO operator +(CPHANSO a, CPHANSO b)
{
int t = a.Tu * b.Mau + b.Tu * a.Mau;
int m = a.Mau * b.Mau;
CPHANSO k=new CPHANSO(t,m);
return k.RutGon();
}
public CHONSO honso()
{
CHONSO c = new CHONSO();
c.Nguyen = Tu / Mau;
c.Tu = Tu % Mau;
c.Mau = Mau;
return c;
}
}
}
class CHONSO
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Bai22_honso
{
class CHONSO
{
int nguyen, tu, mau;
#region propety
public int Mau
{
get { return mau; }
set { mau = value; }
}
public int Tu
{
get { return tu; }
set { tu = value; }
}
public int Nguyen
{
get { return nguyen; }
set { nguyen = value; }
}
#endregion
public void nhap()
{
Console.Write("Nhap phan nguyen: ");
nguyen=int.Parse(Console.ReadLine());
Console.Write("Nhap tu so: ");
tu=int.Parse(Console.ReadLine());
Console.Write("Nhap mau so: ");
mau=int.Parse(Console.ReadLine());
}
public CHONSO()
{
}
public CHONSO(int a,int b,int c)
{
nguyen=a;
tu=b;
mau=c;
}
public CHONSO(CHONSO b)
{
nguyen=b.nguyen;
tu=b.tu;
mau=b.mau;
}
public void xuat()
{
Console.Write("{0}:{1}/{2}\n", nguyen, tu, mau);
}
public CPHANSO chuyenps()
{
CPHANSO c = new CPHANSO();
c.Tu1 = tu * mau + tu;
c.Mau1= mau;
return c;
}
public static CHONSO operator +(CHONSO a, CHONSO b)
{
CHONSO kq = new CHONSO();
kq.nguyen = a.nguyen + b.nguyen;
kq.tu = (a.tu * b.mau) + (a.mau * b.tu);
kq.mau = a.mau * b.mau;
return kq;
}
static public CHONSO operator -(CHONSO a, CHONSO b)
{
CHONSO kq = new CHONSO();
kq.nguyen = a.nguyen - b.nguyen;
kq.tu = (a.tu * b.mau) - (a.mau * b.tu);
kq.mau = a.mau * b.mau;
return kq;
}
static public CHONSO operator *(CHONSO a, CHONSO b)
{
CPHANSO c =a.chuyenps();
CPHANSO d = b.chuyenps();
CPHANSO e = c.tich(d);
CHONSO kq = new CHONSO();
kq = e.honso();
return kq;
}
static public CHONSO operator /(CHONSO a, CHONSO b)
{
CPHANSO c = a.chuyenps();
CPHANSO d = b.chuyenps();
CPHANSO e = c.thuong(d);
CHONSO kq = new CHONSO();
kq = e.honso();
return kq;
}
public override string ToString()
{
string s = nguyen + ":" + tu + "/" + mau;
return s;
}
}
}
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Bai22_honso
{
class CHONSO
{
int nguyen, tu, mau;
#region propety
public int Mau
{
get { return mau; }
set { mau = value; }
}
public int Tu
{
get { return tu; }
set { tu = value; }
}
public int Nguyen
{
get { return nguyen; }
set { nguyen = value; }
}
#endregion
public void nhap()
{
Console.Write("Nhap phan nguyen: ");
nguyen=int.Parse(Console.ReadLine());
Console.Write("Nhap tu so: ");
tu=int.Parse(Console.ReadLine());
Console.Write("Nhap mau so: ");
mau=int.Parse(Console.ReadLine());
}
public CHONSO()
{
}
public CHONSO(int a,int b,int c)
{
nguyen=a;
tu=b;
mau=c;
}
public CHONSO(CHONSO b)
{
nguyen=b.nguyen;
tu=b.tu;
mau=b.mau;
}
public void xuat()
{
Console.Write("{0}:{1}/{2}\n", nguyen, tu, mau);
}
public CPHANSO chuyenps()
{
CPHANSO c = new CPHANSO();
c.Tu1 = tu * mau + tu;
c.Mau1= mau;
return c;
}
public static CHONSO operator +(CHONSO a, CHONSO b)
{
CHONSO kq = new CHONSO();
kq.nguyen = a.nguyen + b.nguyen;
kq.tu = (a.tu * b.mau) + (a.mau * b.tu);
kq.mau = a.mau * b.mau;
return kq;
}
static public CHONSO operator -(CHONSO a, CHONSO b)
{
CHONSO kq = new CHONSO();
kq.nguyen = a.nguyen - b.nguyen;
kq.tu = (a.tu * b.mau) - (a.mau * b.tu);
kq.mau = a.mau * b.mau;
return kq;
}
static public CHONSO operator *(CHONSO a, CHONSO b)
{
CPHANSO c =a.chuyenps();
CPHANSO d = b.chuyenps();
CPHANSO e = c.tich(d);
CHONSO kq = new CHONSO();
kq = e.honso();
return kq;
}
static public CHONSO operator /(CHONSO a, CHONSO b)
{
CPHANSO c = a.chuyenps();
CPHANSO d = b.chuyenps();
CPHANSO e = c.thuong(d);
CHONSO kq = new CHONSO();
kq = e.honso();
return kq;
}
public override string ToString()
{
string s = nguyen + ":" + tu + "/" + mau;
return s;
}
}
}
class Program
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Bai22_honso
{
class Program
{
static void Main(string[] args)
{
//Chuyen hon so sang phan so
CHONSO a1 = new CHONSO();
a1.nhap();
a1.xuat();
CHONSO b1 = new CHONSO();
b1.nhap();
b1.xuat();
CPHANSO c1 = new CPHANSO();
Console.WriteLine("Doi hon so thu nhat sang phan so:");
c1 = a1.chuyenps();
c1.Xuat();
CPHANSO d1 = new CPHANSO();
Console.WriteLine("Doi hon so thu hai sang phan so:");
d1 = b1.chuyenps();
d1.Xuat();
CHONSO e1 = new CHONSO();
Console.WriteLine("Tong 2 hon so");
e1 = a1 + b1;
e1.xuat();
CHONSO f1 = new CHONSO();
Console.WriteLine("Hieu 2 hon so");
f1 = a1 - b1;
f1.xuat();
CHONSO g1 = new CHONSO();
Console.WriteLine("Tich 2 hon so");
g1 = a1 * b1;
g1.xuat();
CPHANSO g2 = new CPHANSO();
CHONSO h1 = new CHONSO();
h1 = a1 / b1;
Console.WriteLine("Thuong 2 hon so");
h1.xuat();
//Chuyen phan so sang hon so
CPHANSO a= new CPHANSO();
a.nhap();
a.Xuat();
CPHANSO b = new CPHANSO();
b.nhap();
b.Xuat();
CHONSO c = new CHONSO();
Console.WriteLine("Doi phan so thu nhat sang hon so:");
c = a.honso();
c.xuat();
CHONSO d = new CHONSO();
Console.WriteLine("Doi phan so thu nhat sang hon so:");
d = b.honso();
d.xuat();
}
}
}
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Bai22_honso
{
class Program
{
static void Main(string[] args)
{
//Chuyen hon so sang phan so
CHONSO a1 = new CHONSO();
a1.nhap();
a1.xuat();
CHONSO b1 = new CHONSO();
b1.nhap();
b1.xuat();
CPHANSO c1 = new CPHANSO();
Console.WriteLine("Doi hon so thu nhat sang phan so:");
c1 = a1.chuyenps();
c1.Xuat();
CPHANSO d1 = new CPHANSO();
Console.WriteLine("Doi hon so thu hai sang phan so:");
d1 = b1.chuyenps();
d1.Xuat();
CHONSO e1 = new CHONSO();
Console.WriteLine("Tong 2 hon so");
e1 = a1 + b1;
e1.xuat();
CHONSO f1 = new CHONSO();
Console.WriteLine("Hieu 2 hon so");
f1 = a1 - b1;
f1.xuat();
CHONSO g1 = new CHONSO();
Console.WriteLine("Tich 2 hon so");
g1 = a1 * b1;
g1.xuat();
CPHANSO g2 = new CPHANSO();
CHONSO h1 = new CHONSO();
h1 = a1 / b1;
Console.WriteLine("Thuong 2 hon so");
h1.xuat();
//Chuyen phan so sang hon so
CPHANSO a= new CPHANSO();
a.nhap();
a.Xuat();
CPHANSO b = new CPHANSO();
b.nhap();
b.Xuat();
CHONSO c = new CHONSO();
Console.WriteLine("Doi phan so thu nhat sang hon so:");
c = a.honso();
c.xuat();
CHONSO d = new CHONSO();
Console.WriteLine("Doi phan so thu nhat sang hon so:");
d = b.honso();
d.xuat();
}
}
}
0 comments:
Post a Comment