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.

16 Introduction to programm<strong>in</strong>g<br />

which when compiled with additional statements would produce output of the form shown below:<br />

Cost of apples per kilo : 1.20<br />

Kilo's Cost<br />

0.0 0.00<br />

0.1 0.12<br />

0.2 0.24<br />

0.3 0.36<br />

0.4 0.48<br />

0.5 0.60<br />

0.6 0.72<br />

0.7 0.84<br />

0.8 0.96<br />

0.9 1.08<br />

1.0 1.20<br />

1.1 1.32<br />

1.2 1.44<br />

1.3 1.56<br />

1.4 1.68<br />

etc.<br />

Note:<br />

1.15 Self-assessment<br />

Us<strong>in</strong>g Put(Price_Per_Kilo), Put(Kilos_Of_Apples) and Put(Price) will cause the<br />

value to be output <strong>in</strong> scientific notation. To get the effect of the format shown above the Put statements<br />

would need to be changed to:<br />

Put(Price_Per_Kilo) -> Put(Price_Per_Kilo,Exp=>0,Aft=>2)<br />

Put(Kilos_Of_Apples) -> Put(Kilos_Of_Apples,Exp=>0,Aft=>2)<br />

Put(Cost) -> Put(Cost,Exp=>0,Aft=>2).<br />

This is fully expla<strong>in</strong>ed <strong>in</strong> Section 4.6.1.<br />

• What is a computer programm<strong>in</strong>g language?<br />

• What do the follow<strong>in</strong>g fragments of <strong>Ada</strong> <strong>95</strong> code do?<br />

declare<br />

I : Integer;<br />

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

I := 10;<br />

while I > 0 loop<br />

Put( I );<br />

I := I - 1;<br />

end loop;<br />

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

end;<br />

declare<br />

Temperature : Integer;<br />

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

Temperature := 10;<br />

if Temperature > 20 then<br />

Put( "It's Hot!" );<br />

end if;<br />

if Temperature

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!