comp.lang.ada
 help / color / mirror / Atom feed
From: "Steve" <nospam_steved94@comcast.net>
Subject: Re: Help needed for ada package
Date: Wed, 27 Jul 2005 19:27:45 -0700
Date: 2005-07-27T19:27:45-07:00	[thread overview]
Message-ID: <IIudnVT7F-2b33XfRVn-vQ@comcast.com> (raw)
In-Reply-To: 1122475184.849564.159870@g44g2000cwa.googlegroups.com

<strictly_mk@hotmail.com> wrote in message 
news:1122475184.849564.159870@g44g2000cwa.googlegroups.com...
> With the code kindly posted by Steve and with the advice some of you
> here gave me I have attempted this thing again and this is the code I
> have 'written'/'modified'. I've simplified it somewhat since I am
> supposed to show the concept of the procedures and functions working
> regardless if they fail after a certain amount of time.
>

Now that you're asking for help, and not for someone to do it for you, as 
you can see, you get a lot more positive response.

> package body POP is
>
> type Individual is
> record
> Person : ID;
> Danger : Rating;
> Associate : ID;
> Reported : Boolean;
> end record;
>
> type Society is array( 1 .. 1000000 ) of Individual;
>
> type Society_Ptr is access all Society;
>
> Pointer : Society_Ptr;
> Counter : Natrual := 0;
>

If the array is going to be fixed in size, why not just use:

  type Society is array( 1 .. 1000000 ) of Individual;

  Society_Buffer : Society;

  In my original response I used a pointer because I dynamically allocated 
an array to store individuals.  When the array became full, I dynamically 
allocated a new larger array, copied the values from the original array to 
the new larger array and then deallocated the original array.  It is 
certainly simpler to just go with a fixed maximum size.

> procedure Rate (Citizen : in ID; Badness : in Rating) is
> begin
> Counter := Counter + 1;
> Pointer( Counter ).Person := Citizen;
> Pointer( Counter ).Rating := Badness;
> Pointer( Counter ).Associate := null;
> Pointer( Counter ).Reported := false;
> end;
> end Rate;
>

  Just a note: One of the features I really like about Ada is the ability to 
do record assignments, so this Rate function could be:

  Counter := Counter + 1;
  Pointer( Counter ) := ( Person => Citizen, Rating => Badness, Associate => 
null, Reported => False );


> procedure Associate (Citizen_1, Citizen_2 : in ID) is
>
> I : Integer
>
> for I in 0..Counter loop
> if Pointer( I ).Citizen = Citizen_1
> then
> Pointer( I ).Associate := Citizen_2;
> end if;
> end Associate;
>
> --query functions
> function Most_Dangerous return ID is
>
> MD_Counter : Integer := 1;
>
> I : Integer
>
> for I in 0..Counter loop
> if Society(I).Danger < Society(MD_Counter).Danger then
> if Society(MD_Counter).Reported = false then
> begin
> Most_Dangerous_Pointer := MD_Counter;
> MD_Counter := MD_Counter + 1;
> end;
> else
> MD_Counter := MD_Counter + 1;
> end if;
> else
> MD_Counter := MD_Counter + 1;
> end if;
> end loop;
>
> begin
> return Pointer(Most_Dangerous_Pointer).Citizen;
> Pointer(Most_Dangerous_Pointer).Reported := true;
> end;
>
> end Most_Dangerous;
>
> I've put all the required information into an array of records. But the
> problem is I realised that if a citizen has more than one associate my
> code won't work. (If the code were to compile) As it stands it would
> logically work if each person only had one associate. I remember an old
> project using code similar to Associate : Associates.Bag within the
> record instances. An I was wondering if anyone knows how this package
> might look like. This way I could put Associate, Next_Member and
> More_In_Group in that package as well. I think this is what the marker
> is looking for as I think I'm supposed to demonstrate my program being
> modular. Any comments?
>

One way to handle the "associates" is to create an association code for each 
individual.  When two citizens are associated, make the id's of the 
associates the same.

You might, for example start out with an association id of 0 indicating no 
association.  When the Associate procedure is called, find the location of 
each of the citizens and handle each of the cases:
  If both associates have no association, create a new association id, and 
assign it to both.
  If just one of the associates has a non-zero association id, assign it to 
the other.
  If both of the associates have a non-zero association id (ie: A and B), 
then change the association ID of all citizens that are currently B to A.

I am assuming that:
  if A associated with B and B associated with C it is implied that A 
associated with C.

I hope this helps,
Steve
(The Duck)





  parent reply	other threads:[~2005-07-28  2:27 UTC|newest]

Thread overview: 48+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <1122305318.728942.304120@f14g2000cwb.googlegroups.com>
2005-07-25 17:45 ` Help needed for ada package Marc A. Criley
2005-07-25 17:47 ` Simon Clubley
2005-07-25 18:21   ` Georg Bauhaus
2005-07-25 18:46 ` Frank J. Lhota
2005-07-25 19:26 ` tmoran
2005-07-25 22:12 ` Ludovic Brenta
2005-07-25 23:33 ` Jeffrey Carter
2005-07-26 17:29   ` Pascal Obry
2005-07-26 19:03     ` Ed Falis
2005-07-26 19:05       ` Pascal Obry
2005-07-26 22:20     ` Jeffrey Carter
2005-07-27  9:07       ` Georg Bauhaus
2005-08-01  5:37     ` Dave Thompson
2005-08-01 12:37       ` Adrien Plisson
2005-07-26  3:17 ` Steve
     [not found]   ` <1122475184.849564.159870@g44g2000cwa.googlegroups.com>
2005-07-27 17:13     ` Martin Krischik
2005-07-27 18:03     ` Simon Wright
2005-07-28  0:58       ` Jeffrey Carter
2005-07-28  1:53         ` tmoran
2005-07-28 16:21           ` Jeffrey Carter
2005-07-28  2:27     ` Steve [this message]
     [not found]       ` <1122547648.069514.63520@g14g2000cwa.googlegroups.com>
2005-07-28 18:33         ` Ludovic Brenta
2005-07-28 19:51           ` tmoran
     [not found]           ` <uaaje1d0l4tp1kjs18mkrgfmbkcir308bt@4ax.com>
2005-07-29  8:37             ` tmoran
2005-07-30  1:44             ` Steve
2005-07-29  1:57         ` Steve
     [not found]           ` <1122980923.842598.181310@g49g2000cwa.googlegroups.com>
2005-08-02 11:37             ` Adrien Plisson
2005-08-02 12:05             ` Georg Bauhaus
     [not found]               ` <1122986293.760710.320180@g44g2000cwa.googlegroups.com>
2005-08-02 13:19                 ` Adrien Plisson
2005-08-02 14:26                 ` Georg Bauhaus
     [not found]                   ` <1122995870.689997.66000@g44g2000cwa.googlegroups.com>
2005-08-02 15:38                     ` Georg Bauhaus
     [not found]                       ` <1122997736.667017.104140@o13g2000cwo.googlegroups.com>
2005-08-02 16:37                         ` Georg Bauhaus
2005-08-02 16:52             ` Jeffrey Carter
     [not found]             ` <o04ve11odsjs756915g5eonn0g1guopih2@4ax.com>
2005-08-02 23:21               ` tmoran
     [not found]               ` <1123069124.562944.246730@o13g2000cwo.googlegroups.com>
2005-08-03 12:08                 ` Georg Bauhaus
2005-08-03 16:13                   ` Jeffrey Carter
2005-08-03 17:57                     ` Georg Bauhaus
2005-08-03 16:48                   ` Martin Dowie
     [not found]                   ` <1123084562.854161.299550@g44g2000cwa.googlegroups.com>
2005-08-03 17:58                     ` Georg Bauhaus
     [not found]                 ` <n0o1f1lqsbi23bt7b2li6oc85r7pgfn9d5@4ax.com>
     [not found]                   ` <1123090742.323338.311230@f14g2000cwb.googlegroups.com>
2005-08-03 18:07                     ` Georg Bauhaus
2005-08-03 20:18                     ` Simon Wright
2005-08-04  0:59                       ` Jeffrey Carter
2005-08-04  5:42                         ` Simon Wright
     [not found]   ` <1123173235.773051.23360@z14g2000cwz.googlegroups.com>
2005-08-04 16:50     ` Simon Clubley
     [not found]       ` <1123174747.107994.317580@o13g2000cwo.googlegroups.com>
2005-08-04 16:27         ` Georg Bauhaus
2005-08-04 20:14         ` Simon Wright
     [not found] <1122320036.858648.242630@f14g2000cwb.googlegroups.com>
2005-07-26  0:47 ` tmoran
     [not found] <1122372224.124606.271380@f14g2000cwb.googlegroups.com>
2005-07-26 17:31 ` tmoran
replies disabled

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