Line(x-round((r div 2)*(sqrt(3)/2)),round(y-(r div 2)/2),x+round((r div 2)*(sqrt(3)/2)),round(y-(r div 2)/2));
Line(x+round((r div 2)*(sqrt(3)/2)),round(y-(r div 2)/2),x,round(y+(r div 2)));
Circle(X,Y, r div 4);
end;
procedure TCirTrSq.Hide;
begin
SetColor(0);
Line(x,y-r,x+round(r*(sqrt(3)/2)),round(y+r/2));
Line(x+round(r*(sqrt(3)/2)),round(y+r/2),x-round(r*(sqrt(3)/2)),round(y+r/2));
Line(x-round(r*(sqrt(3)/2)),round(y+r/2),x,round(y-r));
Line(x,y+(r div 2),x-round((r div 2)*(sqrt(3)/2)),round(y-(r div 2)/2));
Line(x-round((r div 2)*(sqrt(3)/2)),round(y-(r div 2)/2),x+round((r div 2)*(sqrt(3)/2)),round(y-(r div 2)/2));
Line(x+round((r div 2)*(sqrt(3)/2)),round(y-(r div 2)/2),x,round(y+(r div 2)));
Circle(X,Y,r div 4);
end;
{ Global peremennue }
var
Points: array [1..5] of TPoint;
T_treyg: array [1..5] of Ttreyg;
TtrInCirs: array [1..5] of TtrInCir;
CirTrSqs: array [1..5] of TCirTrSq;
i, Gd, Gm: Integer;
{ service procedure implementations: }
{--------------------------------------------------------}
procedure writehexword(w: Word);
const
hexChars: array [0..$F] of Char =
'0123456789ABCDEF';
begin
Graph.OutText (hexChars[Hi(w) shr 4]+
hexChars[Hi(w) and $F]+
hexChars[Lo(w) shr 4]+
hexChars[Lo(w) and $F]);
end;
procedure writestructtype(siz: word; ppp: pointer);
var
i,j: word;
St: string;
begin
for i:=0 to (siz - 1) div 2 do
begin
Graph.MoveTo(16,220+i*12);
writehexword(seg(ppp^));
Graph.OutTextXY(56,220+i*12,':');
Graph.MoveTo(64,220+i*12);
writehexword(ofs(ppp^)+i*2);
Graph.OutTextXY(96,220+i*12,'-');
Graph.MoveTo(104,220+i*12);
writehexword(memw[seg(ppp^):ofs(ppp^)+i*2]);
Str(memw[seg(ppp^):ofs(ppp^)+i*2],St);
Graph.OutTextXY(160,220+i*12,St);
end;
end;
procedure writestructvar(siz: word; ppp: pointer);
var
i: word;
St: string;
begin
for i:=0 to (siz - 1) div 2 do
begin
Graph.MoveTo(296,220+i*12);
writehexword(seg(ppp^));
Graph.OutTextXY(336,220+i*12,':');
Graph.MoveTo(344,220+i*12);
writehexword(ofs(ppp^)+i*2);
Graph.OutTextXY(376,220+i*12,'-');
Graph.MoveTo(384,220+i*12);
writehexword(memw[seg(ppp^):ofs(ppp^)+i*2]);
Str(memw[seg(ppp^):ofs(ppp^)+i*2],St);
Graph.OutTextXY(440,220+i*12,St);
end;
end;
procedure WriteStructMain;
var
siz: word;
ppp: pointer;
St: string;
c: char;
begin
{-------- Структура типа TCirTwoSq -----------------------------}
Graph.Bar(0,200,639,479);
siz:=16;
ppp:=typeof(TCirTrSq);
Graph.OutTextXY(8,208,'TCirTrSq: ');
Str(siz,St);
Graph.OutTextXY(66,208,'size of VMT "TCirTrSq" = '+ St);
writestructtype(siz,ppp);
siz:=sizeof(CirTrSqs[1]);
ppp:=@CirTrSqs[1];
Graph.OutTextXY(268,208,'CirTrSqs[1]: ');
Str(siz,St);
Graph.OutTextXY(330,208,'size of variable "CirTrSqs[1]" = '+ St);
writestructvar(siz,ppp);
end;
{ Main }
begin
Gd := Detect;
InitGraph(Gd, Gm, ' ');
if GraphResult <> grOk then Halt(1);
ClearDevice;
for i:=1 to 5 do
begin
Points[i].Init(random(100),100+random(50),0);
Points[i].Show;
T_treyg[i].Init(random(200),100+random(100),30);
T_treyg[i].Show;
TtrInCirs[i].Init(random(200),100+random(150),50);
TtrInCirs[i].Show;
CirTrSqs[i].Init(random(200),100+random(200),40);
CirTrSqs[i].Show;
end;
WriteStructMain;
repeat
for i:=1 to 5 do
begin
Points[i].Move(i+1,0,0);
T_treyg[i].Move(i-1,i+1,2-integer(random(5)));
TtrInCirs[i].Move(i+1,i-1,2-integer(random(5)));
CirTrSqs[i].Move(0,i+1,2-integer(random(5)));
end;
WriteStructMain;
delay(3000);
until keypressed;
CloseGraph;
end.
Висновок: Використовуючи програму лабораторної роботи №1, отримали вивід структур екземпляра об’ктного типа і таблиці віртуальних методів відповідно до індивідуального завдання.
Уважаемый посетитель!
Чтобы распечатать файл, скачайте его (в формате Word).
Ссылка на скачивание - внизу страницы.