1 / 15

Hoofdstuk 10.2

Hoofdstuk 10.2. Rekenmachine-casus. Voorbeeld: Rekenmachine. Voorbeeld: Rekenmachine. Twee aspecten: User-interface Werking. class Calculator : Form. class Processor. Rekenmachine: User-interface. Label. TableLayoutPanel. Button. Calculator ( ). {.

nizana
Download Presentation

Hoofdstuk 10.2

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 10.2 Rekenmachine-casus

  2. Voorbeeld: Rekenmachine

  3. Voorbeeld: Rekenmachine Twee aspecten: • User-interface • Werking class Calculator : Form class Processor

  4. Rekenmachine: User-interface Label TableLayoutPanel Button Calculator ( ) { paneel = new TableLayoutPanel( ); for (int t=0; t<16; t++) { } Button knop = new Button(); Buttons zijn ondergeschikt aanhet paneel paneel.Controls.Add( knop ); this.Controls.Add( paneel ); }

  5. User-interface Calculator ( ) { paneel = new TableLayoutPanel( ); paneel.Columncount = 4; for (int t=0; t<4; t++) paneel.ColumnStyles.Add( ...25%... ); for (int t=0; t<16; t++) { Button knop = new Button(); knop.Text = "789/456*123+0C=-"[t].ToString(); knop.Dock = DockStyle.Fill; knop.Click += this.klik; knop.KeyPress += this.toets; knop.Resize += this.groei; Buttons zijn ondergeschikt aanhet paneel paneel.Controls.Add( knop ); } this.Controls.Add( paneel ); }

  6. Opbouw klasse Calculator class Calculator : Form { Label result;TableLayoutPanel paneel; Proc proc; membervariabelenook nodig inEventHandlers Calculator ( ) { result = new Label( );result.TextAlign = ContentAlignment.MiddleRight; // en de rest van de Userinterface-opbouw proc = new Processor ( ); }

  7. Calculator Event-handlers class Calculator : Form { Label result; Proc proc; void klik (object obj, EA ea) { } verwerk( ((Button) object) . Text[0] ); void toets(object obj, KPEA kpea ) { } verwerk( kpea.KeyChar ); void groei(object obj, EA ea ) { } Control c = (Control) obj; int h = c.Height / 2; if (c==result) h = c.Height/3; c.Font = new Font("Tahoma", h);

  8. Calculator Event-handlers class Calculator : Form { Label result; Proc proc; void verwerk (char c) { if (c==‘C’) proc.Schoon(); else if (c==‘=’) proc.Reken(); else if (c>=‘0’&&c<=‘9’) proc.Cijfer(c- ‘0’); else proc.Operatie(c); result . Text ( ); proc . Scherm }

  9. Opbouw klasse Proc class Proc { long Scherm; wat is een Proc? Proc ( ) { this . Schoon(); } void Schoon ( ) { ... } void Reken ( ) { ... } void Cijfer (int n) { ... } void Operatie (char c) { ... } wat kan een Proc?

  10. Wat is een Proc? • waarde op het scherm • huidige waarde 37 372 9 3348 • vorige waarde • laatst gebruikte operator er lijkt niets te gebeuren... schermwaarde wordt tienmaal zo groot plus cijfer

  11. Opbouw klasse Proc class Proc { long Scherm; wat is een Proc? long waarde, vorige; char op; Proc ( ) { this . Schoon(); } void Schoon ( ) { ... } void Reken ( ) { ... } void Cijfer (int n) { ... } void Operatie (char c) { ... } wat kan een Proc?

  12. Proc’s methode cijfer class Proc { long scherm, waarde, vorige; char op; void Cijfer (int n) { } waarde = 10*waarde + n; scherm = waarde;

  13. Proc’s methode reken class Proc { long scherm, waarde, vorige; char op; void Reken ( ) { } if (op==‘+’) if (op==‘-’) if (op==‘*’) if (op==‘/’) vorige += waarde; vorige -= waarde; vorige *= waarde; vorige /= waarde; scherm = vorige; waarde = 0;

  14. Proc’s methode operatie class Proc { long scherm, waarde, vorige; char op; void Operatie (char c) { } this . reken ( ); op = c; void Schoon ( ) { waarde = 0; vorige = 0; scherm = 0; op = } ‘+’;

  15. Testen van een reeks mogelijke waarden switch (x) { } if (x==1) else if (x==2) else if (x==3) else if (x==4) else if (x==5) else if (x==6) else if (x==7) else case 1: case 2: case 3: case 4: case 5: case 6: case 7: default: this.een(); this.twee(); this.drie(); this.vier(); this.vijf(); this.zes(); this.zeven(); this.meer(); break; break; break; break; break; break; break;

More Related