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.

222 Polymorphism<br />

15.5.1 Putt<strong>in</strong>g it all together<br />

The revised version of the class Account can be used <strong>in</strong> the same way as previously. In this program, the<br />

procedure Statement seen earlier <strong>in</strong> Section 6.3.2 is used to pr<strong>in</strong>t details about an <strong>in</strong>dividual account.<br />

with <strong>Ada</strong>.Text_Io, Class_Account, Statement;<br />

use <strong>Ada</strong>.Text_Io, Class_Account;<br />

procedure Ma<strong>in</strong> is<br />

My_Account:Account;<br />

Obta<strong>in</strong> :Money;<br />

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

Statement( My_Account );<br />

Put("Deposit £100.00 <strong>in</strong>to account"); New_L<strong>in</strong>e;<br />

Deposit( My_Account, 100.00 );<br />

Statement( My_Account );<br />

Put("Withdraw £80.00 from account"); New_L<strong>in</strong>e;<br />

Withdraw( My_Account, 80.00, Obta<strong>in</strong> );<br />

Statement( My_Account );<br />

Put("Deposit £200.00 <strong>in</strong>to account"); New_L<strong>in</strong>e;<br />

Deposit( My_Account, 200.00 );<br />

Statement( My_Account );<br />

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

which when run, would produce:<br />

M<strong>in</strong>i statement: The amount on deposit is £ 0.00<br />

Deposit _100.00 <strong>in</strong>to account<br />

M<strong>in</strong>i statement: The amount on deposit is £100.00<br />

Withdraw _80.00 from account<br />

M<strong>in</strong>i statement: The amount on deposit is £20.00<br />

Deposit _200.00 <strong>in</strong>to account<br />

M<strong>in</strong>i statement: The amount on deposit is £220.00<br />

Note:<br />

The class Account allows the assignment of an <strong>in</strong>stance of an Account. The consequences of this<br />

are that two objects will share the same storage. Section 17.4 explores and discusses this <strong>in</strong> detail and<br />

shows a solution to the problem.<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!