Musterlösung zur Kurvendiskussion für lineare Funktionen f(x) = mx + t

MODULE Lindisk;

IMPORT Display, ColorPlane, Float;

VAR m,t: REAL;

PROCEDURE Einlesen* (VAR m,t:REAL);
VAR ch: CHAR;
BEGIN
     Display. WriteStr ("Programm zur Kurvendiskussion linearer Funktionen y=mx+t");
     Display. WriteLn;
     Display. WriteStr ("Bitte m angeben: ");
     Display. ReadReal (m, 5, ch);
     Display. WriteLn;
     Display. WriteStr ("Bitte t angeben: ");
     Display. ReadReal (t, 5, ch);
     Display. WriteLn;
END Einlesen;

PROCEDURE Nullstelle* (m,t:REAL);
VAR d: REAL;
BEGIN
     Display. SetForeColor (255,0,0);
     ColorPlane. SetForeColor (255,0,0);
     IF (m=0)&(t#0) THEN Display. WriteStr ("Keine Nullstellen! ");
          ELSE IF (m=0)&(t=0) THEN Display. WriteStr ("Unendlich viel Nullstellen! ");
                         ELSE Display. WriteStr ("Nullstelle: ");
                         d:=-t/m;
                         Display. WriteReal (d,5);
                         Display. WriteLn;
                         ColorPlane. Line (SHORT(ENTIER(50+(d+5)*30)),37,SHORT(ENTIER(50+(d+5)*30)),43,1);
                     END;
    END;
END Nullstelle;


PROCEDURE Schnittpunkty* (t: REAL);
VAR yabschnitt:REAL;
BEGIN
     Display. SetForeColor (100,100,255);
     ColorPlane. SetForeColor (100,100,255);
     yabschnitt:=t;
     Display. WriteStr ("Der Schnittpunkt mit der y-Achse liegt bei ");
     Display. WriteReal (yabschnitt, 5);
     Display. WriteStr (".");
     Display. WriteLn;
     ColorPlane. Line (197,SHORT(ENTIER(40+30*yabschnitt)),203,SHORT(ENTIER(40+30*yabschnitt)),1);
END Schnittpunkty;

PROCEDURE ZeichneAchsen;
VAR i:INTEGER;
BEGIN
     ColorPlane. Line (50,40, 500,40,1); (*Achsen*)
     ColorPlane. Line ( 200,40,200 ,250,1);
     ColorPlane. Line ( 200,250,195 ,245,1); (*Achsenpfeile*)
     ColorPlane. Line ( 200,250,205 ,245,1);
     ColorPlane. Line ( 500,40,495 ,45,1);
     ColorPlane. Line ( 500,40,495 ,35,1);
     ColorPlane. GotoXY (185, 255); (*Achsenbeschriftung*)
     ColorPlane. WriteStr ("y");
     ColorPlane. GotoXY (504, 45); 
     ColorPlane. WriteStr ("x");
     FOR i:=0 TO 6 DO (*Einteilung y-Achse*)
          ColorPlane. Line (197,40+i*30,200,40+i*30,1);
          ColorPlane. GotoXY (185,45+i*30);
          CASE i OF
               0: ColorPlane. WriteStr ("0");
               |1: ColorPlane. WriteStr ("1");
               |2: ColorPlane. WriteStr ("2"); 
               |3: ColorPlane. WriteStr ("3");
               |4: ColorPlane. WriteStr ("4");
               |5: ColorPlane. WriteStr ("5");
               |6: ColorPlane. WriteStr ("6"); 
          END;
     END;
     FOR i:=0 TO 14 DO (*Einteilung y-Achse*)
          ColorPlane. Line (50+i*30,37,50+i*30,40,1);
          ColorPlane. GotoXY (45+i*30,30);
          CASE i OF
               0: ColorPlane. WriteStr ("-5");
               |1: ColorPlane. WriteStr ("-4");
               |2: ColorPlane. WriteStr ("-3"); 
               |3: ColorPlane. WriteStr ("-2");
               |4: ColorPlane. WriteStr ("-1");
               |5: ColorPlane. WriteStr ("0");
               |6: ColorPlane. WriteStr ("1"); 
               |7: ColorPlane. WriteStr ("2");
               |8: ColorPlane. WriteStr ("3"); 
               |9: ColorPlane. WriteStr ("4");
               |10: ColorPlane. WriteStr ("5");
               |11: ColorPlane. WriteStr ("6");
               |12: ColorPlane. WriteStr ("7");
               |13: ColorPlane. WriteStr ("8");
               |14: ColorPlane. WriteStr ("9"); 
          END;
     END;
END ZeichneAchsen;

PROCEDURE ZeichnePunkte* (m,t:REAL);
VAR xakt,yakt: LONGREAL;
     xdot,ydot,i:INTEGER;
     ydotl:LONGINT;

BEGIN
     FOR i:=0 TO 420 DO
          xakt:=-5+i/30;
          yakt:=m*xakt+t;
          xdot:=50+i;
          ydot:=SHORT(ENTIER(40+30*yakt));
          ColorPlane. Dot (xdot,ydot,1); 
     END;
END ZeichnePunkte;


PROCEDURE Zeichnen*(m,t:REAL);
BEGIN
     ColorPlane. Open ();
     ZeichneAchsen;
     ZeichnePunkte(m,t);

END Zeichnen;

PROCEDURE ProgMain*;
VAR m,t: REAL;
BEGIN
     Einlesen (m,t);
     Zeichnen(m,t);
     Nullstelle (m,t); 
     Schnittpunkty (t);


     REPEAT UNTIL Display.KeyPressed();
END ProgMain;

END Lindisk.

Zurück zur Kurvendiskussion linearer Funktionen