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 405<br />

with <strong>Ada</strong>.Text_Io;<br />

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

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

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

for I <strong>in</strong> 32 .. 127 loop<br />

Put( "Character " ); Put( Character'Val(I) );<br />

Put( " is represented by code " ); Put( Integer'Image(I) );<br />

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

end loop;<br />

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

From chapter 3<br />

A program to pr<strong>in</strong>t an arbitrary time table <strong>in</strong> the range 1 .. 20.<br />

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

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

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

subtype Valid_Times_Table is Integer range 1 .. 20;<br />

Table, Last : Integer;<br />

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

if Argument_Count >= 1 then<br />

Get( Argument(1), Table, Last );<br />

if Table <strong>in</strong> Valid_Times_Table then<br />

Put("The "); Put( Table, Width=>2 );<br />

Put(" times table is"); New_L<strong>in</strong>e;<br />

for I <strong>in</strong> 1 .. 12 loop<br />

Put( Table, Width=>2 ); Put( " * " );<br />

Put( I, Width=>2 ); Put(" = ");<br />

Put( I*Table, Width=>3 ); New_L<strong>in</strong>e;<br />

end loop;<br />

else<br />

Put("Number not valid"); New_L<strong>in</strong>e;<br />

end if;<br />

else<br />

Put("No argument specified"); New_L<strong>in</strong>e;<br />

end if;<br />

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

A program to determ<strong>in</strong>e if a number is prime or not.<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!