namespace Thuc_Hanh_Thua_Ke
{
public class HinhVuong : Hinh
{
private double chieuDaiCanh = 1;
public double ChieuDaiCanh
{
get
{
return chieuDaiCanh;
}
set
{
if (value > 0)
{
chieuDaiCanh = value;
}
}
}
public HinhVuong()
: base(4)
{
}
public HinhVuong(double a)
: base(4)
{
chieuDaiCanh = a;
}
//cac ham thua ke
public override void NhapHinh()
{
//Console.WriteLine("Nhap chieu dai canh hinh vuong{0}",
chieuDaiCanh);
//sua lai
Console.WriteLine("Nhap chieu dai canh hinh vuong");
chieuDaiCanh = double.Parse(Console.ReadLine());
}
public override void InHinh()
{
//in theo mau cua de bai
Console.WriteLine("Hinh vuong:");
Console.WriteLine("Canh = {0}", chieuDaiCanh);
Console.WriteLine("Chu vi = {0}", this.ChuVi());
Console.WriteLine("Dien tich = {0}", this.DienTich());
}
public override double ChuVi()
{
double kq = 0;
kq = ChieuDaiCanh * 4;
return kq;
}
public override double DienTich()
{
double kq = 0;
kq = ChieuDaiCanh * ChieuDaiCanh;
return kq;
}
}
}
namespace Thuc_Hanh_Thua_Ke
{
public class HinhChuNhat : Hinh
{
private double chieuDaiCanhA = 1;
public double ChieuDaiCanhA
{
get
{
return chieuDaiCanhA;
}
set
{
chieuDaiCanhA = value;
}
}
private double chieuDaiCanhB = 1;
public double ChieuDaiCanhB
{
get
{
return chieuDaiCanhB;
}
set
{
chieuDaiCanhB = value;
}
}
public HinhChuNhat()
: base(4)
{
chieuDaiCanhA = 1;
chieuDaiCanhB = 1;
}
public HinhChuNhat(double a, double b)
:base(4)
{
chieuDaiCanhA = 1;
chieuDaiCanhB = 1;
}
//cac ham thua ke
public override void NhapHinh()
{
Console.WriteLine("Nhap chieu dai canh hinh chu nhat");
chieuDaiCanhA = double.Parse(Console.ReadLine());
Console.WriteLine("Nhap chieu rong canh hinh chu nhat");
chieuDaiCanhB = double.Parse(Console.ReadLine());
}
public override void InHinh()
{
//in thao mau cua de bai
Console.WriteLine("Hinh chu nhat");
Console.WriteLine("Canh ngan = {0}", chieuDaiCanhA);
Console.WriteLine("Canh dai = {0}", chieuDaiCanhB);
Console.WriteLine("Chu vi = {0}", this.ChuVi());
Console.WriteLine("Dien tich = {0}", this.DienTich());
}
public override double ChuVi()
{
double kq = 0;
kq = (ChieuDaiCanhA + ChieuDaiCanhB) * 2;
return kq;
}
public override double DienTich()
{
double kq = 0;
kq = ChieuDaiCanhA * ChieuDaiCanhB;
return kq;
}
}
}