1 / 18

Hoofdstuk 9

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.

meagan
Download Presentation

Hoofdstuk 9

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Hoofdstuk 9 Arrays

  2. (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 alleenlaatste cirkel gr.FillEllipse(Brushes.Black,this.x, this.y, 15, 15 );

  3. (poging 2) CirkelKlikker void klik(object o, MouseEA mea) { Graphics gr =this.CreateGraphics(); hertekent hetwindow nietwanneer nodig gr.FillEllipse(Brushes.Black, mea.x, mea.y, 15, 15 ); }

  4. (final version) CirkelKlikker int x, y; [ ] int n=0; void klik(object o, MouseEA mea) { } this.x = mea.X; this.y = mea.Y; this.Invalidate(); [n] [n] n++; void teken(object o, PaintEA pea) { } Graphics gr = pea.Graphics; ARRAY for (int t=0; t<n; t++) gr.FillEllipse(Brushes.Black,this.x , this.y , 15, 15 ); [t] [t]

  5. tabel 5 length 0 1 2 3 4 Arrays • Array: rij genummerde variabelen declaratie vaneen array int [ ] tabel; tabel = newint [5]; creëren vanhet eigenlijkearray-object

  6. tabel 5 length 0 1 2 3 4 Gebruik van een array • ’t zijn echte variabelen: tabel [2] = 37; tabel[4] = tabel [2] + 5; if (tabel.Length<10) ... 37 tabel.Length = 10; 42 Length is eenread-only property

  7. tabel 5 length 42 0 1 42 2 42 3 42 4 42 Gebruik van een array • variabele als index in de array tabel [0] = 42; tabel [1] = 42; tabel [2] = 42; tabel [3] = 42; tabel [4] = 42; for (t=0; t<5; t++) tabel [t] = 42;

  8. tabel 5 length 0 12 1 95 2 11 3 23 4 15 Array als parameter int Kleinste ( int [ ] tabel ) { } int resultaat; int t; resultaat =tabel [0]; for (t=0; t<tabel.Length; t++) if (tabel [t] < resultaat) resultaat = tabel [t]; return resultaat;

  9. tabel 5 length 0 12 1 95 2 11 3 4 Deel van de array doorzoeken static int Kleinste ( int [ ] tabel ) { } , int aantal) int resultaat; int t; resultaat =tabel [0]; for (t=0; t<tabel.Length; t++) aantal if (tabel [t] < resultaat) resultaat = tabel [t]; return resultaat;

  10. (final version) CirkelKlikker int [ ] x, y; int n; int r=7; void teken(object o, PaintEA pea) { } Graphics gr = pea.Graphics; for (int t=0; t<n; t++) gr.FillEllipse(Brushes.Black,this.x[t], this.y[t], 15, 15) ; intminX = Bieb.Kleinste(x,n)–r; intmaxX = Bieb.Grootste(x,n)+r; intminY = Bieb.Kleinste(y,n)–r; ARRAY intmaxY = Bieb.Grootste(y,n)+r; gr.DrawRectangle(Brushes.Blue, minX, minY, maxX-minX, maxY-minY ) ;

  11. Syntax van array-type type struct naam sbyte byte float bool waarde short ushort double char int uint decimal long ulong string array [ ] object , verwijzing class naam

  12. tabel Array van getallen 5 length 0 int [ ] tabel; 1 2 tabel = newint [5]; 3 4

  13. tabel Array van struct-objecten 5 length 0 Point[ ] tabel; 1 new Point[5]; tabel = 2 3 4

  14. tabel Array van class-objecten 5 length 0 Button [ ] tabel; 1 new Button[5]; tabel = 2 3 for (int t=0; t<5; t++) 4 tabel[t] = new Button();

  15. tabel Twee-dimensionale array 5 3 length 0 int [ , ] tabel; 1 2 newint [5,3]; tabel = 3 4 tabel.GetLength(0) tabel.GetLength(1) 2 0 1

  16. tabel Array van arrays 5 length 0 int [ ] [ ] tabel; 1 new int[5][]; tabel = 2 3 for (int t=0; t<5; t++) tabel[t] = new int[t]; 4

  17. tabel Drie-dimensionale array 5 3 2 length 1 0 int [ , , ] tabel; 0 newint [5,3,2]; tabel = 1 2 3 4 2 0 1

  18. Declaratie met intitialisatie declaratie const = initialisatie type naam ; initialisatie var , expressie { initialisatie } , int [ ] maand = { 31,28,31,30,31,30,31,31,30,31,30,31 }; string [ ] woorden = { "aap", "noot", "mies" }; int [ , ] = { {1,2,3,4}, {5,6,7,8} };

More Related