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

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Appendix D: Answers to selected exercises<br />

From chapter 2<br />

A program to pr<strong>in</strong>t the first 20 numbers.<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> 1 .. 20 loop<br />

Put( Integer'Image( I ) ); New_L<strong>in</strong>e;<br />

end loop;<br />

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

A program to pr<strong>in</strong>t the 8 times table.<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> 1 .. 12 loop<br />

Put( " 8 * " ); Put( Integer'Image(I) ); Put(" = ");<br />

Put( Integer'Image( I*8 ) ); New_L<strong>in</strong>e;<br />

end loop;<br />

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

A program to pr<strong>in</strong>t numbers <strong>in</strong> the Fibonacci series.<br />

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

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

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

First, Second, Next : Integer;<br />

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

First := 0;<br />

Second := 1;<br />

Put( Integer'Image(1) ); New_L<strong>in</strong>e;<br />

while Second < 10000 loop<br />

Put( Integer'Image( Second ) ); New_L<strong>in</strong>e;<br />

Next := First + Second;<br />

First := Second;<br />

Second := Next;<br />

end loop;<br />

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

A program to pr<strong>in</strong>t a character table.<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!