home *** CD-ROM | disk | FTP | other *** search
/ ProfitPress Mega CDROM2 …eeware (MSDOS)(1992)(Eng) / ProfitPress-MegaCDROM2.B6I / PROG / PASCAL / PASTUT24.ZIP / PTUTRSRC.ZIP / ENCAP2.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  1989-12-01  |  3.0 KB  |  112 lines

  1.                                      (* Chapter 15 - Program 2 *)
  2. program Encapsulation_2;
  3.  
  4. type
  5.    Box = object
  6.       length : integer;
  7.       width  : integer;
  8.       constructor Init(len, wid : integer);
  9.       procedure Set_Data(len, wid : integer);
  10.       function Get_Area : integer;
  11.    end;
  12.  
  13.    Pole = object
  14.       height : integer;
  15.       depth  : integer;
  16.       constructor Init(hei, dep : integer);
  17.       procedure Set_Data(hei, dep : integer);
  18.       function Get_Total_Length : integer;
  19.    end;
  20.  
  21.    constructor Box.Init(len, wid : integer);
  22.    begin
  23.       length := len;
  24.       width := wid;
  25.    end;
  26.  
  27.    constructor Pole.Init(hei, dep : integer);
  28.    begin
  29.       height := hei;
  30.       depth := dep;
  31.    end;
  32.  
  33.    procedure Box.Set_Data(len, wid : integer);
  34.    begin
  35.       length := len;
  36.       width := wid;
  37.    end;
  38.  
  39.    function Box.Get_Area : integer;
  40.    begin
  41.       Get_Area := length * width;
  42.    end;
  43.  
  44.    procedure Pole.Set_Data(hei, dep : integer);
  45.    begin
  46.       height := hei;
  47.       depth := dep;
  48.    end;
  49.  
  50.    function Pole.Get_Total_length : integer;
  51.    begin
  52.       Get_Total_length := height + depth;
  53.    end;
  54.  
  55. var Small, Medium, Large : Box;
  56.     Short, Average, Tall : Pole;
  57.  
  58. begin
  59.  
  60.    Small.Init(8,8);
  61.    Medium.Init(10,12);
  62.    Large.Init(15,20);
  63.    Short.Init(8,2);
  64.    Average.Init(12,3);
  65.    Tall.Init(17,4);
  66.  
  67.    WriteLn('The area of the small box is ',Small.Get_Area);
  68.    WriteLn('The area of the medium box is ',Medium.Get_Area);
  69.    WriteLn('The area of the large box is ',Large.Get_Area);
  70.    WriteLn('The overall length of the short pole is ',
  71.                                           Short.Get_Total_Length);
  72.    WriteLn('The overall length of the average pole is ',
  73.                                         Average.Get_Total_Length);
  74.    WriteLn('The overall length of the tall pole is ',
  75.                                            Tall.Get_Total_Length);
  76.    WriteLn;
  77.  
  78.    Small.Set_Data(6,7);
  79.    Short.Set_Data(6,1);
  80.    Average.Set_Data(11,2);
  81.    WriteLn('The area of the small box is ',Small.Get_Area);
  82.    WriteLn('The area of the medium box is ',Medium.Get_Area);
  83.    WriteLn('The area of the large box is ',Large.Get_Area);
  84.    WriteLn('The overall length of the short pole is ',
  85.                                           Short.Get_Total_Length);
  86.    WriteLn('The overall length of the average pole is ',
  87.                                         Average.Get_Total_Length);
  88.    WriteLn('The overall length of the tall pole is ',
  89.                                            Tall.Get_Total_Length);
  90.  
  91. end.
  92.  
  93.  
  94.  
  95.  
  96. { Result of execution
  97.  
  98. The area of the small box is 64
  99. The area of the medium box is 120
  100. The area of the large box is 300
  101. The overall length of the short pole is 10
  102. The overall length of the average pole is 15
  103. The overall length of the tall pole is 21
  104.  
  105. The area of the small box is 42
  106. The area of the medium box is 120
  107. The area of the large box is 300
  108. The overall length of the short pole is 7
  109. The overall length of the average pole is 13
  110. The overall length of the tall pole is 21
  111.  
  112. }