Name Eric Hartway (hartwaer) Assignment: HW2 Date Submitted: Wednesday, September 5, 2007 4:10:05 PM EDT Current Grade: not yet graded Comments: For some reason i was unable to add the file so here it is pasted. -- Programmer: Eric Hartway -- Course: CS 240 -- Date Due: 9/5/07 -- Language: Ada -- Compiler used: gnat generic -- Source Filename: binary_search_test2.adb -- Executable Filename: none -- Professor: Adams with Ada.Text_IO; with Ada.Integer_Text_IO; with Bin_Search; with ada.io_exceptions; procedure Binary_Search_Test2 is -- Test driver for setting up array of values and calling a search routine. subtype List_Type is Bin_Search.Integer_Array (1..10); --using subtype bin_search to creat an array --------------------------------------------------------------------------- procedure Get_List (List : out List_Type; Count : out Natural) is dummy : character; -- Ask tester for list of values to put in search array. begin Ada.Text_IO.Put_Line ("Enter number of test elements (0-10).");--prompts user for number of elements Ada.Integer_Text_IO.Get (Count); --records the amount given Ada.Text_IO.Put_Line ("Enter the test elements in order, one per line.");--prompts user for the emlements --to be used for Index in 1..Count loop begin --begings the loop for user input of the elements Ada.Integer_Text_IO.Get (List(Index)); exception --handles and exception of wrong input, such as a letter when ada.io_exceptions.data_error => ada.text_io.get (dummy); ada.text_io.put ( " value '" ); ada.text_io.put (dummy); ada.text_io.put_line ("' that you entered was not valid "); ada.text_io.put (" please re-enter "); end; end loop; end Get_List; ------------------------------------------------------------------------------- Num_Elements : Natural; -- number of elements to search List : List_Type; -- list of elements to search Search_Value : Integer; -- value to search for in List Location : Natural; -- index of Value in List begin Get_List (List => List, Count => Num_Elements); Ada.Text_IO.Put_line ("Input value for which to search: ");--prompts user for whic value to search for Ada.Integer_Text_IO.Get (Search_Value);--records the users choice Bin_Search.Binary_Search (List => List(1..Num_Elements),--calls the Binary_search procdure Value => Search_Value, Location => Location); if Location /= 0 then Ada.Text_IO.Put ("Search value found at location ");--if the value is found this is printed out Ada.Integer_Text_IO.Put (Item => Location, Width => 2);--prints out the value that was found else Ada.Text_IO.Put ("Search value not found in list");--if the value is not found this is printed out end if; Ada.Text_IO.New_Line(2); end Binary_Search_Test2;