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.

368 Appendix A<br />

The follow<strong>in</strong>g code will execute until the condition sunny is met.<br />

loop --Repeat<br />

Work; -- Perform work<br />

exit when Sunny; -- exit from loop when sunny<br />

end loop; --<br />

Class declaration and implementation<br />

package Class_Account is<br />

type Account is tagged private;<br />

type Money is delta 0.01 digits 8; --<br />

subtype Pmoney is Money range 0.0 .. Money'Last; --+ve Money<br />

procedure Deposit( The:<strong>in</strong> out Account; Amount:<strong>in</strong> Pmoney );<br />

procedure Withdraw( The:<strong>in</strong> out Account;<br />

Amount:<strong>in</strong> Pmoney; Get:out Pmoney );<br />

function Balance( The:<strong>in</strong> Account ) return Money;<br />

private<br />

type Account is tagged record --Instance variables<br />

Balance_Of : Money := 0.00; --Amount on deposit<br />

M<strong>in</strong>_Balance : Money := 0.00; --M<strong>in</strong>imum Balance<br />

end record;<br />

end Class_Account;<br />

package body Class_Account is<br />

procedure Deposit( The:<strong>in</strong> out Account; Amount:<strong>in</strong> Pmoney ) is<br />

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

The.Balance_Of := The.Balance_Of + Amount;<br />

end Deposit;<br />

-- Procedures withdraw and balance<br />

end Class_Account;<br />

Inheritance<br />

with Class_Account;<br />

use Class_Account;<br />

package Class_Interest_Account is<br />

type Interest_Account is new Account with private;<br />

type Imoney is digits Money'digits+2; --<br />

procedure End_Of_Day( The:<strong>in</strong> out Interest_Account );<br />

procedure Interest_Credit( The:<strong>in</strong> out Interest_Account );<br />

procedure Interest_Accumulate( The:<strong>in</strong> out Interest_Account;<br />

Amount: <strong>in</strong> Imoney );<br />

private<br />

Daily_Interest_Rate: constant Imoney := 0.000133680617;<br />

type Interest_Account is new Account with record<br />

Accumulated_Interest : Imoney := 0.00; --To date<br />

end record;<br />

The_Interest_Rate : Imoney := Daily_Interest_Rate;<br />

end Class_Interest_Account;<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!