comp.lang.ada
 help / color / mirror / Atom feed
* making compare function with multiple values(help for newbie)
@ 2006-10-11 23:03 isaac2004
  2006-10-12  5:36 ` Jeffrey R. Carter
  0 siblings, 1 reply; 7+ messages in thread
From: isaac2004 @ 2006-10-11 23:03 UTC (permalink / raw)


hello for a assignment in one of my classes, i am asked to add 3 values
to an array for every appearance of the index (so 3 values like 222, 5,
4 are in one index of the array) and then compare a user prompt to see
if the exact index is in the array, i can do this if there is only one
value but im haveing trouble getting my head around the comparing of
three values at once could i just use nested conditionals in a for
loop. any algorithm ideas would be greatly appreciated. thank you




^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: making compare function with multiple values(help for newbie)
  2006-10-11 23:03 making compare function with multiple values(help for newbie) isaac2004
@ 2006-10-12  5:36 ` Jeffrey R. Carter
  2006-10-12  6:08   ` isaac2004
  0 siblings, 1 reply; 7+ messages in thread
From: Jeffrey R. Carter @ 2006-10-12  5:36 UTC (permalink / raw)


isaac2004 wrote:
> hello for a assignment in one of my classes, i am asked to add 3 values
> to an array for every appearance of the index (so 3 values like 222, 5,
> 4 are in one index of the array) and then compare a user prompt to see
> if the exact index is in the array, i can do this if there is only one
> value but im haveing trouble getting my head around the comparing of
> three values at once could i just use nested conditionals in a for
> loop. any algorithm ideas would be greatly appreciated. thank you

What are the components of the array? A record:

type Three_Values is record
    First  : Integer;
    Second : Integer;
    Third  : Integer;
end record;

type Three_At_Each is array (Positive range <>) of Three_Values;

An array:

type Three_Values is array (Positive range 1 .. 3) of Integer;

type Three_At_Each is array (Positive range <>) of Three_Values;

Or are you using a 2D array:

type Two_D is array (Positive range <>, Positive range <>) of Integer;

type Three_At_Each (Num_Rows : Positive) is record
    Value : Two_D (1 .. Num_Rows, 1 .. 3);
end record;

Or something else I haven't thought of?

-- 
Jeff Carter
"I blow my nose on you."
Monty Python & the Holy Grail
03



^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: making compare function with multiple values(help for newbie)
  2006-10-12  5:36 ` Jeffrey R. Carter
@ 2006-10-12  6:08   ` isaac2004
  2006-10-12  7:24     ` Ludovic Brenta
  2006-10-12 18:35     ` Stephen Leake
  0 siblings, 2 replies; 7+ messages in thread
From: isaac2004 @ 2006-10-12  6:08 UTC (permalink / raw)



Jeffrey R. Carter wrote:
> isaac2004 wrote:
> > hello for a assignment in one of my classes, i am asked to add 3 values
> > to an array for every appearance of the index (so 3 values like 222, 5,
> > 4 are in one index of the array) and then compare a user prompt to see
> > if the exact index is in the array, i can do this if there is only one
> > value but im haveing trouble getting my head around the comparing of
> > three values at once could i just use nested conditionals in a for
> > loop. any algorithm ideas would be greatly appreciated. thank you
>
> What are the components of the array? A record:
>
> type Three_Values is record
>     First  : Integer;
>     Second : Integer;
>     Third  : Integer;
> end record;
>
> type Three_At_Each is array (Positive range <>) of Three_Values;
>
> An array:
>
> type Three_Values is array (Positive range 1 .. 3) of Integer;
>
> type Three_At_Each is array (Positive range <>) of Three_Values;
>
> Or are you using a 2D array:
>
> type Two_D is array (Positive range <>, Positive range <>) of Integer;
>
> type Three_At_Each (Num_Rows : Positive) is record
>     Value : Two_D (1 .. Num_Rows, 1 .. 3);
> end record;
>
> Or something else I haven't thought of?
>
> --
> Jeff Carter
> "I blow my nose on you."
> Monty Python & the Holy Grail
> 03


this is the part that has the generic array

FUNCTION InArray IS NEW In_Array_Generic (
      ValueType => CatType,
      IndexType => Integer,
      ArrayType => CatArrayType);

that is the call to the function so it is the first choice i first get
the 3 values with a loop

 FOR I IN 1..5 LOOP
      Get (Cats(I));
   END LOOP;
where get is a function that
Get(Cat.Id)
Get(Cat.Age)
Get(Cat.Lives)

and the 3 values are stored into one index of the array
i hope this helps and thanks




^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: making compare function with multiple values(help for newbie)
  2006-10-12  6:08   ` isaac2004
@ 2006-10-12  7:24     ` Ludovic Brenta
  2006-10-12 16:21       ` isaac2004
  2006-10-12 18:35     ` Stephen Leake
  1 sibling, 1 reply; 7+ messages in thread
From: Ludovic Brenta @ 2006-10-12  7:24 UTC (permalink / raw)


No, it is not sufficient since you didn't show the type declarations
for the values or the arrays.

Please post your entire code.  Also please keep in mind that we do not
do students' assignments for them; instead we can help you find the
solution for yourself.

-- 
Ludovic Brenta.




^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: making compare function with multiple values(help for newbie)
  2006-10-12  7:24     ` Ludovic Brenta
@ 2006-10-12 16:21       ` isaac2004
  2006-10-12 18:40         ` Jeffrey R. Carter
  0 siblings, 1 reply; 7+ messages in thread
From: isaac2004 @ 2006-10-12 16:21 UTC (permalink / raw)



Ludovic Brenta wrote:
> No, it is not sufficient since you didn't show the type declarations
> for the values or the arrays.
>
> Please post your entire code.  Also please keep in mind that we do not
> do students' assignments for them; instead we can help you find the
> solution for yourself.
>
> --
> Ludovic Brenta.

here is my user interaface file
WITH Ada.Text_Io;
USE Ada.Text_Io;
WITH Cats;
USE Cats;
WITH Cats.Io;
USE Cats.Io;
WITH Maximum_Array_Generic;
WITH In_Array_Generic;
PROCEDURE CompareCats IS

   -- Declare an array of cats
   TYPE CatArrayType IS ARRAY (Integer RANGE <>) OF CatType;
   Cats : CatArrayType (1 .. 5);
   -- Declare a cat variable
   Cat : CatType;
-----------------------------This is what i need to make
   --Instantiate an instance of the In_Array_Generic function.
   --This generic function determines if an element is present in an
array.

   --FUNCTION In_Array_Generic(
   --List:ArrayType;
   --Value:ValueType)RETURNBoolean;
   FUNCTION InArray IS
   NEW In_Array_Generic (
      ValueType => CatType,
      IndexType => Integer,
      ArrayType => CatArrayType);

-----------------------------------------------------------------------------

BEGIN
   -- Read data for 5 cats into the array of cats.

   FOR I IN 1..5 LOOP
      Get (Cats(I));
   END LOOP;
   -- Display the cats entered by the user.
   New_Line;
   Put_Line ("You entered ");
   FOR I IN 1..5 LOOP
      Put (Cats(I));
      New_Line;
   END LOOP;
   -- Determine and display the oldest cat.
   New_Line;
   Put ("The oldest cat is ");
   Put (MaxAge (Cats));
   New_Line;
   -- Determine and display the cat with most lives.
   Put ("The cat with the most lives is ");
   Put (MaxLives (Cats));
   New_Line;
   -- Invite the user to enter a cat and tell the user if an
   -- identical cat is in the array. Two cats are identical if
   -- they have the same id, age, and lives.
   -- Repeat until the user types cntrl-c.
   New_Line;
   Put_Line ("Enter cats and I will tell you if they are in the
array");
   Put_Line ("Type cntrl-c to quit");
   LOOP
      Get(Cat);
      IF InArray (Cats, Cat) THEN
         Put_Line ("This cat is in the array");
      ELSE
         Put_Line ("This cat is not in the array");
      END IF;
      New_Line;
   END LOOP;
END;

i hope that is enough i have other adbs and ads files if you need




^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: making compare function with multiple values(help for newbie)
  2006-10-12  6:08   ` isaac2004
  2006-10-12  7:24     ` Ludovic Brenta
@ 2006-10-12 18:35     ` Stephen Leake
  1 sibling, 0 replies; 7+ messages in thread
From: Stephen Leake @ 2006-10-12 18:35 UTC (permalink / raw)


"isaac2004" <isaac_2004@yahoo.com> writes:

> this is the part that has the generic array
>
> FUNCTION InArray IS NEW In_Array_Generic (
>       ValueType => CatType,
>       IndexType => Integer,
>       ArrayType => CatArrayType);
>
> that is the call to the function so it is the first choice i first get
> the 3 values with a loop
>
>  FOR I IN 1..5 LOOP
>       Get (Cats(I));
>    END LOOP;
> where get is a function that
> Get(Cat.Id)
> Get(Cat.Age)
> Get(Cat.Lives)
>
> and the 3 values are stored into one index of the array
> i hope this helps 

Get will return CatType, which is apparently a record containing the
fields ID, Age, Lives. So to compare these three values you need
something like: 

FOR I IN 1..5 LOOP

    if  Get (Cats(I)).ID = <user_id> then
        ...
    end if;

    if  Get (Cats(I)).Age = <user_age> then
        ...
    end if;

    ...
 END LOOP;

-- 
-- Stephe



^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: making compare function with multiple values(help for newbie)
  2006-10-12 16:21       ` isaac2004
@ 2006-10-12 18:40         ` Jeffrey R. Carter
  0 siblings, 0 replies; 7+ messages in thread
From: Jeffrey R. Carter @ 2006-10-12 18:40 UTC (permalink / raw)


isaac2004 wrote:
> 
> i hope that is enough i have other adbs and ads files if you need

It's not, since we don't know the definition of Cattype. However, it 
appears from your earlier posting to be a record type. "=" is defined 
for record types, and is probably what you want. See ARM 4.5.2.

-- 
Jeff Carter
"If you don't get the President of the United States on that
phone, ... you're going to have to answer to the Coca-Cola
Company."
Dr. Strangelove
32



^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2006-10-12 18:40 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-10-11 23:03 making compare function with multiple values(help for newbie) isaac2004
2006-10-12  5:36 ` Jeffrey R. Carter
2006-10-12  6:08   ` isaac2004
2006-10-12  7:24     ` Ludovic Brenta
2006-10-12 16:21       ` isaac2004
2006-10-12 18:40         ` Jeffrey R. Carter
2006-10-12 18:35     ` Stephen Leake

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