Skip to content

Instantly share code, notes, and snippets.

@conanak99

conanak99/new.cs Secret

Last active April 12, 2016 23:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save conanak99/6ab2087eead99bfda3aec7d5ddd4da9f to your computer and use it in GitHub Desktop.
Save conanak99/6ab2087eead99bfda3aec7d5ddd4da9f to your computer and use it in GitHub Desktop.
// Ta có 3 class: vuông, tròn, tam giác, kế thừa class Shape
// Chuyển logic tính diện tích vào mỗi class
public abstract class Shape
{
public double Area();
}
public class Square : Shape
{
public double Height { get; set; }
public double Area() {
return Math.Sqrt(this.Height);
}
}
public class Circle : Shape
{
public double Radius { get; set; }
public double Area() {
return this.Radius * this.Radius * Math.PI;
}
}
public class Triangle : Shape
{
public double FirstSide { get; set; }
public double SecondSide { get; set; }
public double ThirdSide { get; set; }
public double Area() {
double TotalHalf = (this.FirstSide + this.SecondSide + this.ThirdSide) / 2;
var area += Math.Sqrt(TotalHalf * (TotalHalf - this.FirstSide) *
(TotalHalf - this.SecondSide) * (TotalHalf - this.ThirdSide));
return area;
}
}
// Module in ra diện tích các hình
public class AreaDisplay
{
public double ShowArea(List<Shape> shapes)
{
foreach (var shape in shapes) {
Console.WriteLine(shape.Area());
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment