-
-
Save tuannguyenssu/f9221fb4c7ea7d242781d7f3e05e3a94 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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