[C#] Tính CV và DT HCN
Chương trình chính (Program.cs)
Mã:
using System;
using System.Collections.Generic;
using System.Text;
namespace HINHCHUNHAT
{
class Program
{
static void Main(string[] args)
{
hinhchunhat hcn1 = new hinhchunhat(5, 4);
Console.WriteLine("Dien tich cua hcn thu 1 la:" + hcn1.dientich());
Console.WriteLine("Chu vi cua hcn thu 1 la:" + hcn1.chuvi());
Console.ReadLine();
hinhchunhat hcn2 = new hinhchunhat(9, 7);
Console.WriteLine("Dien tich cua hcn thu 2 la:" + hcn2.dientich());
Console.WriteLine("Chu vi cua hcn thu 2 la:" + hcn2.chuvi());
Console.ReadLine();
}
}
}
Tạo 1 Class tên: HINHCHUNHAT
Mã:
using System;
using System.Collections.Generic;
using System.Text;
namespace HINHCHUNHAT
{
class hinhchunhat
{
private int chieudai;
private int chieurong;
public hinhchunhat(int cr,int cd)
{
chieudai = cd;
chieurong = cr;
}
public int dientich()
{
return chieudai * chieurong;
}
public int chuvi()
{
return 2* chieudai + chieurong;
}
}
}