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.

408 Appendix D<br />

while not End_Of_File loop<br />

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

Get( Ch );<br />

case What_Is_Char( Ch) is<br />

when Letter => No_Letters := No_Letters + 1;<br />

when Digit => No_Digits := No_Digits + 1;<br />

when Punctuation => No_Punct_Chs := No_Punct_Chs + 1;<br />

when Other_Ch => No_Other_Chs := No_Other_Chs + 1;<br />

end case;<br />

end loop;<br />

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

end loop;<br />

Put("Letters are "); Put( No_Letters ); New_L<strong>in</strong>e;<br />

Put("Digits are "); Put( No_Digits ); New_L<strong>in</strong>e;<br />

Put("Punctuation chs are "); Put( No_Punct_Chs ); New_L<strong>in</strong>e;<br />

Put("Other chs are "); Put( No_Punct_Chs ); New_L<strong>in</strong>e;<br />

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

Note:<br />

This only works for the English character set.<br />

A program to pr<strong>in</strong>t the average of three ra<strong>in</strong>fall read<strong>in</strong>gs.<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 />

procedure Order3( A,B,C:<strong>in</strong> out Float ) is<br />

procedure Order2( F,S:<strong>in</strong> out Float ) is<br />

Tmp : Float;<br />

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

if F > S then<br />

Tmp := F; F := S; S := Tmp;<br />

end if;<br />

end Order2;<br />

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

Order2( A, B ); --S L ? (a, b, correct order)<br />

Order2( B, C ); --? ? L ( c is largest)<br />

Order2( A, B ); --S M L (a, b, c ordered )<br />

end Order3;<br />

First,Second,Third : Float;<br />

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

Put("Input 3 ra<strong>in</strong>fall read<strong>in</strong>g ");<br />

Get( First ); Get( Second ); Get( Third ); --Data<br />

Put("Ra<strong>in</strong>fall average is : ");<br />

Put( (First+Second+Third)/3.0, Exp=>0, Aft=>2 ); --Average<br />

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

Order3( First, Second, Third ); --Order<br />

Put("Data values (sorted) are : "); --List<br />

Put( First, Exp=>0, Aft=>2 ); Put(" ");<br />

Put( Second, Exp=>0, Aft=>2 ); Put(" ");<br />

Put( Third, Exp=>0, Aft=>2 ); Put(" ");<br />

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

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

From chapter 5<br />

A class Performance that represents the number of seats at a c<strong>in</strong>ema performance.<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!