protected void Page_Load(object sender, EventArgs e) { HinhVuong hv = new HinhVuong { Canh = 5 }; HinhChuNhat hcn = new HinhChuNhat { ChieuDai = 10, ChieuRong = 20 }; IHinh h; //h = hv; //double dt1 = h.DienTich(); //h = hcn; //double dt2 = h.DienTich(); h = hv as IHinh; h = (IHinh)hv; IHoSoCaNhan hscn; hscn = hv as IHoSoCaNhan; hscn = (IHoSoCaNhan)hv; }
static void Main(string[] args) { HinhChuNhat hinh = new HinhChuNhat(); hinh.ChieuDai = 4; hinh.ChieuRong = 5; hinh.tinhChuVi(); hinh.tinhDienTich(); Console.WriteLine(hinh.Ten + " co chu vi la " + hinh.ChuVi); Console.WriteLine(hinh.Ten + " co dien tich la " + hinh.DienTich); HinhChuNhat hinh2 = hinh; // True Console.WriteLine(hinh2.Equals(hinh)); HinhChuNhat hinh3 = new HinhChuNhat(); hinh3.ChieuDai = hinh.ChieuDai; hinh3.ChieuRong = hinh.ChieuRong; hinh3.tinhChuVi(); hinh3.tinhDienTich(); // False Console.WriteLine(hinh3.Equals(hinh)); Console.ReadLine(); }
static void Main(string[] args) { HinhHoc2D hinh = new HinhChuNhat(4, 5); hinh.tinhDienTich(); hinh.tinhChuVi(); hinh.inChuVi(); hinh.inDienTich(); Console.ReadLine(); }
static void Main(string[] args) { Console.WriteLine("Tinh da hinh trong C#"); Console.WriteLine("Vi du minh hoa Da hinh dong C#"); HinhChuNhat r = new HinhChuNhat(10, 7); double a = r.tinDientich(); Console.WriteLine("Dien tich:{0}", a); Console.ReadKey(); }
public IActionResult OOP() { //tạo đối tượng HinhChuNhat hcn = new HinhChuNhat() { Dai = 4, Rong = 2.2 }; return(Json(hcn)); }
public void Test() { double x1 = double.Parse(TestContext.DataRow[0].ToString()); double y1 = double.Parse(TestContext.DataRow[1].ToString()); double x2 = double.Parse(TestContext.DataRow[2].ToString()); double y2 = double.Parse(TestContext.DataRow[3].ToString()); double expected = double.Parse(TestContext.DataRow[4].ToString()); Diem d1 = new Diem(x1, y1); Diem d2 = new Diem(x2, y2); HinhChuNhat h = new HinhChuNhat(d1, d2); double actual = h.TinhDienTich(); Assert.AreEqual(expected, actual); }
private void panel2_MouseClick(object sender, MouseEventArgs e) { int x = e.X; int y = e.Y; if (chedo == 1) { this.rsPoint(); if (hinh == 1) //hcn { if (p1.X == -1) { p1.X = Pixel.RoundPixel(x); p1.Y = Pixel.RoundPixel(y); Pixel.HienThi(p1, g, this.color); } else if (p2.X == -1) { p2.X = Pixel.RoundPixel(x); p2.Y = Pixel.RoundPixel(y); HinhChuNhat hcn = new HinhChuNhat(p1, p2, this.color); //this.AX.Text = "( " + hcn.A.X/5 + " , " + hcn.A.Y/5 + " )"; //this.BX.Text = "( " + hcn.B.X/5 + " , " + hcn.B.Y/5 + " )"; //this.CX.Text = "( " + hcn.C.X/5 + " , " + hcn.C.Y/5 + " )"; //this.DX.Text = "( " + hcn.D.X/5 + " , " + hcn.D.Y/5 + " )"; this.AX.Text = Pixel.chuyenToaDoNgDg(hcn.A); this.BX.Text = Pixel.chuyenToaDoNgDg(hcn.B); this.CX.Text = Pixel.chuyenToaDoNgDg(hcn.C); this.DX.Text = Pixel.chuyenToaDoNgDg(hcn.D); hcn.Draw(g); p1.X = -1; p2.X = -1; } } else if (hinh == 2) //eclip { if (p1.X == -1) { p1.X = Pixel.RoundPixel(x); p1.Y = Pixel.RoundPixel(y); Pixel.HienThi(p1, g, this.color); } else if (p2.X == -1) { p2.X = Pixel.RoundPixel(x); p2.Y = p1.Y; Pixel.HienThi(p2, g, this.color); } else if (p3.X == -1) { p3.X = p1.X; p3.Y = Pixel.RoundPixel(y); this.AX.Text = Pixel.chuyenToaDoNgDg(p1); this.BX.Text = Pixel.chuyenToaDoNgDg(p2); this.CX.Text = Pixel.chuyenToaDoNgDg(p3); Pixel.HienThi(p1, g, color); int a = Pixel.distancePoint(p1, p2); int b = Pixel.distancePoint(p1, p3); Elip el = new Elip(p1, a, b, this.color); el.Draw(g); p1.X = -1; p2.X = -1; p3.X = -1; } } else if (hinh == 3) //tron { if (p1.X == -1) { p1.X = Pixel.RoundPixel(x); p1.Y = Pixel.RoundPixel(y); Pixel.HienThi(p1, g, this.color); } else if (p2.X == -1) { p2.X = Pixel.RoundPixel(x); p2.Y = Pixel.RoundPixel(y); this.AX.Text = Pixel.chuyenToaDoNgDg(p1); this.BX.Text = Pixel.chuyenToaDoNgDg(p2); Pixel.HienThi(p1, g, color); HinhTron ht = new HinhTron(Pixel.distancePoint(p1, p2), p1, this.color); ht.Draw(g); p1.X = -1; p2.X = -1; } } else if (hinh == 4) //tam giac { if (p1.X == -1) { p1.X = Pixel.RoundPixel(x); p1.Y = Pixel.RoundPixel(y); Pixel.HienThi(p1, g, this.color); } else if (p2.X == -1) { p2.X = Pixel.RoundPixel(x); p2.Y = Pixel.RoundPixel(y); Pixel.HienThi(p2, g, this.color); } else if (p3.X == -1) { p3.X = Pixel.RoundPixel(x); p3.Y = Pixel.RoundPixel(y); this.AX.Text = Pixel.chuyenToaDoNgDg(p1); this.BX.Text = Pixel.chuyenToaDoNgDg(p2); this.BX.Text = Pixel.chuyenToaDoNgDg(p3); HinhTamGiac htg = new HinhTamGiac(p1, p2, p3, color); htg.Draw(g); p1.X = -1; p2.X = -1; p3.X = -1; } } else if (hinh == 5) //line { if (p1.X == -1) { p1.X = Pixel.RoundPixel(x); p1.Y = Pixel.RoundPixel(y); Pixel.HienThi(p1, g, color); } else if (p2.X == -1) { p2.X = Pixel.RoundPixel(x); p2.Y = Pixel.RoundPixel(y); this.AX.Text = Pixel.chuyenToaDoNgDg(p1); this.BX.Text = Pixel.chuyenToaDoNgDg(p2); Line l = new Line(p1, p2, color); l.Draw(g); p1.X = -1; p2.X = -1; } } else if (hinh == 6) { if (p1.X == -1) { p1.X = Pixel.RoundPixel(x); p1.Y = Pixel.RoundPixel(y); Pixel.HienThi(p1, g, color); } else if (p2.X == -1) { p2.X = p1.X; p2.Y = Pixel.RoundPixel(y); this.AX.Text = Pixel.chuyenToaDoNgDg(p1); this.BX.Text = Pixel.chuyenToaDoNgDg(p2); Pixel.HienThi(p1, g, Color.White); Star star = new Star(p1, Math.Abs(p1.Y - p2.Y), color); star.Draw(g); p1.X = -1; p2.X = -1; } } } else if (chedo == 2) { } }
public IActionResult XuLyLuu(HinhChuNhat hcn) { dsHCN.Add(hcn); return(RedirectToAction("Index")); }