with ada.text_io; use ada.text_io;
with ada.integer_text_io; use ada.integer_text_io;
procedure array2 is
type animal_array is array(-3 .. 3) of Natural;
cat_count: animal_array := (-3 | -1 | 1 | 3 => 1, others => 0);
dog_count: animal_array := (-2 | 0 | 2 => 1, others => 0);
animal_count: animal_array;
total_dogs, total_cats, total_animals: Natural := 0;
procedure fill(ca, da, aa: out animal_array) is
begin
ca := (-3 | -1 | 1 | 3 => 1, others => 0);
da := (-2 | 0 | 2 => 1, others => 0);
for i in ca'range loop
aa(i) := ca(i) + da(i);
end loop;
end fill;
procedure total(ca, da, aa: in animal_array; tc, td, ta: out Natural) is
begin
tc := 0;
td := 0;
ta := 0;
for i in cat_count'first .. cat_count'last loop
tc := tc + ca(i);
end loop;
for i in dog_count'range loop
td := td + da(i);
end loop;
for a of aa loop
ta := ta + a;
end loop;
end total;
procedure print(tc, td, ta: Natural) is
w: constant Natural := 5;
begin
put(tc, width => w);
put(td, width => w);
put(td, width => w);
end print;
begin
fill(cat_count, dog_count, animal_count);
total(cat_count, dog_count, animal_count, total_cats, total_dogs, total_animals);
print(total_cats, total_dogs, total_animals);
end array2;