home *** CD-ROM | disk | FTP | other *** search
- -- Chapter 20 - Programming exercise 3
- with Text_IO;
- use Text_IO;
-
- procedure CH20_3 is
-
- package Int_IO is new Text_IO.Integer_IO(INTEGER);
- use Int_IO;
-
- type THREE_INTS is
- record
- Length, Height, Width : INTEGER;
- end record;
-
- Big, Medium, Sum : THREE_INTS;
- Grand_Total : INTEGER;
-
- function "+"(Record1, Record2 : THREE_INTS) return THREE_INTS is
- Temp : THREE_INTS;
- begin
- Temp.Length := Record1.Length + Record2.Length;
- Temp.Height := Record1.Height + Record2.Height;
- Temp.Width := Record1.Width + Record2.Width;
- return Temp;
- end "+";
-
- function "+"(Record1, Record2 : THREE_INTS) return INTEGER is
- Total : INTEGER;
- begin
- Total := Record1.Length + Record2.Length +
- Record1.Height + Record2.Height +
- Record1.Width + Record2.Width;
- return Total;
- end "+";
-
- begin
- Big.Length := 10 + 2;
- Big.Height := 22;
- Big.Width := 17;
- Medium.Length := 5;
- Medium.Height := 7;
- Medium.Width := 4;
- Sum := Big + Medium;
- Put("The sum is");
- Put(Sum.Length);
- Put(Sum.Height);
- Put(Sum.Width);
- New_Line;
-
- Grand_Total := Big + Medium;
- Put("The grand total is ");
- Put(Grand_Total);
- New_Line;
-
- end CH20_3;
-
-
-
-
- -- Result of Execution
-
- -- The sum is 17 29 21
- -- The grand total is 67
-
-