Загрузка данных


unit Geometry;
{$mode objfpc}{$H+}
{$codepage UTF-8}
interface
uses
  SysUtils;

type
  TGeomShape = class
  strict private
    FName: string;
  public
    constructor Create(const AName: string);
    function GetArea: Double; virtual; abstract;
    function GetPerimeter: Double; virtual; abstract;
    function ToString: string; override;
    property Name: string read FName;
  end;

  TCircle = class(TGeomShape)
  strict private
    FRadius: Double;
  public
    constructor Create(const AName: string; ARadius: Double);
    function GetArea: Double; override;
    function GetPerimeter: Double; override;
    property Radius: Double read FRadius;
  end;

  TRectangle = class(TGeomShape)
  strict private
    FWidth: Double;
    FHeight: Double;
  public
    constructor Create(const AName: string; AWidth, AHeight: Double);
    function GetArea: Double; override;
    function GetPerimeter: Double; override;
    property Width: Double read FWidth;
    property Height: Double read FHeight;
  end;

implementation

constructor TGeomShape.Create(const AName: string);
begin
  inherited Create;
  FName := AName;
end;

function TGeomShape.ToString: string;
begin
  Result := FName + ': S=' + FormatFloat('0.00', GetArea) +
            ', P=' + FormatFloat('0.00', GetPerimeter);
end;

constructor TCircle.Create(const AName: string; ARadius: Double);
begin
  inherited Create(AName);
  if ARadius < 0 then
    FRadius := 0
  else
    FRadius := ARadius;
end;

function TCircle.GetArea: Double;
begin
  Result := Pi * FRadius * FRadius;
end;

function TCircle.GetPerimeter: Double;
begin
  Result := 2 * Pi * FRadius;
end;


constructor TRectangle.Create(const AName: string; AWidth, AHeight: Double);
begin
  inherited Create(AName);
  if AWidth < 0 then
    FWidth := 0
  else
    FWidth := AWidth;
  if AHeight < 0 then
    FHeight := 0
  else
    FHeight := AHeight;
end;

function TRectangle.GetArea: Double;
begin
  Result := FWidth * FHeight;
end;

function TRectangle.GetPerimeter: Double;
begin
  Result := 2 * (FWidth + FHeight);
end;

end.