Computer Science Canada Programming C, C++, Java, PHP, Ruby, Turing, VB   Username:   Password: Wiki   Blog   Search   Turing   Chat Room  Members
Initializing a two/three dimensional array.
Author Message
JayLo

Posted: 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)

Posted: 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

Posted: 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.
Tony's programming blog. DWITE - a programming contest.

Posted: 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

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

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
Tony's programming blog. DWITE - a programming contest.
Catalyst

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

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

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

ah crap.

though why initialize arrays? just get info from a file
Tony's programming blog. DWITE - a programming contest.

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

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

JayLo

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

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

Posted: 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
Tony's programming blog. DWITE - a programming contest.
Homer_simpson

Posted: 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: All Posts1 Day7 Days2 Weeks1 Month3 Months6 Months1 Year Oldest FirstNewest First

Page 1 of 1  [ 11 Posts ]
 Jump to:  Select a forum  CompSci.ca ------------ - Network News - General Discussion     General Forums   -----------------   - Hello World   - Featured Poll   - Contests     Contest Forums   -----------------   - DWITE   - [FP] Contest 2006/2008   - [FP] 2005/2006 Archive   - [FP] 2004/2005 Archive   - Off Topic     Lounges   ---------   - User Lounge   - VIP Lounge     Programming -------------- - General Programming     General Programming Forums   --------------------------------   - Functional Programming   - Logical Programming   - C     C   --   - C Help   - C Tutorials   - C Submissions   - C++     C++   ----   - C++ Help   - C++ Tutorials   - C++ Submissions   - Java     Java   -----   - Java Help   - Java Tutorials   - Java Submissions   - Ruby     Ruby   -----   - Ruby Help   - Ruby Tutorials   - Ruby Submissions   - Turing     Turing   --------   - Turing Help   - Turing Tutorials   - Turing Submissions   - PHP     PHP   ----   - PHP Help   - PHP Tutorials   - PHP Submissions   - Python     Python   --------   - Python Help   - Python Tutorials   - Python Submissions   - Visual Basic and Other Basics     VB   ---   - Visual Basic Help   - Visual Basic Tutorials   - Visual Basic Submissions     Education ----------- - Student Life   Graphics and Design ----------------------- - Web Design     Web Design Forums   ---------------------   - (X)HTML Help   - (X)HTML Tutorials   - Flash MX Help   - Flash MX Tutorials   - Graphics     Graphics Forums   ------------------   - Photoshop Tutorials   - The Showroom   - 2D Graphics   - 3D Graphics     Teams ------ - dTeam Public

 Style: Appalachia blueSilver eMJay subAppalachia subBlue subCanvas subEmjay subGrey subSilver subVereor Search: