with ada.exceptions; with ada.integer_text_io; package body pairpkg is function NewPair return Pair is begin return (0, 0); end NewPair; function NewPair(x, y: Integer) return Pair is temp: Pair := (x, y); begin return temp; end NewPair; function tos(i: integer) return String is s: String := Integer'Image(i); begin return s; end tos; function toString(p: Pair) return String is S: String := "(" & tos(p.x) & ", " & tos(p.y) & ")"; begin return s; end toString; function distanceToOrigin(p: Pair) return Natural is result: Natural; begin result := abs p.x + abs p.y; return result; exception when constraint_error => raise Pair_Distance_Too_Large; when e: others => raise Unknown_Pair_Error with ada.exceptions.exception_message(e); end distanceToOrigin; function distanceBetween(p1, p2: Pair) return Natural is result: Natural; begin result := abs(p1.x - p2.x) + abs(p1.y - p2.y); return result; exception when constraint_error => raise Pair_Distance_Too_Large; when e: others => raise Unknown_Pair_Error with ada.exceptions.exception_message(e); end distanceBetween; function reflect(p: in Pair) return Pair is t: Pair; begin t.x := p.y; t.y := p.x; return t; end reflect; procedure reflectMe(p: in out Pair) is t: constant integer := p.x; begin p.x := p.y; p.y := t; end reflectMe; procedure put(f: ada.text_io.file_type; p: in Pair) is begin ada.integer_text_io.put(f, p.x); ada.integer_text_io.put(f, p.y); end put; procedure put(p: in Pair) is use ada.integer_text_io; begin put(ada.text_io.standard_output,p); end put; -- procedure put(p: in Pair) is -- use ada.integer_text_io; -- begin -- put(p.x); -- put(p.y); -- end put; end pairpkg;