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 D 417<br />

with <strong>Ada</strong>.Text_Io, <strong>Ada</strong>.Integer_Text_Io, Class_Queue_Int;<br />

use <strong>Ada</strong>.Text_Io, <strong>Ada</strong>.Integer_Text_Io, Class_Queue_Int;<br />

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

Number_Queue : Queue; --Queue of numbers<br />

Action : Character; --Action<br />

Number : Integer; --Number processed<br />

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

while not End_Of_File loop<br />

while not End_Of_L<strong>in</strong>e loop<br />

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

Get( Action );<br />

case Action is --Process action<br />

when '+' =><br />

Get( Number ); Add(Number_Queue,Number);<br />

Put("add number = "); Put(Number); New_L<strong>in</strong>e;<br />

when '-' =><br />

Sub(Number_Queue,Number);<br />

Put("remove number = "); Put(Number); New_L<strong>in</strong>e;<br />

when others =><br />

Put("Invalid action"); New_L<strong>in</strong>e;<br />

end case;<br />

exception<br />

when Queue_Error =><br />

Put("Exception Queue_error"); New_L<strong>in</strong>e;<br />

when Data_Error =><br />

Put("Not a number"); New_L<strong>in</strong>e;<br />

when End_Error =><br />

Put("Unexpected end of file"); New_L<strong>in</strong>e; exit;<br />

end;<br />

end loop;<br />

Skip_L<strong>in</strong>e;<br />

end loop;<br />

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

From chapter 19<br />

A task type which allows repeated calculations of a factorial value to be made is:<br />

package Pack_Factorial is<br />

task type Task_Factorial is<br />

entry Calculate( F:<strong>in</strong> Natural );<br />

entry Deliver( Res:out Natural );<br />

entry F<strong>in</strong>ish;<br />

end Task_Factorial;<br />

end Pack_Factorial;<br />

--Specification<br />

--Rendezvous<br />

--Rendezvous<br />

--Rendezvous<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!