/*________________________________________________________________________
 
    Program Title:  Database
 
    Filename.ext:   Database.t
 
  
 
    Description:    This program will allow the user to input a list of names 
 
                    with additional information and output this information 
 
                    depending on what the user wants to organize it by. 
 
                    First, the program will load a list of clients and their
 
                    related information from a Notepad document.  
 
                    The program will then give the user the choice of inputing
 
                    additional information into the Database, or searching 
 
                    for specific clients or key terms (first name, last name, 
 
                    street, car type, VIN, etc).  Then the program will 
 
                    display this information for the user with the option 
 
                    for editing or printing.
 
___________________________________________________________________________*/
 
% Declare the variables to be used in the database
 
    var FileNumber : int   
 
    var Name : string
 
    var DidSwap:string
 
   
 
% Assign the variables
 
    var FileName : string := "ClientDataBase.txt"
 
    var NumberOfDataItems : int := 0
 
    var NumberOfClients : int
 
    var Clients : flexible array 1 .. 0, 1 .. 3 of string
 
    var NumberOfFields : int := 5
 
    var BubbleSortWindow :int:=Window.Open("graphics")
 
    var ListLength:int:=5
 
    var FieldToSortBy:int:=1
 
% Welcome Screen
 
procedure WelcomeScreen
 
    put "Welcome to the Database"
 
    Input.Pause 
 
    put "New Client"
 
    
 
end WelcomeScreen    
 
% Count the number of clients
 
procedure CountClientsData
 
    open : FileNumber, FileName, get
 
    loop
 
        get : FileNumber, Name
 
        NumberOfDataItems := NumberOfDataItems + 1
 
        exit when eof (FileNumber)
 
    end loop
 
    NumberOfClients := NumberOfDataItems div NumberOfFields
 
    close : FileNumber
 
end CountClientsData
 
% Create an array of names
 
procedure CreateClientsArray
 
    new Clients, NumberOfClients, NumberOfFields
 
end CreateClientsArray
 
 
procedure Swap(FirstElement:int, NextElement:int)
 
    var Temp:string
 
    for col : 1 .. NumberOfFields
 
        Temp:=Clients(FirstElement,col)
 
        Clients(FirstElement,col):=Clients(NextElement,col)
 
        Clients(NextElement,col):=Temp
 
    end for
 
    DidSwap:="Yes"
 
end Swap
 
% Sort list of names into alphabetical order
 
procedure BubbleSortClientsArray
 
    var NextElement:int:=0
 
    loop
 
        DidSwap:="No"
 
        for FirstElement: 1 .. ListLength-1         
 
            NextElement:=FirstElement+1
 
            if Clients(NextElement,FieldToSortBy)<Clients(FirstElement,FieldToSortBy) then
 
                Swap(FirstElement,NextElement)
 
            end if
 
        end for
 
        exit when DidSwap = "No"
 
    end loop
 
end BubbleSortClientsArray
 
% Fill the array with the names of the clients
 
procedure FillClientsArray
 
    open : FileNumber, FileName, get
 
    for row : 1 .. NumberOfClients
 
        for col : 1 .. NumberOfFields
 
            get : FileNumber, Clients (row, col)
 
        end for
 
    end for
 
    close : FileNumber
 
end FillClientsArray
 
% Display the names in the array
 
procedure DisplayClientsArray
 
    for row : 1 .. NumberOfClients
 
        for col : 1 .. NumberOfFields
 
            put Clients (row, col) : 13 ..
 
        end for
 
        put ""
 
    end for
 
end DisplayClientsArray
 
% Mainline
 
    CountClientsData
 
    CreateClientsArray
 
    FillClientsArray
 
    BubbleSortClientsArray
 
    DisplayClientsArray
 
% End Mainline
 
 
  |