home *** CD-ROM | disk | FTP | other *** search
/ Chip 1995 March / CHIP3.mdf / programm / prog4 / answers / ch20_3.ada < prev    next >
Encoding:
Text File  |  1991-07-01  |  1.4 KB  |  65 lines

  1.                        -- Chapter 20 - Programming exercise 3
  2. with Text_IO;
  3. use Text_IO;
  4.  
  5. procedure CH20_3 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.    Grand_Total      : INTEGER;
  17.  
  18.    function "+"(Record1, Record2 : THREE_INTS) return THREE_INTS is
  19.    Temp : THREE_INTS;
  20.    begin
  21.       Temp.Length := Record1.Length + Record2.Length;
  22.       Temp.Height := Record1.Height + Record2.Height;
  23.       Temp.Width := Record1.Width + Record2.Width;
  24.       return Temp;
  25.    end "+";
  26.  
  27.    function "+"(Record1, Record2 : THREE_INTS) return INTEGER is
  28.    Total : INTEGER;
  29.    begin
  30.       Total := Record1.Length + Record2.Length +
  31.                Record1.Height + Record2.Height +
  32.                Record1.Width  + Record2.Width;
  33.       return Total;
  34.    end "+";
  35.  
  36. begin
  37.    Big.Length := 10 + 2;
  38.    Big.Height := 22;
  39.    Big.Width := 17;
  40.    Medium.Length := 5;
  41.    Medium.Height := 7;
  42.    Medium.Width := 4;
  43.    Sum := Big + Medium;
  44.    Put("The sum is");
  45.    Put(Sum.Length);
  46.    Put(Sum.Height);
  47.    Put(Sum.Width);
  48.    New_Line;
  49.  
  50.    Grand_Total := Big + Medium;
  51.    Put("The grand total is ");
  52.    Put(Grand_Total);
  53.    New_Line;
  54.  
  55. end CH20_3;
  56.  
  57.  
  58.  
  59.  
  60. -- Result of Execution
  61.  
  62. -- The sum is    17    29    21
  63. -- The grand total is    67
  64.  
  65.