Tra Từ Điển

Thời gianTiếtThứ 2Thứ 3Thứ 4Thứ 5Thứ 6
8g40 - 9g101Tiếng Việt
Tiếng Anh
Tiếng Việt
Tiếng Việt
9g10 - 9g302Nghỉ giải lao
Tiếng Anh
Nghỉ giải lao
Nghỉ giải lao
9g30 - 10g3Toán
Toán
Toán

Sunday, March 21, 2021

Liên kết: Hình Chữ Nhật + Hình Hộp + Form1

// 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