Go Back   PCMech Forums > Help & Discussion > Web Design / Development

Need Some Help? Type Your Keywords Here:

Reply
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
Old 11-02-2004, 03:38 AM   #1
Member (7 bit)
 
Join Date: Jun 2004
Location: central california
Posts: 113
Send a message via AIM to RoyalT
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.
RoyalT is offline   Reply With Quote
Old 11-03-2004, 02:47 AM   #2
Member (7 bit)
 
Join Date: Jun 2004
Location: central california
Posts: 113
Send a message via AIM to RoyalT
This editor will work with Ada crimson editor this is another link to the book I'm using contents
RoyalT is offline   Reply With Quote
Reply

Bookmarks

Still Need Help? Type Your Keywords Here:


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -5. The time now is 07:10 AM.
Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2012, vBulletin Solutions, Inc.
SEO by vBSEO 3.6.0 PL2