Previous       Table of Contents       Next

Sample problem

We have selected a very simple problem which will be programmed in most of the languages discussed in this paper. Simple as it is, it should give some idea of the detail required with the early languages and of how programming languages have evolved.

The problem consists of finding the number of items in a given list of numbers and also the sum of these numbers and the maximum number. For sample data we have recorded the following prices of a few paperbooks in the University Bookstore: $20.95, $29.50, $22.50, $13.95 and $19.50. We see that we have purchased 5 books at a total price of $106.40 with the most expensive book costing $29.50. A hand solution to this problem would be to keep a cumulative record of the number of books and the total cost and when necessary updating the record of the most expensive book. Indeed it is this method which will be used in many of the programming languages which will be illustrated here. Only with array languages and spreadsheets may we depart from this item-by-item consideration of the list of prices.

In order to have a convenient means of terminating the computations in most of the programs we shall introduced a fictitious price of $0.00 at the end of the list of valid prices. In this way the repetitive calculations will continue until this price is encountered. Thus in most of the programs the sample data will be the list
      20.95 29.50 22.50 13.95 19.50 0.00 .


Previous       Table of Contents       Next