11-02-2004, 03:38 AM
|
#1
|
|
Member (7 bit)
Join Date: Jun 2004
Location: central california
Posts: 113
|
Ada language := help please
Okay...I have this program in Ada 95, that is supposed to input a file with a list of names, sort them in alphabetical order, and then create an output file with the new list. I know that Ada is an old language (I prefer C++ myself), but it is for class, and I am stuck!! I can't get it to compile...and I know that it is a rather large chunk of code, so I appreciate the help.
Can Somebody Please Help??
Thanks, many thanks for any help
Code:
with Ada.Text_Io;
use Ada.Text_Io;
with Ada.Characters.Handling;
procedure Name_Sort is
Longest_Name : constant integer := 20;
subtype Name_String is character range 'a'..'z';
type Name_Record is
record
Name : string(1..50);
Length : integer;
end record;
Maximum_Name : constant Positive := 50;
type Index_Type is
record
Value : Character;
Item : Character;
end record;
type List_Type is array (1..50) of Index_Type;
procedure Bubble_Sort (
List : in out List_Type ) is
begin
for I in List_Type'First..List_Type'Last
loop
Process(List_Type(I));
end loop;
end;
procedure Exchange (Item1 : in out Name_Record;
Item2 : in out Name_Record ) is
begin -- Exchange
Tmp := Item1 ;
Item1 := Item2;
Item2 := Tmp;
end;
No_Exchanges_Performed : Boolean;
function Key_Of (
Item : in Name_Record )
return String is
begin -- Key_Of
return Ada.Characters.Handling.To_Lower(Item);
end Key_Of;
begin -- Bubble_Sort
loop
No_Exchanges_Performed := True;
for Current in List'First .. Index_Type'Pred(List'Last) loop
if Key_Of(List(Current)) >
Key_Of(List(Index_Type'Succ(Current))) then
Exchange(List(Current), List(Index_Type'Succ(Current)));
No_Exchanges_Performed := False;
end if;
end loop;
exit when No_Exchanges_Performed;
end loop;
end Bubble_Sort;
Input_File : File_Type;
Output_File : File_Type;
File_Name : String (1 .. 1024);
Last : Natural;
List : List_Type;
begin -- Name_Sort
loop
begin
Put("What file would you like to input? ");
Get(Input_File);
Open(
File => File_Type,
Mode => In_File,
Name => File_Name);
end loop;
Bubble_Sort(List);
loop
begin
Put("What file name should the new list be under?" );
Get(Output_File);
Create(
File => File_Type,
Mode => Out_File,
Name => File_Name);
end;
end loop;
loop
begin
Open(Output_File);
Put(File => File_Type,
Item => Character);
Close(Output_File);
end Name_Sort;
Last edited by RoyalT; 11-02-2004 at 03:41 AM.
|
|
|