comp.lang.ada
 help / color / mirror / Atom feed
From: James Brewer <firstvestor@gmail.com>
Subject: Re: Passing a 2d array into a package and returning the same processed 2d back to main
Date: Mon, 3 Oct 2016 11:36:29 -0700 (PDT)
Date: 2016-10-03T11:36:29-07:00	[thread overview]
Message-ID: <241a25d0-e840-4d2f-b39f-e5bcdf9a6209@googlegroups.com> (raw)
In-Reply-To: <44638b2d-c7fb-4113-9262-d57dd1cd5629@googlegroups.com>

On Friday, September 30, 2016 at 5:28:01 PM UTC-5, dia...@gmail.com wrote:
> Hello again, new Ada programmer with a hopefully easy question. 
> I am trying to take a 2d array pass it to a package have the package change the data in the 2d array and send the same 2d array (with modified data) back to the main program. I am currently away from my computer or I would show you my broken code, though I doubt it would be useful. 
> 
> Thanks

I may not have given enough information for help with this problem. So here is my attempt to clarify what I am trying to do by posting my nonfunctioning code.

                 -- Interface of WarshallsPkg

PACKAGE WarshallsPkg IS
   
   TYPE MY_ARRAY IS ARRAY(INTEGER RANGE <>, INTEGER RANGE <>) OF Boolean;  
   PROCEDURE WarshallExecute(InArray : IN MY_ARRAY; OutArray : OUT MY_ARRAY);
   
end WarshallsPkg;

                 -- Implementation of WarshallsPkg

PACKAGE BODY WarshallsPkg IS
   
   PROCEDURE WarshallExecute(InArray : IN MY_ARRAY; OutArray : OUT MY_ARRAY) IS

--   TestArray: ARRAY(InArray'FIRST..InArray'LAST) OF Integer;

   BEGIN
   FOR I IN InArray'FIRST..InArray'LAST LOOP
      FOR J IN InArray'FIRST..InArray'LAST LOOP
         IF InArray(J,I) = True THEN --true nodes connected
            FOR K IN InArray'FIRST..InArray'LAST LOOP
               OutArray(J,K) := InArray(J,K) OR InArray(I,K);
            END LOOP;
         END IF;
      END LOOP;
   END LOOP;

   END WarshallExecute;
   
END WarshallsPkg;

                      --The program i'm trying to implement it in

WITH Text_IO; USE Text_IO; -- This gets the IO facility.
WITH Ada.Integer_Text_IO; USE Ada.Integer_Text_IO; -- This gets the integer IO facility.
WITH WarshallsPkg; USE WarshallsPkg; --package setup


-- * main procedure *
PROCEDURE WarshallsMain IS

   Output : File_Type; -- output file declaration
   N : Integer := 9; -- max size of array -- why does this overflow if not set?
   yOrN : character; -- user input yes or no
   OutputConvertion : Integer; -- used for conversion from true/false to 1/0
   Array2d: ARRAY (1..N, 1..N) OF Boolean;
      
--  PROCEDURE testExecute(InArray : IN MY_ARRAY; OutArray : OUT MY_ARRAY); -- renames warshall proceedure


-- * main procedure starts begins*
BEGIN
-- try to use io redirection to pull data from file

-- output to file creation section
   Create (File => Output,
      Mode => Out_File,
      Name => "output.txt");

-- input node connection data collection
   -- ask for size of array
   Put("How many nodes need to be processed? ");
   Get(N);
   New_Line(2);

   FOR X IN 1..N LOOP
      FOR Y IN 1..N LOOP
         Put("Is node");
         Put(X);
         Put(" connected to node ");
         Put(Y);
         Put(" y/n ");
         Get(YOrN);

         if yOrN = 'y' then
            Array2d(X,Y) := True;
         ELSE Array2d(X,Y) := False;
         END IF;
      END LOOP;
   END LOOP;


-- Warshall's alorithm

-- implement proceedure here for Array2d

   WarshallExecute(Array2d, Array2d);
 
-- to be removed   
--   FOR I IN 1..N LOOP
--      FOR J IN 1..N LOOP
--         IF Array2d(J,I) = True THEN --true nodes connected
--            FOR K IN 1..N LOOP
--               Array2d(J,K) := Array2d(J,K) OR Array2d(I,K);
--            END LOOP;
--         END IF;
--      END LOOP;
--   END LOOP;

-- end of code to be removed

-- *********** output to file ************

-- column label output
   New_Line(Output, 2);
   Put(Output, "           ");
   FOR I IN 1..N LOOP
      Put(Output, I);
   END LOOP;
   New_Line(Output, 1);

-- data matrix output
   FOR I IN 1..N LOOP
      Put(Output, I);
      FOR J IN 1..N LOOP
         IF Array2d(I,J) = True THEN
            OutputConvertion := 1;
         ELSE
            OutputConvertion := 0;
         END IF;
         Put(Output, OutputConvertion);
      END LOOP;
      New_Line(Output, 1);
   END LOOP;

END WarshallsMain;
-- * main procedure ends *

  parent reply	other threads:[~2016-10-03 18:36 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-09-30 22:27 Passing a 2d array into a package and returning the same processed 2d back to main diane74
2016-10-01  0:01 ` Jeffrey R. Carter
2016-10-01 20:01 ` Aurele
2016-10-01 21:04   ` Jeffrey R. Carter
2016-10-01 21:59     ` Aurele
2016-10-01 22:16       ` Jeffrey R. Carter
2016-10-02  0:09         ` Aurele
2016-10-02  7:31           ` Simon Wright
2016-10-03 18:36 ` James Brewer [this message]
2016-10-03 19:43   ` Björn Lundin
2016-10-03 21:59     ` James Brewer
2016-10-03 23:16       ` Anh Vo
2016-10-04 11:29       ` Brian Drummond
2016-10-05 16:16         ` James Brewer
2016-10-05 17:19           ` James Brewer
2016-10-05 18:57             ` Jeffrey R. Carter
2016-10-05 19:53               ` James Brewer
2016-10-05 19:57                 ` AdaMagica
2016-10-05 20:17                 ` Jeffrey R. Carter
2016-10-05 20:58                   ` James Brewer
2016-10-05 22:11                     ` Anh Vo
2016-10-05 19:47             ` Anh Vo
2016-10-05 20:30               ` James Brewer
2016-10-03 20:16   ` Jeffrey R. Carter
replies disabled

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