shape.ads
package Shape is
type BOX is
record
Length : INTEGER;
Width : INTEGER;
Height : INTEGER;
end record;
function Make_A_Box(In_Length, In_Width, In_Height : INTEGER)
return BOX;
function "+"(Left, Right : BOX) return BOX;
function "+"(Left : INTEGER; Right : BOX) return BOX;
function "*"(Left : INTEGER; Right : BOX) return BOX;
procedure Print_Box(Input_Box : BOX);
end Shape;
shape.adb
with Ada.Text_IO, Ada.Integer_Text_IO;
use Ada.Text_IO, Ada.Integer_Text_IO;
package body Shape is
function Make_A_Box(In_Length, In_Width, In_Height : INTEGER)
return BOX is
Temp_Box : BOX;
begin
Temp_Box.Length := In_Length;
Temp_Box.Width := In_Width;
Temp_Box.Height := In_Height;
return Temp_Box;
end Make_A_Box;
function "+"(Left, Right : BOX) return BOX is
Temp_Box : BOX;
begin
Temp_Box.Length := Left.Length + Right.Length;
Temp_Box.Width := Left.Width + Right.Width;
Temp_Box.Height := Left.Height + Right.Height;
return Temp_Box;
end "+";
function "+"(Left : INTEGER; Right : BOX) return BOX is
Temp_Box : BOX;
begin
Temp_Box.Length := Left + Right.Length;
Temp_Box.Width := Left + Right.Width;
Temp_Box.Height := Left + Right.Height;
return Temp_Box;
end "+";
function "*"(Left : INTEGER; Right : BOX) return BOX is
Temp_Box : BOX;
begin
Temp_Box.Length := Left * Right.Length;
Temp_Box.Width := Left * Right.Width;
Temp_Box.Height := Left * Right.Height;
return Temp_Box;
end "*";
procedure Print_Box(Input_Box : BOX) is
begin
Put("Length = ");
Put(Input_Box.Length, 3);
Put(" Width = ");
Put(Input_Box.Width, 3);
Put(" Height = ");
Put(Input_Box.Height, 3);
New_Line;
end Print_Box;
end Shape;
main.adb
with Shape;
use type Shape.BOX;
procedure OperOver is
Small_Box : Shape.BOX;
Big_Box : Shape.BOX;
begin
Small_Box := Shape.Make_A_Box(2, 3, 2);
Big_Box := Shape.Make_A_Box(4, 5, 3);
Shape.Print_Box(Small_Box);
Shape.Print_Box(Big_Box);
Shape.Print_Box(Small_Box + Big_Box);
Shape.Print_Box(4 + Small_Box);
Shape.Print_Box(10 * Big_Box);
Shape.Print_Box(Small_Box + 5 * Big_Box);
Shape.Print_Box(Shape."+"(Small_Box, Shape."*"(5, Big_Box)));
end OperOver;