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: Wed, 5 Oct 2016 10:19:30 -0700 (PDT)
Date: 2016-10-05T10:19:30-07:00	[thread overview]
Message-ID: <1410516a-584f-4fb1-94a2-57bb9ee80a57@googlegroups.com> (raw)
In-Reply-To: <a93362da-b97d-476d-a262-288ab279e5c3@googlegroups.com>


Well, I thought it worked by I'm just getting 1's for the output.

I'll post the new code if you all are still interested in helping me out.

                 -- Interface of WarshallsPkg

PACKAGE WarshallsPkg IS

   TYPE MY_ARRAY IS ARRAY(INTEGER RANGE <>, INTEGER RANGE <>) OF Boolean;

   PROCEDURE WarshallExecute(Arr : IN OUT MY_ARRAY);

end WarshallsPkg;

                 -- Implementation of WarshallsPkg

PACKAGE BODY WarshallsPkg IS
   PROCEDURE WarshallExecute(Arr : IN OUT My_Array) IS
   BEGIN
      FOR I IN Arr'RANGE LOOP
         FOR J IN Arr'RANGE LOOP
            IF Arr(J,I) THEN --true nodes connected
               FOR K IN Arr'RANGE LOOP
                  Arr(J,K) := Arr(J,K) OR Arr(I,K);
               END LOOP;
            END IF;
         END LOOP;
      END LOOP;
   END WarshallExecute;
END WarshallsPkg;

-- Lab 1 C version read and write to file use package
-- Programmed by James Brewer
-- Version 12

--put this in every program for now
--WITH Ada.Command_Line;
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

   Input : File_Type; -- input file declaration
   Output : File_Type; -- output file declaration
   N : Integer := 9; -- max size of array -- why does this overflow if not set?
   YOrN : String(1..1); -- y or n for node connections
   OutputConvertion : Integer; -- used for conversion from true/false to 1/0

   TestString : String(1..1);

-- highlight section in code that creates the array
--   Array2d: ARRAY (1..N, 1..N) OF Boolean; --****** highlight this section ********
   Array2d: WarshallsPkg.MY_ARRAY(1..N,   1..N);



-- * main procedure starts begins*
BEGIN
-- try to use io redirection to pull data from file
-- open input.txt file
   Open (File => Input,
         Mode => In_File,
         Name => "input.txt");


-- 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? ");
   TestString := Get_Line (Input); -- get number of nodes
   N := Integer'Value(TestString); -- convert number of nodes to Integer
   put(N); -- display n on screen
--   Get(N); -- ** not used
   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 ");
         YOrN := Get_Line(Input);
 --        Get(YOrN); -- ** not used
         put(YOrN); new_line(1); -- display choice on screen
         if yOrN = "y" then
            Array2d(X,Y) := True;
         ELSE Array2d(X,Y) := False;
         END IF;
      END LOOP;
   END LOOP;


-- Warshallpkg implementation

   WarshallExecute(Array2d);
--      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;


-- print each transaction as it is processed

-- *********** 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;

--close files
   Close (Input);
   Close (Output);
exception
   when End_Error =>
      if Is_Open(Input) then
         Close (Input);
      end if;
      if Is_Open(Output) then
         Close (Output);
      end if;

END WarshallsMain;
-- * main procedure ends *


  reply	other threads:[~2016-10-05 17:19 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
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 [this message]
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