Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 i am really stuck here (help)anybody?
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
skier




PostPosted: Fri Nov 12, 2004 6:14 pm   Post subject: i am really stuck here (help)anybody?

i know this is asking a lot of everyone but im going to ask because this is of importance.i have made this database program and the saving to a text fille and then reading it works enough to run it so please do so and let me now how to fix this mess i have made.P.S. just ignore the commented stuff.

code:

setscreen ("graphics:800,400")

var name : flexible array 1 .. 6 of string
var model : flexible array 1 .. 6 of string
var company : flexible array 1 .. 6 of string
var phone : flexible array 1 .. 6 of string
var snowday : flexible array 1 .. 6 of int
var experience : flexible array 1 .. 6 of int
var choice : int
var font1 : int
var font2 : int
var total : real
var large : int
var small : int
var delete : int
var add : int
var num : int
var aver : real
var main : string (1)
var l : string
var s : string
%var pic : int := Pic.FileNew ("pollard7.jpg")
%var picID : int := Pic.FileNew ("pollard10.jpg")
%var picID2 : int := Pic.FileNew ("skiing.jpg")
%var picID3 : int := Pic.FileNew ("pollard3.jpg")
%var picID4 : int := Pic.FileNew ("FR1203_frz03.jpg")
num := upper (name)
total := 0
large := 0
small := 100000
font1 := Font.New ("Ravie:10")
font2 := Font.New ("Ravie:28")

var fileName : string := "database.txt"
var file : int
%------------------------------------------------------------------------------------------
proc savestuff
    open : file, fileName, put
    for i : 1 .. upper (name)
        put : file, name (i), company (i), model (i), phone (i), snowday (i), experience (i)
    end for
    close (file)
end savestuff
proc getstuff
    open : file, fileName, get

    for i : 1 .. upper (name)
        exit when eof (file)
        get : file, name (i) : *
   
    end for
    close (file)
end getstuff
%------------------------------------------------------------------------------------------
%proc values

%name (1) := "Carl Holland"
%name (2) := "Jake Reid"
%name (3) := "Alen Kimple"
%name (4) := "Ryan Lowe"
%name (5) := "Kevin Edwards"
%name (6) := "Sam Burns"

%company (1) := "Rossignol/Armada"
%company (2) := "Head/LINE"
%company (3) := "Armada/LINE"
%company (4) := "Rossignol"
%company (5) := "Atomic"
%company (6) := "Atomic"

%model (1) := "Scratch FS/ARV"
%model (2) := "Mad Trix/Twelve Sixty"
%model (3) := "AR5/Twelve Sixty"
%model (4) := "Carve 5.0"
%model (5) := "S-Daddy Pimp"
%model (6) := "Beta Carve 9.1"

%phone (1) := "(905 - 668 - 8687)"
%phone (2) := "(905 - 683 - 1059)"
%phone (3) := "(905 - 683 - 5697)"
%phone (4) := "(905 - 721 - 5286)"
%phone (5) := "(905 - 896 - 6427)"
%phone (6) := "(905 - 668 - 1384)"

%snowday (1) := 67
%snowday (2) := 71
%snowday (3) := 73
%snowday (4) := 50
%snowday (5) := 2
%snowday (6) := 12

%experience (1) := 10
%experience (2) := 10
%experience (3) := 9
%experience (4) := 7
%experience (5) := 17
%experience (6) := 7

%end values
%------------------------------------------------------------------------------------------
proc displayall
    getstuff
    color (116)
    cls
    %Pic.Draw (picID2, 480, 25, picCopy)
    locate (4, 7)
    put "Name              Fav Company              Weapon of choice               Years of experience"
    for i : 1 .. upper (name)
        locate (6 + i, 7)
        put name (i)
        locate (6 + i, 25)
        put company (i)
        locate (6 + i, 50)
        put model (i)
        locate (6 + i, 81)
        put experience (i)

    end for
    put ""
    put ""

    put "Hit a key to return to the menu"

    getch (main)

end displayall
%------------------------------------------------------------------------------------------
proc average
    getstuff

    color (42)
    total := 0

    for i : 1 .. upper (snowday)
        total := total + snowday (i)
    end for
    aver := total / upper (snowday)

    cls
    put "The average number of days on the hill last year was ", aver : 4 : 2
    put "Hit a key to return to the menu"
   % Pic.Draw (picID3, 200, 50, picCopy)
    getch (main)

end average
%------------------------------------------------------------------------------------------
proc mostexperience
    getstuff

    color (5)
    for i : 1 .. upper (experience)
        if experience (i) > large then
            large := experience (i)
            l := name (i)
        end if
    end for
    cls

    put ""
    put "The the person with the most experience is  ", l, " : ", large, " years."
    put ""
    put "Hit a key to return to the menu"

    getch (main)

end mostexperience
%------------------------------------------------------------------------------------------
proc leastexperience
    getstuff


    for i : 1 .. upper (experience)
        if experience (i) < small then
            small := experience (i)
            s := name (i)
        end if
    end for
    cls

    put ""
    put "The the person with the least experience is  ", s, " : ", small, " years."
    put ""
    put "Hit a key to return to the menu"

    getch (main)

end leastexperience
%------------------------------------------------------------------------------------------
proc deletestuff
    getstuff

    color (64)
    if upper (name) = 1 then
        cls
        put "Cannot delete item!"

    else
        loop
            cls
            for i : 1 .. upper (name)
                put i, " ", name (i)
            end for
            put ""
            put "What name would you like to delete? " ..
            get delete
            exit when delete <= upper (name) and delete > 0
        end loop
        for i : 1 .. upper (name)
            if delete = i then
                for i2 : i .. upper (name) - 1
                    name (i2) := name (i2 + 1)
                    company (i2) := company (i2 + 1)
                    model (i2) := model (i2 + 1)
                    phone (i2) := phone (i2 + 1)
                    snowday (i2) := snowday (i2 + 1)
                    experience (i2) := experience (i2 + 1)

                end for
            end if
        end for
        new name, upper (name) - 1
        new company, upper (name)
        new model, upper (name)
        new phone, upper (name)
        new snowday, upper (name)
        new experience, upper (name)

        locate (22, 36)
        put "Name #", delete, " Deleted"
        delay (2000)
    end if
end deletestuff
%------------------------------------------------------------------------------------------
proc addstuff
    getstuff

    color (63)
    cls
    new name, upper (name) + 1
    new company, upper (company) + 1
    new model, upper (model) + 1
    new phone, upper (phone) + 1
    new snowday, upper (snowday) + 1
    new experience, upper (experience) + 1
    put "Enter the persons name."
    get name (upper (name))
    put "Enter their favorite company."
    get company (upper (company))
    put "Enter the model they ski."
    get model (upper (model))
    put "Enter phone number (ie 905 - 678 - 4567)."
    get phone (upper (phone))
    put "Enter how many days the person skied last year."
    get snowday (upper (snowday))
    put "Enter how many yearrs of experience."
    get experience (upper (experience))

    locate (22, 36)
    put "Name added"
    delay (2000)

end addstuff
%------------------------------------------------------------------------------------------
proc showsorted
    getstuff

    color (54)
    cls
    var temp1 : string
    var temp2 : string
    var temp3 : string
    var temp4 : int
    var temp5 : string
    for x : 1 .. num
        for i : 1 .. num - 1
            if name (i) > name (i + 1) then
                temp1 := name (i)
                name (i) := name (i + 1)
                name (i + 1) := temp1

                temp2 := company (i)
                company (i) := company (i + 1)
                company (i + 1) := temp2

                temp3 := model (i)
                model (i) := model (i + 1)
                model (i + 1) := temp3

                temp4 := experience (i)
                experience (i) := experience (i + 1)
                experience (i + 1) := temp4

                temp5 := phone (i)
                phone (i) := phone (i + 1)
                phone (i + 1) := temp5

            end if
        end for
    end for
    for i2 : 1 .. upper (name)
        locate (2 + i2, 5)
        put name (i2)
        locate (2 + i2, 23)
        put phone (i2)
    end for
    %Pic.Draw (picID4, 400, 0, picCopy)
    locate (10, 10)
    put "" ..
    put "" ..
    put "" ..
    put "SORTED!" ..
    put "" ..
    put "Hit a key to return to the menu"

    getch (main)

end showsorted
%------------------------------------------------------------------------------------------
proc menu
    colorback (7)
    cls
    color (7)

   % Pic.Draw (pic, 20, 250, picCopy)
    %Pic.Draw (picID, 600, 50, picCopy)

    Draw.Text ("FREESKIERS", 260, 310, font2, 42)

    Draw.Text ("1) Display all riders, companies and thier weapon(s) of choice", 25, 200, font1, 50)

    Draw.Text ("2) Average number of days on the snow last year", 25, 184, font1, 50)

    Draw.Text ("3) Phone Numbers (Alphabetically) also sorts everything else", 25, 169, font1, 50)

    Draw.Text ("4) Skier with most experience", 25, 154, font1, 50)

    Draw.Text ("5) Skier with least experience", 25, 139, font1, 50)

    Draw.Text ("6) Add a skier", 25, 124, font1, 50)

    Draw.Text ("7) Delete a skier", 25, 109, font1, 50)

    Draw.Text ("8) Quit", 25, 94, font1, 50)
end menu

%------------------------------------------------------------------------------------------
%values
%------------------------------------------------------------------------------------------

loop
    menu
    get choice
    %------------------------------------------------------------------------------------------
    if choice = 1 then

        displayall

    end if
    %------------------------------------------------------------------------------------------
    if choice = 2 then

        average
    end if
    %------------------------------------------------------------------------------------------
    if choice = 3 then

        showsorted
    end if
    %------------------------------------------------------------------------------------------
    if choice = 4 then

        mostexperience
    end if
    %------------------------------------------------------------------------------------------
    if choice = 5 then

        leastexperience
    end if
    %------------------------------------------------------------------------------------------
    if choice = 6 then

        addstuff
        savestuff
    end if
    %------------------------------------------------------------------------------------------
    if choice = 7 then

        deletestuff
        savestuff
    end if
    %------------------------------------------------------------------------------------------
    exit when choice = 8
    %------------------------------------------------------------------------------------------
end loop



database.txt
 Description:

Download
 Filename:  database.txt
 Filesize:  404 Bytes
 Downloaded:  161 Time(s)

Sponsor
Sponsor
Sponsor
sponsor
Hikaru79




PostPosted: Fri Nov 12, 2004 6:22 pm   Post subject: (No subject)

Does the program WORK and you are just asking us to help make your code more efficient? Or is there something not functioning correctly and you're not sure what? ^ ^:
skier




PostPosted: Fri Nov 12, 2004 6:44 pm   Post subject: (No subject)

when i run the program i want it to find the data i call, in the text file. then i want to use that data to out put the info find averages and other thigs u do in a database. i cant get the "getting" and using the info right. run it and u will better understand.i dont now how to get it to work.

do you?
zylum




PostPosted: Fri Nov 12, 2004 9:36 pm   Post subject: (No subject)

dont post the entire code when you only have a problem with a small portion of it like a certain procedure...

anyways, what does your text file look like? when you are retreiving the data you are taking it an entire line at a time so if your file looks like this:

fname lname age phone# address .... etc all on the same line, then it will be stored on one variable.

instead to get it word by word you should do:

code:
get : file, fname(i)
get file, lname(i)
get: file, age(i)
%etc

note i didnt add the extra ': *' at the end of each get... this prevents the get from retrieving the entire line, instead it does it word by word

it would actually be best to store the values in records as other people have pointed out earlier but you can also use separate arrays (as above) for each feild if you still havent learned them...
Mr. Glib




PostPosted: Fri Nov 12, 2004 10:58 pm   Post subject: (No subject)

skier, have a look at the example above. That will solve your problem. When you're dealing with a sequential file you have to read every piece of data in sequence from the beginning to the end.
skier




PostPosted: Sun Nov 14, 2004 11:42 am   Post subject: (No subject)

ahhhhh this is very good. but when i do this i get an error. for some reason "get" will only get strings.how do i get interagers
Mr. Glib




PostPosted: Sun Nov 14, 2004 2:58 pm   Post subject: (No subject)

If you have a txt file with lines of text that are to be read into both string and int variables you'll need to do the following. Assume that I am reading a series of test scores. The txt file would start with the student's name and on the next line would be their test score...like a 0 for example (cause you know, most kids don't bother studying these days)...


code:

open : stream, "filename", get

loop
 exit when eof(stream)
 get : stream, name
 get : stream, mark
 put name, " has a ", mark
end loop
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 7 Posts ]
Jump to:   


Style:  
Search: