home *** CD-ROM | disk | FTP | other *** search
/ Collection of Hack-Phreak Scene Programs / cleanhpvac.zip / cleanhpvac / PASSRC.ZIP / ENCAP1.PAS < prev    next >
Pascal/Delphi Source File  |  1991-02-04  |  1KB  |  53 lines

  1.                                      (* Chapter 14 - Program 1 *)
  2. program Encapsulation_1;
  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.    constructor Box.Init(len, wid : integer);
  14.    begin
  15.       length := len;
  16.       width := wid;
  17.    end;
  18.  
  19.    procedure Box.Set_Data(len, wid : integer);
  20.    begin
  21.       length := len;
  22.       width := wid;
  23.    end;
  24.  
  25.    function Box.Get_Area : integer;
  26.    begin
  27.       Get_Area := length * width;
  28.    end;
  29.  
  30. var Small, Medium, Large : Box;
  31.  
  32. begin
  33.  
  34.    Small.Init(8,8);
  35.    Medium.Init(10,12);
  36.    Large.Init(15,20);
  37.  
  38.    WriteLn('The area of the small box is ',Small.Get_Area);
  39.    WriteLn('The area of the medium box is ',Medium.Get_Area);
  40.    WriteLn('The area of the large box is ',Large.Get_Area);
  41.  
  42. end.
  43.  
  44.  
  45.  
  46.  
  47. { Result of execution
  48.  
  49. The area of the small box is 64
  50. The area of the medium box is 120
  51. The area of the large box is 300
  52.  
  53. }