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.

56 <strong>Ada</strong> <strong>in</strong>troduction: Part 2<br />

Height_Metres is of subtype Metres, a range check is performed on the assigned value. No conversion is<br />

required when Height_Metres is output as its type Metres is a subtype of Float.<br />

An example of a user's <strong>in</strong>teraction with the program is shown below:<br />

Enter person's height <strong>in</strong> Inches 73.0<br />

Height <strong>in</strong> Metres is 1.85<br />

4.18 Relational operators<br />

The logical comparison operators are:<br />

= equal<br />

/= not equal<br />

< less than<br />

> greater than<br />

= greater than or equal<br />

The relational operators are used to establish the truth of a relationship between two values. The result is of type<br />

Boolean. For example:<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 />

Temperature : Integer; --Temperature <strong>in</strong> Centigrade<br />

Hot : Boolean; --Is it hot<br />

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

Get( Temperature );<br />

if Temperature > 24 then<br />

Put("It's warm"); New_L<strong>in</strong>e;<br />

end if;<br />

Hot := Temperature > 30;<br />

if Hot then<br />

Put("It's hot"); New_L<strong>in</strong>e;<br />

end if;<br />

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

4.18.1 Boolean operators<br />

Boolean values may be comb<strong>in</strong>ed with the follow<strong>in</strong>g operators:<br />

and logical and Note: Both LHS and RHS evaluated<br />

or logical or Note: Both LHS and RHS evaluated<br />

and then logical and Note: RHS only evaluated if LHS TRUE<br />

or else logical or Note: RHS only evaluated if LHS FALSE<br />

xor<br />

Exclusive or,<br />

True xor False => True False xor True => True<br />

True xor True => False False xor False => False<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!