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.

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

they expected. The computer obeys the programm<strong>in</strong>g language statements exactly. However, <strong>in</strong> their formulation<br />

the novice programmer has formulated a solution that does not solve the problem correctly.<br />

1.4 A small problem<br />

A local orchard sells some of its rare variety apples <strong>in</strong> its local farm shop. However, the farm shop has no electric<br />

power and hence uses a set of scales which just give the weight of the purchased product. A customer buy<strong>in</strong>g<br />

apples, fills a bag full of apples and takes the apples to the shop assistant who weighs the apples to determ<strong>in</strong>e their<br />

weight <strong>in</strong> kilograms and then multiples the weight by the price per kilogram.<br />

If the shop assistant is good at mental arithmetic they can perform the calculation <strong>in</strong> their head, or if mental<br />

arithmetic is not their strong po<strong>in</strong>t they can use an alternative means of determ<strong>in</strong><strong>in</strong>g the cost of the apples.<br />

1.5 Solv<strong>in</strong>g the problem us<strong>in</strong>g a calculator<br />

For example, to solve the very simple problem of calculat<strong>in</strong>g the cost of 5.2 kilos of apples at £1.20 a kilo us<strong>in</strong>g a<br />

pocket calculator the follow<strong>in</strong>g 4 steps are performed:<br />

Pocket calculator Step Steps performed<br />

6.24<br />

S M / *<br />

7 8 9 -<br />

4 5 6 +<br />

1<br />

2<br />

3<br />

Enter the cost of a kilo of apples:<br />

C 1 . 2 0<br />

Enter the operation to be performed:<br />

*<br />

Enter the number of kilos to be bought:<br />

5 . 2<br />

1 2 3<br />

0 .<br />

C<br />

=<br />

4<br />

Enter calculate<br />

=<br />

Note: The keys on the calculator are:<br />

C<br />

Clear the display and turn on the calculator if off<br />

S<br />

Save the contents of the display <strong>in</strong>to memory<br />

M<br />

Retrieve the contents of the memory<br />

+ - * / Arithmetic operations<br />

* Multiply / Division<br />

+ plus - m<strong>in</strong>us<br />

= Calculate<br />

When entered, these actions cause the calculation 1.20 * 5.2 to be evaluated and displayed. In solv<strong>in</strong>g the<br />

problem, the problem is broken down <strong>in</strong>to several very simple steps. These steps are <strong>in</strong> the ‘language’ that the<br />

calculator understands. By obey<strong>in</strong>g these simple <strong>in</strong>structions the calculator ‘solves’ the problem of the cost of 5.2<br />

kilos of apples at £1.20 a kilo.<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!