Nhấn vào chữ Spoiler để hiển thị nội dung
- Spoiler:
- Main.cs
- Code:
using System;
public class Tester
{
public static void Main()
{
float x, y, canh, gioihan, xM;
Console.WriteLine("Goc tren cung hinh vuong ngoai tiep duong tron");
Console.Write("xA= ");
x = float.Parse(Console.ReadLine());
Console.Write("yA= ");
y = float.Parse(Console.ReadLine());
diem A = new diem(x, y);
Console.Write("Nhap canh hinh vuong ngoai tiep duong tron: ");
canh = float.Parse(Console.ReadLine());
diem I=new diem(x+canh/2,y+canh/2);
HCN tam = new HCN(A, canh, canh);
Console.WriteLine("Khoang cach tu tam hinh tron toi goc toa do: " + tam.kcIO());
Console.WriteLine("Khoang cach tu goc toa do den diem xa nhat cua HV: " + new diem(x+canh,y+canh).khoangcach());
hinhtron O = new hinhtron(canh, x, y, canh / 2);
Console.WriteLine("Dien tich hinh tron noi tiep: " + O.dientich());
Console.WriteLine("Chu vi hinh tron noi tiep: " + O.chuvi());
gioihan=tam.dientich() - O.dientich();
Console.WriteLine("Dien tich hinh gioi han boi hinh vuong ngoai tiep va hinh tron: " + gioihan);
O.ptrinhTQ();
do
{
Console.Write("Nhap hoanh do xM thuoc duong tron({0} < xM < {1}): ",x,x+canh);
xM = float.Parse(Console.ReadLine());
if (xM < x || xM > x + canh) Console.WriteLine("Ban da nhap sai --> Moi nhap lai!");
} while (xM < x || xM > x + canh);
DiemThuocDT M = new DiemThuocDT(canh/2,xM,tam.I().X,tam.I().Y);
diem U = new diem(x, y + canh / 2);
diem V = new diem(x + canh, y + canh / 2);
KhoangCach2Diem MU = new KhoangCach2Diem(M.Mtdt(), U);
KhoangCach2Diem MV = new KhoangCach2Diem(M.Mtdt(), V);
Console.Write("Dien tich tam giac gioi han boi M va duong kinh song song Ox: {0}",new tamgiac(MU,MV).DTTamGiac());
Console.ReadLine();
}
}
Diem.cs
- Code:
using System;
public class diem
{
public diem(float x, float y)
{
this.x = x;
this.y = y;
}
public float khoangcach()
{
return (float)Math.Sqrt(x * x + y * y);
}
public float X
{
get
{
return x;
}
}
public float Y
{
get
{
return y;
}
}
float x;
float y;
}
HCN.cs
- Code:
using System;
public class HCN
{
public HCN(diem A, float rong, float cao)
{
this.A = A;
this.rong = rong;
this.cao = cao;
}
public diem I()
{
float a = A.X + (float)rong / 2;
float b = A.Y + (float)cao / 2;
return new diem(a, b);
}
public float kcIO()
{
return I().khoangcach();
}
public float dientich()
{
return rong * cao;
}
diem A;
public float rong;
public float cao;
}
KhoangCach2Diem.cs
- Code:
using System;
class KhoangCach2Diem
{
public KhoangCach2Diem(diem A,diem B)
{
this.A = A;
this.B = B;
}
public float doanthang()
{
return (float)Math.Sqrt((A.X - B.X) * (A.X - B.X) + (A.Y - B.Y) * (A.Y - B.Y));
}
diem A;
diem B;
}
hinhTron.cs
- Code:
using System;
public class hinhtron
{
public hinhtron(float canh,float x,float y,float bankinh)
{
this.canh = canh;
this.x = x;
this.y = y;
this.bankinh = bankinh;
}
public float dientich()
{
return pi * bankinh * bankinh;
}
public float chuvi()
{
return 2 * pi * bankinh;
}
public void ptrinhTQ()
{
Console.WriteLine("PTTQ: (x- {0})^2 + (y - {1})^2 = {2}",x+canh/2,y+canh/2,bankinh*bankinh);
}
float canh;
float x;
float y;
float pi = (float)3.14;
float bankinh;
}
DiemThuocDT.cs
- Code:
using System;
public class DiemThuocDT
{
public DiemThuocDT(float bankinh,float x0,float x,float y0)
{
this.bankinh = bankinh;
this.x0 = x0;
this.x = x;
this.y0 = y0;
}
public diem Mtdt()
{
float y = (float)Math.Sqrt(bankinh * bankinh - (x0 - x) * (x0 - x)) + y0;
return new diem(x,y);
}
float x0;
float x;
float y0;
float bankinh;
}
tamgiac.cs
- Code:
using System;
class tamgiac
{
public tamgiac(KhoangCach2Diem AM,KhoangCach2Diem BM)
{
this.AM = AM;
this.BM = BM;
}
public float DTTamGiac()
{
return ((AM.doanthang()*BM.doanthang())/2);
}
KhoangCach2Diem AM;
KhoangCach2Diem BM;
}
Được sửa bởi Black Wind ngày 22/10/2009, 16:51; sửa lần 1.