uses
crt;
type
TVector=object
private
x,y:real;
public
procedure Init(x1,x2,y1,y2:real);
procedure SetVector(valueX,valueY:real);
procedure GetVector(var valueX:real;var valueY:real);
function length:real;
end;
TOperation=object
private
vector1,vector2:TVector;
public
procedure SetVectors(valueVector1,valueVector2:TVector);
end;
TOperationAdd=object(TOperation)
procedure Add(valueVector1,valueVector2:TVector;var result:TVector);
end;
TOperationSub=object(TOperation)
procedure Sub(valueVector1,valueVector2:TVector;var result:TVector);
end;
TOperationMulScalyar=object(TOperation)
function MulScalyar(valueVector1,valueVector2:TVector):real;
end;
TOperationMulVector=object(TOperation)
function MulVector(valueVector1,valueVector2:TVector):real;
end;
procedure TVector.Init(x1,x2,y1,y2:real);
begin
x:=x2-x1;
y:=y2-y1;
end;
procedure TVector.SetVector(valueX,valueY:real);
begin
x:=valueX;
y:=valueY;
end;
procedure TVector.GetVector(var valueX:real;var valueY:real);
begin
valueX:=x;
valueY:=y;
end;
function TVector.length:real;
begin
length:=sqrt(sqr(x)+sqr(y));
end;
procedure TOperation.SetVectors(valueVector1,valueVector2:TVector);
begin
vector1:=valueVector1;
vector2:=valueVector2;
end;
procedure TOperationAdd.Add(valueVector1,valueVector2:TVector;var result:TVector);
var
vectorX1,vectorX2,vectorY1,vectorY2:real;
begin
inherited SetVectors(valueVector1,valueVector2);
vector1.GetVector(vectorX1,VectorY1);
vector2.GetVector(vectorX2,VectorY2);
result.SetVector(vectorX1+vectorX2,vectorY1+vectorY2);
end;
procedure TOperationSub.Sub(valueVector1,valueVector2:TVector;var result:TVector);
var
vectorX1,vectorX2,vectorY1,vectorY2:real;
begin
inherited SetVectors(valueVector1,valueVector2);
vector1.GetVector(vectorX1,VectorY1);
vector2.GetVector(vectorX2,VectorY2);
result.SetVector(vectorX2-vectorX1,vectorY2-vectorY1);
end;
function TOperationMulScalyar.MulScalyar(valueVector1,valueVector2:TVector):real;
var
vectorX1,vectorX2,vectorY1,vectorY2:real;
begin
inherited SetVectors(valueVector1,valueVector2);
vector1.GetVector(vectorX1,VectorX2);
vector2.GetVector(vectorX2,VectorY2);
MulScalyar:=vectorX1*vectorX2+vectorY1*vectorY2;
end;
function TOperationMulVector.MulVector(valueVector1,valueVector2:TVector):real;
var
scalar,valueCos:real;
MulScalyar :TOperationMulScalyar;
begin
inherited SetVectors(valueVector1,valueVector2);
scalar:=MulScalyar.MulScalyar(vector1,vector2);
valueCos:=scalar/(vector1.length*vector2.length);
MulVector:=2*scalar*valueCos;
end;
var
x,y,x1,x2,y1,y2 :real;
vector1,vector2,result:TVector;
operationAdd :TOperationAdd;
operationSub :TOperationSub;
operationMulScalyar :TOperationMulScalyar;
operationMulVector :TOperationMulVector;
mulScalyar,mulVector :real;
begin
clrscr;
randomize;
x1:=random(10);
x2:=random(10);
y1:=random(10);
y2:=random(10);
vector1.Init(x1,x2,y1,y2);
vector1.GetVector(x,y);
writeln('A(',x1:1:0,',',y1:1:0,'); B(',x2:1:0,',',y2:1:0,'); AB(',x:1:0,',',y:1:0,')');
x1:=random(10);
x2:=random(10);
y1:=random(10);
y2:=random(10);
vector2.Init(x1,x2,y1,y2);
vector2.GetVector(x,y);
writeln('C(',x1:1:0,',',y1:1:0,'); D(',x2:1:0,',',y2:1:0,'); CD(',x:1:0,',',y:1:0,')');
operationAdd.Add(vector1,vector2,result);
result.GetVector(x,y);
writeln('Add: (',x:2:0,',',y:2:0,')');
operationSub.Sub(vector1,vector2,result);
result.GetVector(x,y);
writeln('Sub: (',x:2:0,',',y:2:0,')');
MulScalyar:=operationMulScalyar.MulScalyar(vector1,vector2);
writeln('Mul. Scalyar: ',mulScalyar:5:2);
MulVector:=operationMulVector.MulVector(vector1,vector2);
writeln('Mul. Vector: ',mulVector:5:2);
readkey;
end.
Присутствует ли полиморфизм?
Присутствует ли полиморфизм в этой программе? Если да, то, желательно, скажите в какой строчке он характеризуется.
Не видно ни одного метода помеченного как virtual. Хотя... так ли в паскале объявлялись виртуальные методы - не помню...