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 407<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 />

Name_Length : constant Positive := 20;<br />

type Name_Range is range 1 .. Name_Length;<br />

Ch : Character;<br />

Mark: Integer;<br />

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

while not End_Of_File loop<br />

for I <strong>in</strong> Name_Range loop<br />

Get(Ch); Put(Ch);<br />

end loop;<br />

Get( Mark );<br />

case Mark is<br />

when 0 .. 39 => Put("F");<br />

when 40 .. 49 => Put("D");<br />

when 50 .. 59 => Put("C");<br />

when 60 .. 69 => Put("B");<br />

when 70 ..100 => Put("A");<br />

when others => Put("Invalid data");<br />

end case;<br />

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

end loop;<br />

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

From chapter 4<br />

A program to pr<strong>in</strong>t statistics on the number of different types of character <strong>in</strong> a file.<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 />

type Char is ( Digit, Punctuation, Letter, Other_Ch );<br />

function What_Is_Char( Ch:<strong>in</strong> Character ) return Char is<br />

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

case Ch is<br />

when 'a' .. 'z' | 'A' .. 'Z' => return Letter;<br />

when '0' .. '9' => return Digit;<br />

when ',' | '.' | ';' | ':' => return Punctuation;<br />

when others => return Other_Ch;<br />

end case;<br />

end What_Is_Char;<br />

No_Letters : Natural := 0;<br />

No_Digits : Natural := 0;<br />

No_Punct_Chs : Natural := 0;<br />

No_Other_Chs : Natural := 0;<br />

Ch : Character;<br />

beg<strong>in</strong><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!