Senin, 25 Oktober 2010

Program Rec.

,
program RecVar;
(* File : RecVar.pas *)
(* Record Varian : dengan komponen yang variabel *)
(* Konsep : representasi data yang tidak "fix" type-nya*)
(* Kamus *)
(* Cell adalah sebuah sel spread sheet, yang mungkin isinya :*)
(* Formula : string; integer atau real *)

type
trec = (rumus, int, float);
cell = record
adrbrs : char;
adrkol : integer;
case Tsel : trec of
rumus : ( form : string [5]);
int : ( nili : integer);
float : ( nilf : real ) ;

end; (* cell *)

var
Fcell, ICell, RCell : Cell;

begin (* Algoritma *)
(* Cara mengisi nilai *)
(* Type cell adalh formula *)
Fcell.adrbrs := 'A' ;
Fcell.adrkol := 1;
Fcell.Tsel := rumus;
Fcell.form := 'XYZ12';

(* Type cell adalah integer *)
Icell.adrbrs := 'A';
Icell.adrkol := 2;
Icell.Tsel := int;
Icell.form := '10';

(* Type cell adalah bilangan *)
Rcell.adrbrs := 'A';
Rcell.adrkol := 3;
Rcell.Tsel := float;
Rcell.nilf := 10.55;
end.

=====================================================================
program RecVarx;
(* File : RecVarx.pas *)
(* Record Varian dengan type bentukan *)
(* Kamus *)
(* Gambar adalah bentuk ayang dapat berupa garis, segi empat *)

type
trec = ( garis, segi4 );
Point = record
x: integer;
y: integer;
end;
TGrs = record
Pawal : Point; (* titik awal *)
PAkhir : Point (* titik akhir *)
end;
TS4 = record (* Segi empat *)
TopLeft : Point; (* Kiri atas *)
BottRight : Point (* Kanan bawah *)
end;
Gambar = record
id : integer; (* identitas gambar *)
case TBentuk : trec of
garis : (G : TGrs);
segi4 : (S4 : TS4);
end;

var
G1, G2 : Gambar;
G3 : Gambar;


begin (* Algoritma *)
(* Cara mengisi nilai *)
(* Gambar adalah garis *)
G1.id := 1;
G1.TBentuk := garis;
G1.G.PAwal.x := 10;
G1.G.PAwal.x :=10;
G1.G.PAkhir.x :=10;
G1.G.PAkhir.x :=10;
(* Gambar adalah segiempat *)
G2.id := 99;
G2.TBentuk := segi4;
G2.S4.TopLeft.x := 0;
G2.S4.TopLeft.x :=0;
G2.S4.BottRight.x :=10;
G2.S4.BottRight.x :=10;

(******* HATI - HATI *******)
(* Perhatikan apa yang terjadi saat kompilasi *)
(* dengan assignment berikut *)
G3.id :=99;
G3.TBentuk :=garis;
G3.S4.TopLeft.x := 0;
G3.S4.TopLeft.x :=0;
G3.S4.BottRight.x :=10;
G3.S4.BottRight.x :=10;
(* Komentar anda ???*)
end.


0 komentar to “Program Rec.”

Posting Komentar