// Hình Chữ Nhật
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace WindowsFormsApp3
{
class HCN
{
public int cd;
public int cr;
public HCN(int cd,int cr)
{
this.cd = cd;
this.cr = cr;
}
public int tinhDT()
{
return cd * cr;
}
public int tinhCV()
{
return (cd + cr) * 2;
}
public String xuatTT()
{
return "dt: " + tinhDT() + " cv: " + tinhCV();
}
}
}
// Hình Hộp
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace WindowsFormsApp3
{
class HH : HCN
{
public int cc;
public HH(int cd,int cr,int cc):base(cd,cr)
{
this.cc = cc;
}
public int tinhTT()
{
return tinhDT() * cc;
}
public String xuatTT()
{
return base.xuatTT() + " tt: " + tinhTT();
}
}
}// Form1
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace WindowsFormsApp3
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void checkBox1_CheckedChanged(object sender, EventArgs e)
{
if(checkBox1.Checked==true)
{
label3.Enabled = true;
textBox3.Enabled = true;
}
else
{
label3.Enabled = false;
textBox3.Enabled = false;
}
}
private void button1_Click(object sender, EventArgs e)
{
int cd=int.Parse(textBox1.Text);
int cr = int.Parse(textBox2.Text);
if(checkBox1.Checked==true)//hinh hop
{
int cc = int.Parse(textBox3.Text);
HH a = new HH(cd, cr, cc);
label4.Text= a.xuatTT();
}
else
{
HCN a = new HCN(cd, cr);
label4.Text = a.xuatTT();
}
}
}
}
0 comments:
Post a Comment