* Re: Ada Student Needs Help..
1997-01-13 0:00 ` Larry Kilgallen
1997-01-13 0:00 ` Norman H. Cohen
@ 1997-01-14 0:00 ` Michael F Brenner
1997-01-17 0:00 ` Steve Jones - JON
` (2 subsequent siblings)
4 siblings, 0 replies; 10+ messages in thread
From: Michael F Brenner @ 1997-01-14 0:00 UTC (permalink / raw)
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.
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: Ada Student Needs Help..
1997-01-13 0:00 ` Larry Kilgallen
1997-01-13 0:00 ` Norman H. Cohen
1997-01-14 0:00 ` Michael F Brenner
@ 1997-01-17 0:00 ` Steve Jones - JON
1997-01-17 0:00 ` Steve Jones - JON
1997-01-17 0:00 ` John English
4 siblings, 0 replies; 10+ messages in thread
From: Steve Jones - JON @ 1997-01-17 0:00 UTC (permalink / raw)
je@bton.ac.uk (John English) writes:
>
> Larry Kilgallen (kilgallen@eisner.decus.org) wrote:
> : In article <5bdl4i$ffl@saturn.brighton.ac.uk>, jmb36@bton.ac.uk (baker) writes:
> : > I just want a genral solution, hopefully avoiding arrays (cos I'm not very
> : > good with them) Can I use Record types?
>
> : If you aren't very good with arrays, that might be a good reason to
> : use them for your project, since the goal is learning rather than
> : actually mixing drinks.
>
> Well said, Larry, you took the words out of my mouth.
>
> : However, I might be wrong about that, since I am not in the
> : Education business.
>
> You're not wrong -- not wrong at all!
Added to this the student has now raised the issue that if he doesn't
use arrays he is admitting defeat. Next project... a generic matrix
multiplication packge for NxN(xN etc :) arrays.
Reminds me of a student who disagreed with my fathers marking, my father
admitted he was wrong in that case but pointed out 5 other places
where he really should have docked marks so the student ended up with
plus a few and minus more.
--
Un Lupe en France | Cat 1, Cha, Cha, Cha -- NERC offical drinking song
----The above of opinions rarely reflect my own and never my employers------
Do not add me to mailing lists violations will be billed for time.
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: Ada Student Needs Help..
1997-01-13 0:00 ` Larry Kilgallen
` (2 preceding siblings ...)
1997-01-17 0:00 ` Steve Jones - JON
@ 1997-01-17 0:00 ` Steve Jones - JON
1997-01-17 0:00 ` John English
4 siblings, 0 replies; 10+ messages in thread
From: Steve Jones - JON @ 1997-01-17 0:00 UTC (permalink / raw)
je@bton.ac.uk (John English) writes:
>
> Larry Kilgallen (kilgallen@eisner.decus.org) wrote:
> : In article <5bdl4i$ffl@saturn.brighton.ac.uk>, jmb36@bton.ac.uk (baker) writes:
> : > I just want a genral solution, hopefully avoiding arrays (cos I'm not very
> : > good with them) Can I use Record types?
>
> : If you aren't very good with arrays, that might be a good reason to
> : use them for your project, since the goal is learning rather than
> : actually mixing drinks.
>
> Well said, Larry, you took the words out of my mouth.
>
> : However, I might be wrong about that, since I am not in the
> : Education business.
>
> You're not wrong -- not wrong at all!
Added to this the student has now raised the issue that if he doesn't
use arrays he is admitting defeat. Next project... a generic matrix
multiplication packge for NxN(xN etc :) arrays.
Reminds me of a student who disagreed with my fathers marking, my father
admitted he was wrong in that case but pointed out 5 other places
where he really should have docked marks so the student ended up with
plus a few and minus more.
--
Un Lupe en France | Cat 1, Cha, Cha, Cha -- NERC offical drinking song
----The above of opinions rarely reflect my own and never my employers------
Do not add me to mailing lists violations will be billed for time.
^ permalink raw reply [flat|nested] 10+ messages in thread