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

  1.                                      (* Chapter 15 - Program 3 *)
  2. program Virtual_3;
  3.  
  4. { ******************** class definitions **********************}
  5.  
  6. type
  7.    Vehicle = object
  8.       Wheels : integer;
  9.       Weight : real;
  10.       constructor Init(In_Wheels : integer; In_Weight : real);
  11.       procedure Message; virtual;
  12.    end;
  13.  
  14.    Vehicle_Pointer = ^Vehicle;
  15.  
  16.  
  17.    Car = object(Vehicle)
  18.       Passenger_Load : integer;
  19.       constructor Init(In_Wheels : integer;
  20.                        In_Weight : real;
  21.                        People    : integer);
  22.       procedure Message; virtual;
  23.    end;
  24.  
  25.    Car_Pointer = ^Car;
  26.  
  27.  
  28.    Truck = Object(Vehicle)
  29.       Passenger_Load : integer;
  30.       Payload        : real;
  31.       constructor Init(People : integer;
  32.                        Max_Load : real;
  33.                        In_Wheels : integer;
  34.                        In_Weight : real);
  35.       procedure Message; virtual;
  36.    end;
  37.  
  38.    Truck_Pointer = ^Truck;
  39.  
  40.  
  41. { ********************* class implementations ******************** }
  42.  
  43.    constructor Vehicle.Init(In_Wheels : integer; In_Weight : real);
  44.    begin
  45.       Wheels := In_Wheels;
  46.       Weight := In_Weight;
  47.    end;
  48.  
  49.    procedure Vehicle.Message;
  50.    begin
  51.       WriteLn('This message is from the vehicle.');
  52.    end;
  53.  
  54.  
  55.  
  56.    constructor Car.Init(In_Wheels : integer;
  57.                         In_Weight : real;
  58.                         People    : integer);
  59.    begin
  60.       Wheels := In_Wheels;
  61.       Weight := In_Weight;
  62.       Passenger_Load := People;
  63.    end;
  64.  
  65.    procedure Car.Message;
  66.    begin
  67.       WriteLn('This message is from the car.');
  68.    end;
  69.  
  70.  
  71.  
  72.    constructor Truck.Init(People : integer;
  73.                           Max_Load : real;
  74.                           In_Wheels : integer;
  75.                           In_Weight : real);
  76.    begin
  77.       Passenger_Load := People;
  78.       Payload := Max_Load;
  79.       Wheels := In_Wheels;
  80.       Weight := In_Weight;
  81.    end;
  82.  
  83.    procedure Truck.Message;
  84.    begin
  85.       WriteLn('This message is from the truck.');
  86.    end;
  87.  
  88.  
  89.  
  90.    procedure Output_A_Message(VAR Machine : Vehicle_Pointer);
  91.    begin
  92.       Write('This is from Output_A_message; ');
  93.       Machine^.Message;
  94.    end;
  95.  
  96.  
  97. { ************************ main program ************************** }
  98.  
  99. var Unicycle : Vehicle_Pointer;
  100.     Sedan    : Car_Pointer;
  101.     Semi     : Truck_Pointer;
  102.  
  103. begin
  104.    New(Unicycle);
  105.    New(Sedan);
  106.    New(Semi);
  107.  
  108.    Unicycle^.Init(1, 12.0);
  109.    Sedan^.Init(4, 2100.0, 5);
  110.    Semi^.Init(1, 25000.0, 18, 5000.0);
  111.  
  112.    WriteLn;
  113.    Unicycle^.Message;
  114.    Sedan^.Message;
  115.    Semi^.Message;
  116.  
  117.    WriteLn;
  118.    Output_A_Message(Unicycle);
  119.    Dispose(Unicycle);
  120.    Unicycle := Sedan;
  121.    Output_A_Message(Unicycle);
  122.    Unicycle := Semi;
  123.    Output_A_Message(Unicycle);
  124.    Dispose(Sedan);
  125.    Dispose(Semi);
  126.  
  127. end.
  128.  
  129.  
  130.  
  131.  
  132. { Result of execution
  133.  
  134. This message is from the vehicle.
  135. This message is from the car.
  136. This message is from the truck.
  137.  
  138. This is from Output_A_Message; This message is from the vehicle.
  139. This is from Output_A_Message; This message is from the car.
  140. This is from Output_A_Message; This message is from the truck.
  141.  
  142. }