From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,FREEMAIL_FROM autolearn=unavailable autolearn_force=no version=3.4.4 X-Received: by 10.159.34.44 with SMTP id 41mr2513176uad.33.1475687970514; Wed, 05 Oct 2016 10:19:30 -0700 (PDT) X-Received: by 10.157.37.235 with SMTP id q98mr1135677ota.19.1475687970419; Wed, 05 Oct 2016 10:19:30 -0700 (PDT) Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!news.eternal-september.org!news.eternal-september.org!feeder.eternal-september.org!news.glorb.com!g45no183861qte.1!news-out.google.com!w143ni894itb.0!nntp.google.com!l13no273866itl.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail Newsgroups: comp.lang.ada Date: Wed, 5 Oct 2016 10:19:30 -0700 (PDT) In-Reply-To: Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=2601:2c4:101:d816:d1dc:87b4:993b:ab39; posting-account=bfqYCQoAAADhOBV9jx08D2gm5EA72sgj NNTP-Posting-Host: 2601:2c4:101:d816:d1dc:87b4:993b:ab39 References: <44638b2d-c7fb-4113-9262-d57dd1cd5629@googlegroups.com> <241a25d0-e840-4d2f-b39f-e5bcdf9a6209@googlegroups.com> <23322f1c-76c2-4ab5-8098-421a3394bc04@googlegroups.com> User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: <1410516a-584f-4fb1-94a2-57bb9ee80a57@googlegroups.com> Subject: Re: Passing a 2d array into a package and returning the same processed 2d back to main From: James Brewer Injection-Date: Wed, 05 Oct 2016 17:19:30 +0000 Content-Type: text/plain; charset=UTF-8 Xref: news.eternal-september.org comp.lang.ada:31998 Date: 2016-10-05T10:19:30-07:00 List-Id: 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 *