Computer Science Canada

[HELP ME] Inputting Information into a Database

Author:  Mardy2008 [ Tue Dec 02, 2008 8:48 am ]
Post subject:  [HELP ME] Inputting Information into a Database

Below is the attached turing code for our major project in computers class (grade 11). Another thing that we need to figure out for the code is how to enter a new contact and how to load/search for a client from the database and also how to save into the text file.

Sory for the length!

Any help would greatly be appreciated!
+ bits for anyone who helps

**There is a text file that is not included with this code**

code:
/*________________________________________________________________________
    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


Author:  BetaKing [ Tue Dec 02, 2008 9:13 am ]
Post subject:  RE:[HELP ME] Inputting Information into a Database

Ooh... Tough Question. I'll work on it and get back to you.

EDIT: Go here! Jekate has a search function in his database. Might help. Very Happy


: