Category : Pascal Source Code
Archive   : PASTUT.ZIP
Filename : ENCAP2.PAS

 
Output of file : ENCAP2.PAS contained in archive : PASTUT.ZIP
(* Chapter 15 - Program 2 *)
program Encapsulation_2;

type
Box = object
length : integer;
width : integer;
constructor Init(len, wid : integer);
procedure Set_Data(len, wid : integer);
function Get_Area : integer;
end;

Pole = object
height : integer;
depth : integer;
constructor Init(hei, dep : integer);
procedure Set_Data(hei, dep : integer);
function Get_Total_Length : integer;
end;

constructor Box.Init(len, wid : integer);
begin
length := len;
width := wid;
end;

constructor Pole.Init(hei, dep : integer);
begin
height := hei;
depth := dep;
end;

procedure Box.Set_Data(len, wid : integer);
begin
length := len;
width := wid;
end;

function Box.Get_Area : integer;
begin
Get_Area := length * width;
end;

procedure Pole.Set_Data(hei, dep : integer);
begin
height := hei;
depth := dep;
end;

function Pole.Get_Total_length : integer;
begin
Get_Total_length := height + depth;
end;

var Small, Medium, Large : Box;
Short, Average, Tall : Pole;

begin

Small.Init(8,8);
Medium.Init(10,12);
Large.Init(15,20);
Short.Init(8,2);
Average.Init(12,3);
Tall.Init(17,4);

WriteLn('The area of the small box is ',Small.Get_Area);
WriteLn('The area of the medium box is ',Medium.Get_Area);
WriteLn('The area of the large box is ',Large.Get_Area);
WriteLn('The overall length of the short pole is ',
Short.Get_Total_Length);
WriteLn('The overall length of the average pole is ',
Average.Get_Total_Length);
WriteLn('The overall length of the tall pole is ',
Tall.Get_Total_Length);
WriteLn;

Small.Set_Data(6,7);
Short.Set_Data(6,1);
Average.Set_Data(11,2);
WriteLn('The area of the small box is ',Small.Get_Area);
WriteLn('The area of the medium box is ',Medium.Get_Area);
WriteLn('The area of the large box is ',Large.Get_Area);
WriteLn('The overall length of the short pole is ',
Short.Get_Total_Length);
WriteLn('The overall length of the average pole is ',
Average.Get_Total_Length);
WriteLn('The overall length of the tall pole is ',
Tall.Get_Total_Length);

end.




{ Result of execution

The area of the small box is 64
The area of the medium box is 120
The area of the large box is 300
The overall length of the short pole is 10
The overall length of the average pole is 15
The overall length of the tall pole is 21

The area of the small box is 42
The area of the medium box is 120
The area of the large box is 300
The overall length of the short pole is 7
The overall length of the average pole is 13
The overall length of the tall pole is 21

}

  3 Responses to “Category : Pascal Source Code
Archive   : PASTUT.ZIP
Filename : ENCAP2.PAS

  1. Very nice! Thank you for this wonderful archive. I wonder why I found it only now. Long live the BBS file archives!

  2. This is so awesome! 😀 I’d be cool if you could download an entire archive of this at once, though.

  3. But one thing that puzzles me is the “mtswslnkmcjklsdlsbdmMICROSOFT” string. There is an article about it here. It is definitely worth a read: http://www.os2museum.com/wp/mtswslnk/