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

Username:   Password: 
 RegisterRegister   
 Processing Data
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
dehu87




PostPosted: Sun Jun 01, 2008 9:57 am   Post subject: Processing Data

For this code I want to replicate a text file that has 7 columns and 20 rows of music information, but when I run it turing only outputs 1 row of information and the rest is scattered all over the screen. Also, it is not outputing all the information from the text file. I want the program to output the file so that it is organized into rows and columns. Could someone plz check over this code (Let me know if you need the file).
code:

type MusicRow :
    record
        title : string (20)
        artists : string (20)
        price : real
        recordlabel : string
        genre : string
        catalogue_num : string
        release_date : int
    end record

var MusicDatabase : array 1 .. 20 of MusicRow

var inFile : int
var ch : string
var i : int := 1
open : inFile, "g:\\Music.txt", get
assert inFile not= 0

loop
    exit when eof (inFile)           
    get : inFile, ch               
    put ch : 25..
    MusicDatabase(i).title := ch
    i := i + 1                   
end loop
close : inFile



Music.txt
 Description:
Its divided into title,artist,pricerecord label, catalog ,date and genre

Download
 Filename:  Music.txt
 Filesize:  1.23 KB
 Downloaded:  78 Time(s)

Sponsor
Sponsor
Sponsor
sponsor
TheWanderer




PostPosted: Sun Jun 01, 2008 11:00 am   Post subject: Re: Processing Data

Quote:
Title a Artist a 12.00 Record label 36231 20/05/2003 Pop

I quoted a line from your text file EXACTLY. note how it eliminates your tab spacing. same thing with Turing
(this also sucked for me when we did excel formatting)

the problem i see is you're reading single words into Turing with
Turing:
get : inFile, ch


this only works if you're reading single words from sentences. it will mess up if you're reading other stuff

for this you'll have to specify how many characters to read for each column.
i.e. since you already set title to be 20 characters, make turing read

get : inFile, ch :20

this will include 20 characters from the start of the line and cut it off afterwards

cut off the string length for the other columns that have different lengths
then when you display the information again, make it display to how many characters

the reason why its going all over the page for you, is that you haven't told Turing where the end of the row is.
make a variable to count off how many columns you outputted, then when it reached that number, put a new line "\n"

it would be much easier to use multi-dimensional arrays though
dehu87




PostPosted: Sun Jun 01, 2008 1:21 pm   Post subject: (No subject)

I got the turing program to have the text organized into columns, but now im trying to make it so that the program understands which column is which.
How do I make it so that turing knows that one specific column are the title values, or another column are genres. I have the records set up but i dont know how to put the values from the text file into those record fields.

code:

type MusicRow :
    record
        title : string 
        artists : string 
        genre : string
    end record
TheWanderer




PostPosted: Sun Jun 01, 2008 2:19 pm   Post subject: Re: Processing Data

Turing doesn't work that way. You can't define which item you get is for which purpose.

What you're doing is simply retrieving the values of items.
So if you want to fill the record according to the order you made,
you'd loop a get sequence to go through the file and retrieve the values in that order.

just have your values in the file in order of:
title, artists, price, recordlabel, genre, cataloguenum, releasedate

you can loop these in reverse order and Turing wouldn't tell the difference lol

but if you insist on recognizing which column is which, stick an extra character at the end of each string you're getting

eg. when getting a title, in the original file have it read:

Apple#

and when Turing reads it, you make it check the last character and if its a "#" make it sort into titles, "&" for artists, etc.
this is the only way to have Turing "recognize" the data you're inputting. nevertheless it's excessive and a waste of time.
gitoxa




PostPosted: Sun Jun 01, 2008 2:43 pm   Post subject: RE:Processing Data

code:
    get : inFile, ch               
    put ch : 25..
    MusicDatabase(i).title := ch


The reason you can't get all the information is because you're storing all your data into the "title" variable of your record. I may be mistaken, but not all the information is titles.

Just out of curiousity, have you played with file manipulation on smaller scales? You need to understand HOW turing interacts with files properly before jumping into something like this. And if you have already, then go back and do it again anyways.
dehu87




PostPosted: Sun Jun 01, 2008 3:15 pm   Post subject: Re: Processing Data

Well you see my data looks something like this and my main goal is to sort by either title or genre alphabetically and then use binary searching to display a particular artist or genre. If you or anyone else could help me by giving me an outline then that would be much appreciated.


Title a Artist a 12.00 Record_label 36231 20/05/2003 Pop
Title s Artist s 12.00 Record_label 92346 15/06/2003 Solo
Title d Artist g 12.00 Record_label 38998 15/08/2003 Rock
Title f Artist f 12.00 Record_label 9877839 23/09/2003 Pop
Title g Artist e 12.00 Record_label ERE565 15/12/2003 Electronic

Note: There is better spacing then what it has above
TheWanderer




PostPosted: Sun Jun 01, 2008 4:51 pm   Post subject: Re: RE:Processing Data

gitoxa @ Sun Jun 01, 2008 2:43 pm wrote:
code:
    get : inFile, ch               
    put ch : 25..
    MusicDatabase(i).title := ch


The reason you can't get all the information is because you're storing all your data into the "title" variable of your record. I may be mistaken, but not all the information is titles.


oops I missed that..

well if we understand your goal correctly, given the purpose you stated, what gitoxa and I gave you should be enough to create your database program.

since you have a record set up of multiple elements, you have to read values into each of those elements.
so far you have not done that anywhere.

go through a file, reading every line for each of these elements and store that into your array.

don't worry about sorting yet. there are numerous tutorials on that in the tutorials section.
what your temporary goal right now is to be able to call up a single title, and have Turing output the artist, price, etc. all in one line/row

PS. I did give you an outline on how to do this in my last post. its just not written in step format lol nor is it concise XP.
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: