18
Hoofdstuk 9 Arrays

Hoofdstuk 9

  • Upload
    meagan

  • View
    39

  • Download
    0

Embed Size (px)

DESCRIPTION

Hoofdstuk 9. Arrays. (poging 1). CirkelKlikker. int x, y;. void klik(object o, MouseEA mea) { }. this .x = mea.X; this .y = mea.Y; this .Invalidate();. void teken(object o, PaintEA pea) { }. Graphics gr = pea.Graphics;. tekent alleen laatste cirkel. - PowerPoint PPT Presentation

Citation preview

Page 1: Hoofdstuk 9

Hoofdstuk 9

Arrays

Page 2: Hoofdstuk 9

CirkelKlikker

void klik(object o, MouseEA mea){

}void teken(object o, PaintEA pea){

}

this.x = mea.X;this.y = mea.Y;this.Invalidate();

gr.FillEllipse(Brushes.Black, this.x, this.y, 15, 15 );

int x, y;

(poging 1)

Graphics gr = pea.Graphics;tekent alleenlaatste cirkel

Page 3: Hoofdstuk 9

CirkelKlikker

void klik(object o, MouseEA mea){

}

gr.FillEllipse(Brushes.Black, mea.x, mea.y, 15, 15 );

(poging 2)

Graphics gr = this.CreateGraphics();hertekent het

window nietwanneer nodig

Page 4: Hoofdstuk 9

CirkelKlikker

void klik(object o, MouseEA mea){

}void teken(object o, PaintEA pea){

}

this.x = mea.X;this.y = mea.Y;this.Invalidate();

gr.FillEllipse(Brushes.Black, this.x , this.y , 15, 15 );

int x, y;

(final version)

Graphics gr = pea.Graphics;

ARRAYfor (int t=0; t<n; t++)

[t] [t]

[n][n]

int n=0;[ ]

n++;

Page 5: Hoofdstuk 9

Arrays

Array: rij genummerde variabelen

tabel

0

1

2

3

4

length5

int [ ] tabel;

new int [5];

tabel =

declaratie vaneen array

creëren vanhet eigenlijkearray-object

Page 6: Hoofdstuk 9

Gebruik van een array

’t zijn echte variabelen:

tabel

0

1

2

3

4

length5tabel [2] = 37;

tabel[4] = tabel [2] + 5;

37

42

if (tabel.Length<10) ...

tabel.Length = 10;

Length is eenread-only property

Page 7: Hoofdstuk 9

Gebruik van een array

variabele als index in de array

tabel

0

1

2

3

4

length5tabel [0] = 42;tabel [1] = 42;tabel [2] = 42;tabel [3] = 42;tabel [4] = 42;

42

42

42

42

42

tabel [t] = 42;for (t=0; t<5; t++)

Page 8: Hoofdstuk 9

Array als parameter

tabel

0

1

2

3

4

length5

12

95

11

23

15

int Kleinste ( int [ ] tabel ){

}

int resultaat;

return resultaat;

if (tabel [t] < resultaat)

resultaat = tabel [t];

for (t=0; t<tabel.Length; t++)

int t;

resultaat =tabel [0];

Page 9: Hoofdstuk 9

Deel van de array doorzoeken

tabel

0

1

2

3

4

length5

12

95

11

int Kleinste ( int [ ] tabel ){

}

int resultaat;

return resultaat;

if (tabel [t] < resultaat)

resultaat = tabel [t];

for (t=0; t<tabel.Length; t++)

int t;

resultaat =tabel [0];aantal

, int aantal)static

Page 10: Hoofdstuk 9

CirkelKlikker

void teken(object o, PaintEA pea){

}

gr.FillEllipse(Brushes.Black, this.x[t], this.y[t], 15, 15) ;

int [ ] x, y; int n;

(final version)

Graphics gr = pea.Graphics;

ARRAY

for (int t=0; t<n; t++)

int minX = Bieb.Kleinste(x,n)–r;

int r=7;

int maxX = Bieb.Grootste(x,n)+r;int minY = Bieb.Kleinste(y,n)–r;int maxY = Bieb.Grootste(y,n)+r;gr.DrawRectangle(Brushes.Blue, minX, minY, maxX-minX, maxY-minY ) ;

Page 11: Hoofdstuk 9

Syntax van array-type

type

int

short

sbyte

long

decimal

double

float

char

bool

uint

ushort

byte

ulong

structnaam

classnaam

object

string

waard

everw

ijzin

g [ ]

,

arra

y

Page 12: Hoofdstuk 9

Array van getallen

tabel

int [ ] tabel;

new int [5];

tabel =

0

1

2

3

4

length5

Page 13: Hoofdstuk 9

Array van struct-objecten

tabel

Point [ ] tabel;

new Point[5];tabel =

0

1

2

3

4

length5

Page 14: Hoofdstuk 9

Array van class-objecten

tabel

Button [ ] tabel;

new Button[5];

tabel =

0

1

2

3

4

length5

for (int t=0; t<5; t++)

tabel[t] = new Button();

Page 15: Hoofdstuk 9

Twee-dimensionale array

tabel

int [ , ] tabel;

new int [5,3];

tabel =

0

1

2

3

4

length5

0 1

3

2tabel.GetLength(0)tabel.GetLength(1)

Page 16: Hoofdstuk 9

Array van arrays

tabel

int [ ] [ ] tabel;

new int[5][];tabel =

0

1

2

3

4

length5

for (int t=0; t<5; t++) tabel[t] = new int[t];

Page 17: Hoofdstuk 9

Drie-dimensionale array

tabel

int [ , , ] tabel;

new int [5,3,2];

tabel =

0

1

2

3

4

length5

0 1

3

2

2

01

Page 18: Hoofdstuk 9

Declaratiedeclaratie

naamtype

,

= initialisatieconst

;

var

met intitialisatie

initialisatie

expressie

initialisatie }{

,

string [ ] woorden = { "aap", "noot", "mies" };

int [ ] maand = { 31,28,31,30,31,30,31,31,30,31,30,31 };

int [ , ] = { {1,2,3,4}, {5,6,7,8} };