Previous topic |
Ada Home Page |
Index
User defined exceptions
Package specification
package vector_package is
type vector is array (integer range <>) of float;
function add (v1,v2 : vector) return vector;
function scalar_product (v1,v2 : vector) return float;
LENGTH_ERROR : exception;
end vector_package;
Package body
package body vector_package is
function add (v1,v2 : vector) return vector is
begin
...
end add;
function scalar_product (v1,v2 : vector) return float is
sum : float := 0.0;
temp : vector(v1'RANGE);
begin
if v1'LENGTH /= v2'LENGTH then
raise LENGTH_ERROR;
end if;
temp := v2;
for i in v1'RANGE loop
sum := sum + v1(i)*temp(i);
end loop;
return sum;
end scalar_product;
end vector_package;
Previous topic |
Ada Home Page |
Index
c-lokan@adfa.oz.au / 26 Feb 96