Задача: Родительский класс - круг радиуса R=11 Вычислить его площадь. Производный класс - прямой конус высотой H=6. Вычислить его объем.
заранее спасибо.
uses crt;
type
TCircle = Object
public
constructor Init(r : word);
destructor Done;
function GetS : single;
private
radius : word;
end;
TConus = Object(TCircle)
public
constructor Init(r, h : word);
destructor Done;
function GetV : single;
private
height : word;
end;
constructor TCircle.Init(r : word);
begin
radius := r;
end;
destructor TCircle.Done;
begin end;
function TCircle.GetS : single;
begin
GetS := 2 * PI * radius;
end;
constructor TConus.Init(r, h : word);
begin
inherited Init( r );
height := h;
end;
destructor TConus.Done;
begin
inherited Done;
end;
function TConus.GetV : single;
begin
GetV := (1/3) * height * PI * PI;
end;
var
cir : TCircle;
con : TConus;
begin
clrscr;
cir.Init(11);
con.Init(11, 6);
writeln('S circle = ', cir.GetS : 2 : 2);
writeln('V conus = ', con.GetV : 2 : 2);
readln;
end.
function TCircle.GetS : single;
begin
GetS := PI * Sqr(radius);
end;
...
function TConus.GetV : single;
begin
GetV := (1/3) * heigth * GetS;
end;
var
con : TConus;
begin
clrscr;
con.Init(11, 6);
writeln('S circle = ', con.GetS : 2 : 2);
writeln('V conus = ', con.GetV : 2 : 2);
readln;
end.