Разработка классов на языке Object Pascal. Соколов Е.В. - 28 стр.

UptoLike

Составители: 

28
begin
result:=0;
for i:=1 to Dim do
result:=result+sqr(self.comp[i].GetNum/self.comp[i].GetDen);
result:=sqrt(result);
end;
function RVector.IsEqual(v: RVector): Boolean;
var i: Integer;
begin
result:=true;
for i:=1 to Dim do
if not(self.comp[i].IsEqual(v.comp[i])) then result:=false;
end;
procedure RVector.Assign(v: RVector);
var i: Integer;
begin for i:=1 to Dim do self.comp[i]:=v.comp[i]; end;
function RVector.GetComp(i: Integer): Rational;
begin
if (i>=1) and (i<=Dim)
then result:=self.comp[i]
else raise Exception.Create('Index is out of bounds');
end;
procedure RVector.SetComp(i: Integer; value: Rational);
begin
if (i>=1) and (i<=Dim)
then self.comp[i]:=value
else raise Exception.Create('Index is out of bounds');
end;
function RVector.AsString: String;
var i: Integer;
begin
result:='(';
for i:=1 to Dim do begin
result:=result+self.comp[i].AsString;
if i<Dim then result:=result+', ';
end;
result:=result+')';
end;
8. Поскольку приведенный код , будучи стандартным образом раз -
мещен в модуле, успешно компилируется, перейдем к модификации
демонстрационной программы. Проблемы здесь также связаны искл ю-
чительно с необходимостью явно создавать и удалять переменные типа
Rational, а также изменять их значения только через соответствующие
открытые методы.
begin
  result:=0;
  for i:=1 to Dim do
     result:=result+sqr(self.comp[i].GetNum/self.comp[i].GetDen);
  result:=sqrt(result);
end;
function RVector.IsEqual(v: RVector): Boolean;
var i: Integer;
begin
  result:=true;
  for i:=1 to Dim do
     if not(self.comp[i].IsEqual(v.comp[i])) then result:=false;
end;
procedure RVector.Assign(v: RVector);
var i: Integer;
begin for i:=1 to Dim do self.comp[i]:=v.comp[i]; end;
function RVector.GetComp(i: Integer): Rational;
begin
  if (i>=1) and (i<=Dim)
     then result:=self.comp[i]
     else raise Exception.Create('Index is out of bounds');
end;
procedure RVector.SetComp(i: Integer; value: Rational);
begin
  if (i>=1) and (i<=Dim)
     then self.comp[i]:=value
     else raise Exception.Create('Index is out of bounds');
end;
function RVector.AsString: String;
var i: Integer;
begin
  result:='(';
  for i:=1 to Dim do begin
     result:=result+self.comp[i].AsString;
     if i