comp.lang.ada
 help / color / mirror / Atom feed
From: mfb@mbunix.mitre.org (Michael F Brenner)
Subject: Re: Ada Student Needs Help..
Date: 1997/01/14
Date: 1997-01-14T00:00:00+00:00	[thread overview]
Message-ID: <5bg4un$bct@top.mitre.org> (raw)
In-Reply-To: 1997Jan13.130528.1@eisner


Yes, Rage Matrix, you can use record types.
 
We presume that you are spelling Berverage as you did to avoid 
speculation that you or your instructor partake or preach partakement
in Beverages.

In setting up the objects and methods for your program architecture,
you will probably decide to have an object called a Drink which 
sends messages to objects called Berverages. The messages ask questions
like <what is thy percentage alcohol>, <thy volume in ml>, and <thy 
serving size in ml>. From the responses to these messages you could 
compute the number of 10 ml doses of alcohol the imbiber injests. So 
far, no record types or arrays at all. However, INSIDE the methods 
that ask the questions of the Berverage objects, there will be some
kind of data structure which stores the table of strengths and volumes.
This table can be done in several different ways, and you will have
to make two choices. 

First, the abstract data type to use for the Berverages
must be selected, for example, a record type, an array,
a character string, a linked list, a double linked list, a heap,
a balanced or semi-balanced tree, a graph, an unordered set of tuples
or associative array, a relational database, a sequential disk file,
a random disk file, a human-in-the-loop help desk, a CGI Net search,
a data mining encyclopedia CD-ROM search application, an electronic
interface to a chemical measuring tool, a punched card or paper tape
reader, an indexed sequential floppy dataset, a multiplicative group
based on a numerical generating function, a polynomial approximation,
a dynamic system (with or without chaos), a voice recognition circuit
that rings the 900 hundred phone number for Bartenders anonymous, or
an interface to your robot who knocks up the local pub and gets advice.

Second, the abstract data type to use for the table itself must be selected,
from the list above or others. Actually, there is a data type called a
two-dimensional array which would be a single data structure that takes
the place of the individual data types for the Berverages and the Table
above.

Next, you code the test programs to exercise these data structures
completely.

Finally, you fill in the code for the methods used by the ADTs you have
chosen. The best way to do this is to reuse code from existing libraries,
for example, the PAL. That way you dont actually have to program any
arrays or record types at all. Programming data types is the most fruitful
source of bugs in languages like Ada where you dont use pointers or go_tos.
If you reuse every data structure, you can just do applications level
programming from your operating environment. Another way of reusing code
is dynamically loaded through your operating environment, for example, 
dynamically load the table type through CORBA from another computer that
happens to have the volumes and strengths already loaded, such as the
UBREW brewery in Ottawa, Ontario, Canada that makes this beer and wine
information available through the Algae Gateway at the Net address
http://www.synapse.net/~fti/al.htm. If you absolutely refuse to reuse
the code for your abstract data structures, then you could read a good
book on how to do arrays, such as Edsger Dijkstra, Discipline of Programming.
An example of the code for implementing an array reference to get the
number of millilitres in each container of Berverage is as follows:

    type container_volumes is array (berverages) of ounces; 
    container_volume: constant container_volumes := (8, 16, 20);
    
    function volume (berverage: berverages) return millilitres is

      -- precondition: The container volume array has been 
      --               initialized with an entry for berverage,
      --               which, when multiplied by the number of
      --               millilitres_per_ounce, will not overflow
      --               millilitres'last.

      container: constant ounces := container_volume (berverage);
      berverage_volume: constant millilitres :=
        millilitres_per_ounce * container;
    begin
      -- invariant: If the program counter has arrived at this point
      -- in the program, then the berverage_volume is the number of 
      -- millilitres in one container of the requested berverage.

      return berverage_volume;                    
    end volume; 

Coding arrays is like learning algebra, it requires lots of practice
to get the preconditions and invariants correctly, and in some cases,
to ensure termination of the loops. I recommend a lot of practice,
and a lot of tolerance for an educational system that does not teach
programming by giving you lots of examples of working code, and 
methods of modifying that code to do what you want. Attempting to 
program an array from scratch is bound to result in many frustrating
false starts.
 




  parent reply	other threads:[~1997-01-14  0:00 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1997-01-13  0:00 Ada Student Needs Help baker
1997-01-13  0:00 ` Larry Kilgallen
1997-01-13  0:00   ` Norman H. Cohen
1997-01-14  0:00   ` Michael F Brenner [this message]
1997-01-17  0:00   ` Steve Jones - JON
1997-01-17  0:00   ` Steve Jones - JON
1997-01-17  0:00   ` John English
1997-01-16  0:00 ` John English
1997-01-16  0:00   ` whiting_ms@corning.com (Matt Whiting)
1997-01-16  0:00   ` Larry Kilgallen
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox