home *** CD-ROM | disk | FTP | other *** search
/ Chip 1995 March / CHIP3.mdf / programm / prog4 / infix.ada < prev    next >
Encoding:
Text File  |  1991-07-01  |  981 b   |  48 lines

  1.                                        -- Chapter 20 - Program 7
  2. with Text_IO;
  3. use Text_IO;
  4.  
  5. procedure Infix is
  6.  
  7.    package Int_IO is new Text_IO.Integer_IO(INTEGER);
  8.    use Int_IO;
  9.  
  10.    type THREE_INTS is
  11.       record
  12.          Length, Height, Width : INTEGER;
  13.       end record;
  14.  
  15.    Big, Medium, Sum : THREE_INTS;
  16.  
  17.    function "+"(Record1, Record2 : THREE_INTS) return THREE_INTS is
  18.    Temp : THREE_INTS;
  19.    begin
  20.       Temp.Length := Record1.Length + Record2.Length;
  21.       Temp.Height := Record1.Height + Record2.Height;
  22.       Temp.Width := Record1.Width + Record2.Width;
  23.       return Temp;
  24.    end "+";
  25.  
  26. begin
  27.    Big.Length := 10 + 2;
  28.    Big.Height := 22;
  29.    Big.Width := 17;
  30.    Medium.Length := 5;
  31.    Medium.Height := 7;
  32.    Medium.Width := 4;
  33.    Sum := Big + Medium;
  34.    Put("The sum is");
  35.    Put(Sum.Length);
  36.    Put(Sum.Height);
  37.    Put(Sum.Width);
  38.    New_Line;
  39. end Infix;
  40.  
  41.  
  42.  
  43.  
  44. -- Result of Execution
  45.  
  46. -- The sum is    17    29    21
  47.  
  48.