18.10.2014 Views

Object-oriented Software in Ada 95

Object-oriented Software in Ada 95

Object-oriented Software in Ada 95

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Appendix A 369<br />

package body Class_Interest_Account is<br />

procedure Interest_Credit( The:<strong>in</strong> out Interest_Account ) is<br />

beg<strong>in</strong><br />

Deposit( The, Money(The.Accumulated_Interest) ); --Rounds<br />

The.Accumulated_Interest := 0.00;<br />

end Interest_Credit;<br />

-- Procedure calc_<strong>in</strong>terest<br />

end Class_Interest_Account;<br />

Program delay<br />

delay n.m seconds<br />

delay n.m;<br />

delay until a_time;<br />

declare<br />

use <strong>Ada</strong>.Calendar;<br />

beg<strong>in</strong><br />

delay until time_of(2000,1,1,0.0);<br />

-- 24 Hours<br />

end;<br />

Task<br />

task type Task_Factorial is<br />

entry Start( F:<strong>in</strong> Positive );<br />

entry F<strong>in</strong>ish( R:out Positive );<br />

end Task_Factorial;<br />

--Specification<br />

--Rendezvous<br />

--Rendezvous<br />

task body Task_Factorial is --Implementation<br />

Fact : Positive; Answer : Positive := 1;<br />

beg<strong>in</strong><br />

accept Start( F:<strong>in</strong> Positive) do Fact := F; end Start;<br />

for I <strong>in</strong> 2 .. Fact loop Answer := Answer * I; end loop;<br />

accept F<strong>in</strong>ish( R:out Positive ) do R:=Answer; end F<strong>in</strong>ish;<br />

end Task_Factorial;<br />

Communication with a task<br />

procedure Ma<strong>in</strong> is<br />

Factorial : Task_Factorial;<br />

Res : Natural;<br />

beg<strong>in</strong><br />

Factorial.Start(5); Put("Factorial 5 is ");<br />

Factorial.F<strong>in</strong>ish(Res); Put( Res, Width=>4 ); New_L<strong>in</strong>e;<br />

end Ma<strong>in</strong>;<br />

Rendezvous<br />

select statement select with else select with delay<br />

© M A Smith - May not be reproduced without permission

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!