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.

92 Packages as classes<br />

6.14 Exercises<br />

Construct the follow<strong>in</strong>g classes:<br />

• Account_with_overdraft<br />

Construct a class which represents an account on which a customer is allowed to go overdrawn. You<br />

should restrict the amount the customer is allowed to go overdrawn. The methods of this class are:<br />

Method<br />

Responsibility<br />

Balance<br />

Deliver the balance of the account.<br />

Deposit<br />

Deposit money <strong>in</strong>to the account<br />

Set_Overdraft_Limit Set the overdraft limit.<br />

Statement<br />

Pr<strong>in</strong>t a statement of the current balance of<br />

the account.<br />

Withdraw<br />

Withdraw money from the account.<br />

• C<strong>in</strong>ema Performance Attendance<br />

A class Performance, an <strong>in</strong>stance of which represents the seats at a particular show<strong>in</strong>g of a film, has<br />

the follow<strong>in</strong>g methods:<br />

Method<br />

Book_seats<br />

Cancel<br />

Sales<br />

Seats_Free<br />

Responsibility<br />

Book n seats at the performance.<br />

Unbook n seats.<br />

Return the value of the seats sold at this<br />

performance.<br />

Return the number of seats that are still<br />

unsold.<br />

Thus on an <strong>in</strong>stance of Performance the follow<strong>in</strong>g actions can be performed:<br />

• Book a number of seats<br />

• F<strong>in</strong>d out the number of unsold seats at the performance<br />

• Cancel the book<strong>in</strong>g for n seats.<br />

• Return the value of the seats sold at this performance.<br />

• Library Book<br />

A class to represent a book <strong>in</strong> a library, such that the follow<strong>in</strong>g operations can be processed:<br />

(a)<br />

(b)<br />

(c)<br />

(d)<br />

Loan the book.<br />

Mark the book as be<strong>in</strong>g reserved. Only one outstand<strong>in</strong>g reservation is allowed on a book.<br />

Ask if a book can be loaned. A book can only be loaned if it is not already on loan or is not<br />

reserved.<br />

Return the book.<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!