Создать структуру работы с кругом - C#
Формулировка задачи:
Собственно всё написано в прикреплённом изображении. Помогите получить зачёт!
Решение задачи: «Создать структуру работы с кругом»
textual
Листинг программы
public struct Circle
{
private double _Radius;
private double _Diameter;
public Point Center { get; set; }
public double Radius {
get { return _Radius;
}
set {
_Radius = value;
_Diameter = value * 2;
}
}
public double Diameter {
get {
return _Diameter;
}
set {
_Diameter = value;
_Radius = value / 2;
}
}
public double Area {
get {
return Math.PI * _Radius * _Radius;
}
}
public double Length {
get {
return Math.PI * _Diameter;
}
}
public Circle(Point center, double radius) {
Center = center;
_Radius = radius;
_Diameter = radius * 2;
}
public Circle(double x, double y, double radius) {
Center = new Point(x, y);
_Radius = radius;
_Diameter = radius * 2;
}
public override string ToString()
{
return $"Center = [{Center.X}, {Center.Y}];\n" +
$"Radius = {_Radius};\n" +
$"Diameter = {_Diameter};\n" +
$"Area = {Area};\n" +
$"Length = {Length}";
}
}