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

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




PostPosted: Mon Apr 12, 2004 6:31 pm   Post subject: Records

Wink Embarassed
hey guys.... umm im kinda embaressed to say this but i'm a newb, and i have no dam clue on how to make and edit a record....

i read dodge_tomahawk's tutorial, but i ran it and it didn't ask me to input anything Confused .... i want to be able to input names, addresses, telephone #s, etc. so i kinda need help desperately Shocked .... i'd appriciate it if anyone can explain it to me....

thanks Very Happy
Sponsor
Sponsor
Sponsor
sponsor
Tony




PostPosted: Mon Apr 12, 2004 7:00 pm   Post subject: (No subject)

well records are used to group a number of variables into a group to create types. Such as a 2D point type will contain both X and Y coordinates of the point rether then having 2 separate variables.

code:

type person:
record
name:string
age:int
end record

var me:person

me.name := "tony"
me.age := 18


here instead having to declear separate variables for name and age, a record is created to hold both. A variable is decleared to be of that type and contains every variable field inside of itself.

records are usually used in conjunction with arrays
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
EDEN-E




PostPosted: Mon Apr 12, 2004 10:37 pm   Post subject: or

or you can declare variable like following without 'type'

code:
var me:
    record
        name:string
        age:int
    end record

me.name := "edne-e"
me.age := 16

put me.name
put me.age
rk_rkade




PostPosted: Thu Apr 15, 2004 5:52 pm   Post subject: (No subject)

Very Happy Smile Very Happy Smile Very Happy Smile

YAY! thanks a lot guys.....but, how can i type the name/age as a variable instead of a constant?

and also, how can i save it in a text file??

Embarassed Embarassed Embarassed

thanx again guys....
AsianSensation




PostPosted: Thu Apr 15, 2004 6:30 pm   Post subject: (No subject)

like you would save any other string.

code:
type SomeType :
    record
        X, Y : real;
        Clr : int;
    end record;

var Object: SomeType;

Object.X := 5.6;
Object.Y := 6.7;
Object.Clr := 4;

var fileout : int;
open: fileout, "something.txt", put;

put: fileout, Object.X;
put: fileout, Object.Y;
put: fileout, Object.Clr;


to get, just get it in the same fashion as normal textfiles. But make sure you get it in the same format when you declared the structure.
rk_rkade




PostPosted: Sun Apr 18, 2004 1:06 pm   Post subject: (No subject)

aah....thanks a lot AsianSensation....you answered everything that i wanted to kno.... Very Happy!
the_short1




PostPosted: Sun Apr 18, 2004 4:43 pm   Post subject: (No subject)

that was a question from the gr.10 turing book..


"make a program using record's that asks the user for age,name,adress, then display it"

sound familiar....

its ok RK_RK..... Wink
ur better then most ppl that come here for help....

some just say the question from the book and tell us to do it..

u were genuinely needing the help, and u were atempting it....
good job... ur not 'one of them' **the anoying ppl that just ask us for the answers....

here is 3 bits... and i hope u become an active member of this forum Very Happy
rk_rkade




PostPosted: Wed Apr 21, 2004 5:54 pm   Post subject: (No subject)

YAY! thanks short1 Very Happy ...i'll try to b as active as i can 8)
gamer




PostPosted: Wed Apr 21, 2004 5:58 pm   Post subject: (No subject)

sry but little confusing for me.....but i will still try it...thnx forhelp
TheZsterBunny




PostPosted: Sun Apr 25, 2004 3:16 pm   Post subject: (No subject)

how can one read entire records from a file?

and for that matter, write them.

and is it possible to have arrays within the records?

-bunny

(read/write not get/put)
Cervantes




PostPosted: Sun Apr 25, 2004 4:14 pm   Post subject: (No subject)

yeah you can have arrays within the records.

you just do it. Smile

code:

type sometype :
    record
        x, y, Clr : array 1 .. 100 of int
    end record

var object : sometype

for i : 1 .. 100
    object.x (i) := Rand.Int (0, maxx)
    object.y (i) := Rand.Int (0, maxy)
    object.Clr (i) := Rand.Int (1, 255)
end for

for d : 1 .. 100
    drawfilloval (object.x (d), object.y (d), 4, 4, object.Clr (d))
end for


EDIT: One thing you can't do to the best of my knowledge in the current version of turing is use flexible arrays in records. You get a syntax error. Evil or Very Mad
the_short1




PostPosted: Sun Apr 25, 2004 6:23 pm   Post subject: (No subject)

yea... records are great for mass amounts of stuff...

see their use in Asian Sensation's and Mazer's SNOWFALL program in source code..

cuz it needed x,y, and direction, and size.... and it works VERY well..

.... now i want to make something as good as that snowfall.. Sad


?: WHAT IS A FLEXIBLE ARRAY??
TheZsterBunny




PostPosted: Sun Apr 25, 2004 6:43 pm   Post subject: (No subject)

a flexible array is an array which must be 1d, but can change size.

ex.
code:

var flexon :flexible array 1..0 of int

new flexon, 50


flexon is now an array from 1..50

this can be used in animation where you don't always have to have so many, but the number can change.

-bunny

oh, and flexon(r) is wholly owned by someone, so i can't use the name.
[/code]
TheZsterBunny




PostPosted: Sun Apr 25, 2004 7:15 pm   Post subject: (No subject)

The problem i'm having with records are writing them to files.

I'll attach my problem. this is supposed to help design levels for my game. it is still in the process of being made (the code is disorderly, and the program sucks) but i cannot seem to get this program to write full records.

my record has an array, a string, and an integer. all 3 are initialized, but only the string is put.

Why is this
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  [ 14 Posts ]
Jump to:   


Style:  
Search: