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

Username:   Password: 
 RegisterRegister   
 Initializing a two/three dimensional array.
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
JayLo




PostPosted: Tue Apr 15, 2003 5:02 pm   Post subject: Initializing a two/three dimensional array.

how do you initialize values for a two dimensional array?
I know that arrays would be:
var x : array 1 .. 3 of int := init (3,5,7)
but what about 2d arrays?
Sponsor
Sponsor
Sponsor
sponsor
Blade




PostPosted: Tue Apr 15, 2003 5:15 pm   Post subject: (No subject)

heres the example from help
Quote:
Example
var mensNames : array 1 .. 3 of string :=
init ( "Tom", "Dick", "Harry" )
put mensNames ( 2 ) % This outputs Dick
var names : array 1 .. 2, 1 .. 3 of string :=
init ( "Tom", "Dick", "Harry",
"Alice", "Barbara", "Cathy")
put names ( 2, 1 ) % This outputs Alice


it should explain it for you
Tony




PostPosted: Tue Apr 15, 2003 5:19 pm   Post subject: (No subject)

once again, read the tutorial on the arrays. It covers EVERYTHING you need to know, including explanation of multidimentional arrays.
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
Blade




PostPosted: Tue Apr 15, 2003 5:34 pm   Post subject: (No subject)

i read it and it didnt tell me how to initilize 2d arrays...
Tony




PostPosted: Tue Apr 15, 2003 5:53 pm   Post subject: (No subject)

read the tutorial again Evil or Very Mad

Quote:
Some array tricks - 2D arrays
Here's something that I used to scare people with right before grade10 compsci exam... "you need to know 2D arrays". People were freaking out... I donno why

Anyway, the point is that each of our little "boxes" in an array can contain a row of boxes of its own. So for each box in a row, we get another row, forming columns. This way we just created a grid (also called matrix).

it's decleared as
Code:

var grid:array 1..10, 1..5 of int



10 rows, 5 columns. Though that depends how you look at it and how you set up your forloops. I had a huge argument with my teacher of what value gous first - row or column. I dont remember what she said, but in my opinion it doesnt matter - as long as you know
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
Catalyst




PostPosted: Tue Apr 15, 2003 6:07 pm   Post subject: (No subject)

i think he means using the init command...
Tony




PostPosted: Tue Apr 15, 2003 6:53 pm   Post subject: (No subject)

ah crap.

Blade is right then.

though why initialize arrays? just get info from a file Wink
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
Blade




PostPosted: Tue Apr 15, 2003 9:21 pm   Post subject: (No subject)

YAY BLADE IS RIGHT!! go blade go, oh yeah uh huh! Very Happy hehe i wouldnt have argued with you if i didnt know i was right tony Wink
Sponsor
Sponsor
Sponsor
sponsor
JayLo




PostPosted: Wed May 07, 2003 6:16 pm   Post subject: (No subject)

about initializing from a text file...
how? Embarassed
Tony




PostPosted: Wed May 07, 2003 6:43 pm   Post subject: (No subject)

:= init(variable1, variable2, ... , variableN)

or just read from the file and save values right in the array
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
Homer_simpson




PostPosted: Wed May 07, 2003 7:11 pm   Post subject: (No subject)

my new tetris project uses 2d arrays that might help u if u take a look at it....
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  [ 11 Posts ]
Jump to:   


Style:  
Search: