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.

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

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

A computer programm<strong>in</strong>g language is used by a programmer to express the solution to a problem <strong>in</strong> terms<br />

that the computer system can understand. This chapter looks at how to solve a small problem us<strong>in</strong>g the<br />

computer programm<strong>in</strong>g language <strong>Ada</strong> <strong>95</strong>.<br />

1.1 Computer programm<strong>in</strong>g<br />

Solv<strong>in</strong>g a problem by implement<strong>in</strong>g the solution us<strong>in</strong>g a computer programm<strong>in</strong>g language is a meticulous process.<br />

In essence the problem is expressed <strong>in</strong> terms of a very stylized language <strong>in</strong> which every detail must be correct.<br />

However, this is a reward<strong>in</strong>g process both <strong>in</strong> the sense of achievement when the program is completed, and<br />

usually the eventual f<strong>in</strong>ancial reward obta<strong>in</strong>ed for the effort.<br />

Like the planet on which we live where there are many different natural languages, so the computer world also<br />

has many different programm<strong>in</strong>g languages. The programm<strong>in</strong>g language <strong>Ada</strong> <strong>95</strong> is just one of the many computer<br />

programm<strong>in</strong>g languages used today.<br />

1.2 Programm<strong>in</strong>g languages<br />

In the early days of comput<strong>in</strong>g circa 1<strong>95</strong>0s, computer programs had to be written directly <strong>in</strong> the mach<strong>in</strong>e<br />

<strong>in</strong>structions of the computer. Soon assembly languages were <strong>in</strong>troduced that allowed the programmer to write<br />

these <strong>in</strong>structions symbolically. An assembler program would then translate the programmer’s symbolic<br />

<strong>in</strong>structions <strong>in</strong>to the real mach<strong>in</strong>e code <strong>in</strong>structions of the computer. For example, to calculate the cost of a<br />

quantity of apples us<strong>in</strong>g an assembly language the follow<strong>in</strong>g style of symbolic <strong>in</strong>structions would be written by a<br />

programmer:<br />

LDA AMOUNT_OF_OF_APPLES ; Load <strong>in</strong>to the accumulator # pounds<br />

MLT PRICE_PER_POUND ; Multiply by cost per pound of apples<br />

STA COST_OF_APPLES ; Save result<br />

Note:<br />

Each assembly language <strong>in</strong>struction corresponds to a mach<strong>in</strong>e code <strong>in</strong>struction.<br />

In the period 1<strong>95</strong>7—1<strong>95</strong>8 the first versions of the high-level languages FORTRAN & COBOL were developed. In<br />

these high-level programm<strong>in</strong>g languages programmers could express many ideas <strong>in</strong> terms of the problem rather<br />

than <strong>in</strong> terms of the mach<strong>in</strong>e architecture. A compiler for the appropriate language would translate the<br />

programmer’s high level statements <strong>in</strong>to the specific mach<strong>in</strong>e code <strong>in</strong>structions of the target mach<strong>in</strong>e. Advantages<br />

of the use of a compiler <strong>in</strong>clude:<br />

• Ga<strong>in</strong>s <strong>in</strong> programmer productivity as the solution is expressed <strong>in</strong> terms of the problem rather<br />

than <strong>in</strong> terms of the mach<strong>in</strong>e.<br />

• If written correctly, programs may be compiled <strong>in</strong>to the mach<strong>in</strong>e <strong>in</strong>structions of many<br />

different mach<strong>in</strong>es. Hence, the program may be moved between mach<strong>in</strong>es without hav<strong>in</strong>g to<br />

be re-written.<br />

For example, the same calculation to calculate the cost of apples is expressed <strong>in</strong> FORTRAN as:<br />

COST = PRICE * AMOUNT<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!